@elyx-code/project-logic-tree 0.0.6162 → 0.0.6164

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:R.Error,code:S.NameNotUniqueInS
42
42
  Please provide a unique 'name' string.`,severity:R.Error,code:S.NameNotUniqueInScope,issue:null}))}}return e}function M7(i,s){switch(i.type){case n.DefinitionEntity:return Cd(i,s);case n.FunctionDeclaration:return dp(i,s);case n.VariableDeclaration:return lp(i,s);case n.Property:return up(i,s);case n.ArgumentDeclaration:return cp(i,s);case n.ReturnDeclaration:return pp(i,s);default:return[]}}function G1(i,s,e){const r=`${Od(i)}-${s}-id`;return e.instances[r]?w.UUID.uuid():r}function fp(i,s){let e="",t=null;if(i.parent){const a=s.get(i.parent);a&&(t=a)}let r="";return t&&(r=`${Od(U(t,s))}-`),e=`${r}${Od(U(i,s))}-id`,s.instances[e]?w.UUID.uuid():e}function pt(i,s,e="uuid"){return e==="semantic"?G1(U(i,s),i.type,s):w.UUID.uuid()}function N7(i){var d;const s=r6(),e=i.toJSON();s.safeParse(e).success;const r=L7(i);(d=i.dataType)==null||d.validate();const a=[...r];if(i.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return a}function L7(i){const s=[];if(!i.implements)return s;const e=i.implements;if(!e.abstract){const r=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(e,i.project)}" with id "${e.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});s.push(r.error)}if(i.static&&!e.static){const r=pe({id:`${i.id}--${Z.NonStaticPropertyImplementsStatic}`,message:`Static property "${U(i,i.project)}" with id "${i.id}" implements a non-static property "${U(e,i.project)}" with id "${e.id}".`,issue:null,severity:R.Error,code:Z.NonStaticPropertyImplementsStatic,entity:i});s.push(r.error)}if(!i.static&&e.static){const r=pe({id:`${i.id}--${Z.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${U(i,i.project)}" with id "${i.id}" implements a static property "${U(e,i.project)}" with id "${e.id}".`,issue:null,severity:R.Error,code:Z.StaticPropertyImplementsNonStatic,entity:i});s.push(r.error)}if(!Ir(i.dataType,e.dataType)){const r=pe({id:`${i.id}--${Z.PropertyImplementsIncompatibleType}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a property "${U(e,i.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:R.Error,code:Z.PropertyImplementsIncompatibleType,entity:i});s.push(r.error)}return Ye(i.errors,s)}function S7(i,s){const e=[];if(i.parent){const r=s.get(i.parent);if(!r)e.push(new D({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.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 a=Ji(r);if(a){const d=r!==a?`The entity of type '${i.type}' with id '${i.id}' have 'parent' with id '${i.parent}' because the entity belongs to a built-in '${a.type}' entity with id '${a.id}' (${U(a,r.project)}) higher up in the tree.`:`The entity of type '${i.type}' with id '${i.id}' have 'parent' with id '${i.parent}' because it is a built-in entity of type ${a.type}.`;e.push(new D({id:`${i.id}--${I.InvalidBuiltInEntityReference}`,code:I.InvalidBuiltInEntityReference,severity:R.Error,message:d,issue:null}))}else if(![n.DefinitionEntity].includes(r.type))e.push(new D({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=qi(r).filter(l=>!l.interactive);if(o.length){let l=o.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${r.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${re(o.map(c=>U(c,c.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${r.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${U(o[0],o[0].project)}").`;l+=`
43
43
  ${xi}`,e.push(new D({id:`${i.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:R.Error,message:l,issue:null}))}else if(i.implements){const l=s.get(i.implements);if(i.id===i.implements)return e.push(new D({id:`${i.id}--${i.implements}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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(!l)e.push(new D({id:`${i.id}--${i.implements}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.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 c=r.properties.find(f=>{var y;return((y=f.implements)==null?void 0:y.id)===i.implements});c?e.push(new D({id:`${i.id}--${S.PropertyOverwrite}`,code:S.PropertyOverwrite,severity:R.Error,message:`The property with id "${i.id}" is trying to implement the property with id "${i.implements}", but the parent entity already has a property with id '${c.id}' that implements the same base property.`,issue:null})):[n.Property].includes(l.type)?l.abstract||e.push(new D({id:`${i.id}--${i.implements}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new D({id:`${i.id}--${i.implements}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=It(i,{},s);return e.push(...t.errors),e}class rt{constructor(s){p(this,"version");p(this,"previousVersion",null);p(this,"createdAt");p(this,"deleted",!1);p(this,"author");this.version=s.version,this.previousVersion=s.previousVersion,this.createdAt=T(s.createdAt).toISOString(),this.deleted=s.deleted,this.author=s.author}metaSync(s){this.deleted=s.deleted!==void 0?s.deleted:this.deleted}}var yp=(i=>(i.Manual="manual",i.Automatic="automatic",i))(yp||{}),b=(i=>(i.Added="added",i.Updated="updated",i.Removed="removed",i.Affected="affected",i))(b||{});class A{constructor(s,e,t,r,a=!1,d=""){p(this,"id",w.UUID.uuid());p(this,"seenEntities",[]);p(this,"added",{});p(this,"updated",{});p(this,"removed",{});p(this,"affected",{});p(this,"self",null);p(this,"author");p(this,"timestamp");p(this,"open",!0);p(this,"dirty",!0);p(this,"type","manual");p(this,"autoclose",!1);p(this,"autoCloseActionName","");p(this,"project");if(this.project=s,this.author=e,this.timestamp=t,this.self=r,this.autoclose=a,this.autoCloseActionName=d,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 s;return!(this.isEmpty&&this.self&&!this.affected[(s=this.self)==null?void 0:s.id])}attemptAutoclose(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}close(){return this.open=!1,!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.isEmpty?(this.project.discardChangeSet(this),this):(this.project.closeChangeSet(this),this)}add(s,e){if(!this.open||!this.dirty)return this;if(this.seenEntities.indexOf(s.id)===-1&&this.seenEntities.push(s.id),e!=="affected"&&s.createdAt!==this.timestamp&&(s.increaseVersion(this.timestamp),s.recursiveCaptureUpstreamVersions(this.timestamp)),e==="removed"&&(this.added[s.id]&&delete this.added[s.id],this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],this.removed[s.id]=s),e==="added"){if(this.removed[s.id])return this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],this.added[s.id]=s}if(e==="updated"){if(this.removed[s.id])return this;if(this.added[s.id])return this;this.affected[s.id]&&delete this.affected[s.id],this.updated[s.id]=s}if(e==="affected"){if(this.removed[s.id])return this;if(this.added[s.id])return this;if(this.updated[s.id])return this;this.affected[s.id]=s}return this}toJSON(){const s={},e={},t=new Set,r=new Set;for(const a of Object.values(this.added))s[a.id]=a.toShallowJSON();for(const a of Object.values(this.updated))e[a.id]=a.toShallowJSON();for(const a of Object.values(this.removed))t.add(a.id);for(const a of Object.values(this.affected))r.add(a.id);return{added:s,updated:e,removed:t,affected:r,self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(s){return!!this.added[s]||!!this.removed[s]||!!this.updated[s]||!!this.affected[s]}hasAdded(s){return!!this.added[s]}hasUpdated(s){return!!this.updated[s]}hasRemoved(s){return!!this.removed[s]}hasAffected(s){return!!this.affected[s]}}var j1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(j1||{});const Ee=class Ee extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"private");p(this,"abstract");p(this,"index");p(this,"static");p(this,"required");p(this,"constant",!1);p(this,"type",n.Property);p(this,"hidden",!1);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"implements",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.implements){const c=g(e.implements);d=t.get(c)}const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:a.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:d,dataType:null,parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=S7(r,t),o=up(r,t);return a.push(...d,...o,...ot(r)),{errors:a,modifiedData:r}}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 D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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 D({id:`${this.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${Nd}`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ee(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];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),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ee(c,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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=O(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?this.index:0),this.static=e.static!==void 0?e.static:this.static,this.hidden=e.hidden!==void 0?e.hidden:this.hidden,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ee.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ee.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ee.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ee.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ee.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ee.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),r.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),r.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r,a;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:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",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:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:(()=>{var y;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((y=this.implements)==null?void 0:y.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((d=this.implements)==null?void 0:d.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 r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.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=N7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v,E;let a=ft(e,this);const d=t||w.UUID.uuid();let o=e||this.parent;const l={hidden:!1,id:d,version:w.UUID.uuid(),createdAt:this.createdAt,author:this.author,previousVersion:this.version,deleted:this.deleted,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:o},c=lt(l,a);r&&c.subscribe(),c.setParent(o,null),c.initChildren(null);const f=((v=this.dataType)==null?void 0:v.clone(c,w.UUID.uuid(),r))||null;f&&c.setDataType(f);const y=(E=this.defaultValue)==null?void 0:E.clone(c,w.UUID.uuid(),r);return c.defaultValue=y||null,this.implements&&(c.implements=this.implements),c.addSelfToProject(null),c}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};p(Ee,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ee,"type",n.Property),p(Ee,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),p(Ee,"PARENT_TYPES",[...Ee.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),p(Ee,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),p(Ee,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(Ee,"BASE_PROPERTIES",[...Ee.MUTABLE_BASE_PROPERTIES,...Ee.INMUTABLE_BASE_PROPERTIES]),p(Ee,"MUTABLE_META_PROPERTIES",[...Ee.MUTABLE_BASE_PROPERTIES,"index"]),p(Ee,"INMUTABLE_META_PROPERTIES",[...Ee.INMUTABLE_BASE_PROPERTIES]),p(Ee,"META_PROPERTIES",[...Ee.MUTABLE_META_PROPERTIES,...Ee.INMUTABLE_META_PROPERTIES]),p(Ee,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Ee,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(Ee,"UPSTREAM_PROPERTIES",[...Ee.MUTABLE_UPSTREAM_PROPERTIES,...Ee.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ee,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),p(Ee,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ee,"DOWNSTREAM_PROPERTIES",[...Ee.MUTABLE_DOWNSTREAM_PROPERTIES,...Ee.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ee,"PROPERTIES",[...Ee.META_PROPERTIES,...Ee.UPSTREAM_PROPERTIES,...Ee.DOWNSTREAM_PROPERTIES]);let wi=Ee;function $7(i){var a;const s=O6(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const d=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var F1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(F1||{});const Ie=class Ie extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"index");p(this,"required");p(this,"constant",!0);p(this,"isError");p(this,"type",n.ReturnDeclaration);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"readsValue",null);p(this,"implements",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.readsValue){const c=g(e.readsValue);d=t.get(c)}const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:a.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:d,dataType:null,parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l,c;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=pp(r,t);if(r=d.modifiedData,r.parent){const f=t.get(g(r.parent));if(f&&[n.BreakStatement,n.ContinueStatement].includes(f.type)){const y=f,v=y.parent,E=[...v.breakStatements.filter(V=>V.id!==f.id),...v.continueStatements.filter(V=>V.id!==f.id)];if(y.outputs.length)a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${y.type}' with id '${y.id}'. This '${y.type}' already has return declarations.
45
+ ${Nd}`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ee(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];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),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ee(c,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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=O(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?this.index:0),this.static=e.static!==void 0?e.static:this.static,this.hidden=e.hidden!==void 0?e.hidden:this.hidden,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ee.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ee.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ee.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ee.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ee.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ee.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),r.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),r.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r,a;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:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",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:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:(()=>{var y;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((y=this.implements)==null?void 0:y.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((d=this.implements)==null?void 0:d.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 r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.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=N7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v,E;let a=ft(e,this);const d=t||w.UUID.uuid();let o=e||this.parent;const l={hidden:!1,id:d,version:w.UUID.uuid(),createdAt:this.createdAt,author:this.author,previousVersion:this.version,deleted:this.deleted,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:o},c=lt(l,a);r&&c.subscribe(),c.setParent(o,null),c.initChildren(null);const f=((v=this.dataType)==null?void 0:v.clone(c,w.UUID.uuid(),r))||null;f&&c.setDataType(f);const y=(E=this.defaultValue)==null?void 0:E.clone(c,w.UUID.uuid(),r);return c.defaultValue=y||null,this.implements&&(c.implements=this.implements),c.addSelfToProject(null),c}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};p(Ee,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ee,"type",n.Property),p(Ee,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),p(Ee,"PARENT_TYPES",[...Ee.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),p(Ee,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),p(Ee,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ee,"BASE_PROPERTIES",[...Ee.MUTABLE_BASE_PROPERTIES,...Ee.INMUTABLE_BASE_PROPERTIES]),p(Ee,"MUTABLE_META_PROPERTIES",[...Ee.MUTABLE_BASE_PROPERTIES,"index"]),p(Ee,"INMUTABLE_META_PROPERTIES",[...Ee.INMUTABLE_BASE_PROPERTIES]),p(Ee,"META_PROPERTIES",[...Ee.MUTABLE_META_PROPERTIES,...Ee.INMUTABLE_META_PROPERTIES]),p(Ee,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Ee,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(Ee,"UPSTREAM_PROPERTIES",[...Ee.MUTABLE_UPSTREAM_PROPERTIES,...Ee.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ee,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),p(Ee,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ee,"DOWNSTREAM_PROPERTIES",[...Ee.MUTABLE_DOWNSTREAM_PROPERTIES,...Ee.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ee,"PROPERTIES",[...Ee.META_PROPERTIES,...Ee.UPSTREAM_PROPERTIES,...Ee.DOWNSTREAM_PROPERTIES]);let wi=Ee;function $7(i){var a;const s=O6(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const d=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var F1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(F1||{});const Ie=class Ie extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"index");p(this,"required");p(this,"constant",!0);p(this,"isError");p(this,"type",n.ReturnDeclaration);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"readsValue",null);p(this,"implements",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.readsValue){const c=g(e.readsValue);d=t.get(c)}const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:a.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:d,dataType:null,parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l,c;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=pp(r,t);if(r=d.modifiedData,r.parent){const f=t.get(g(r.parent));if(f&&[n.BreakStatement,n.ContinueStatement].includes(f.type)){const y=f,v=y.parent,E=[...v.breakStatements.filter(V=>V.id!==f.id),...v.continueStatements.filter(V=>V.id!==f.id)];if(y.outputs.length)a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${y.type}' with id '${y.id}'. This '${y.type}' already has return declarations.
46
46
  ${Rp}`,issue:null}));else{const V=(c=(l=E[0])==null?void 0:l.outputs[0])==null?void 0:c.name;V!==r.name&&a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${y.type}' with id '${y.id}'. This new 'return-declaration' doesn't have the same name "${V}" as the return declarations on the other statements in the same scope.
47
47
  ${Rp}`,issue:null}))}}else if(f&&f.type===n.ReturnStatement){const y=f.parent;if(y&&at.includes(y.type)){const v=y.implements;if(v){const E=v.outputs.find(B=>B.name===r.name),P=v.outputs.filter(B=>!f.outputs.find(z=>z.type===n.ReturnDeclaration&&z.name===B.name)),V=f.outputs.filter(B=>B.type===n.ReturnDeclaration),C=V.find(B=>B.name===r.name),G=V.length?`The parent entity already implements the following return declarations: ${re(V.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",j=P.length?`The parent entity is still missing the following returns in the implementation: ${re(P.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";E?C&&a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${f.type}' with id '${f.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.
@@ -51,13 +51,13 @@ ${j}`,issue:null})):a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSigna
51
51
  Adding a new return would make the implementation invalid. There are no returns in the descriptor with the same name.
52
52
  ${G}
53
53
  ${j}`,issue:null}))}}}}return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=Os(r,this);return r=a.modifiedData,t.push(...a.errors),r.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
54
- 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})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ie(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ie(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}propagateChanges(){const e=[this],t=[],r=[],a=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.parent.parent,{updated:o,added:l,removed:c}=d.syncChildren();e.push(...o),t.push(...l),r.push(...c)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=O(this.initialData.implements,this.project);this.setImplements(t,null)}return pi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,this.isError=e.isError||this.isError,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ie.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ie.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ie.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ie.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ie.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ie.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...((d=this.dataType)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatIds(e))||[],...((d=this.dataType)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;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,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,required:this.required,constant:!0,isError:this.isError,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((y=this.implements)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((v=this.readsValue)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatJSON(e))||[],...((d=this.dataType)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.dataType)==null?void 0:d.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=$7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.dataType=null,d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r);l.dataType=c||null;const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(){const e=ap(this);if(e){const t=e.clone(this);t&&(t.inferred=!0,this.setDataType(t))}return this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(d=>d.outputs).filter(d=>U(d,this.project)===U(this,this.project)&&d.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const r=this.parent.parent.returnStatements.flatMap(a=>a.outputs);this.implements?e=r.filter(d=>{var o;return this.implements.id===((o=d.implements)==null?void 0:o.id)}):e=r.filter(d=>U(d,this.project)===U(this,this.project)&&d.id!==this.id)}return e}inferDataTypeFromCounterparts(){var r,a;const e=this.getCounterparts(),t=e.find(d=>{var o;return(o=d.dataType)==null?void 0:o.isResolved});if(t)this.setDataType(t.dataType);else for(let d=0;d<e.length;d++){const o=e[d];if((!o.dataType||!o.dataType.isResolved||(r=o.dataType)!=null&&r.inferred)&&o.readsValue&&o.inferDataType(),(a=o.dataType)!=null&&a.isResolved){this.setDataType(o.dataType);break}}return this}getDataType(){var e;return(!this.dataType||!this.dataType.isResolved||(e=this.dataType)!=null&&e.inferred)&&this.readsValue?this.inferDataType():this.inferDataTypeFromCounterparts(),this.dataType}};p(Ie,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ie,"type",n.ReturnDeclaration),p(Ie,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),p(Ie,"PARENT_TYPES",[...Ie.USER_MANAGED_PARENT_TYPES]),p(Ie,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),p(Ie,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(Ie,"BASE_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,...Ie.INMUTABLE_BASE_PROPERTIES]),p(Ie,"MUTABLE_META_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,"index"]),p(Ie,"INMUTABLE_META_PROPERTIES",[...Ie.INMUTABLE_BASE_PROPERTIES]),p(Ie,"META_PROPERTIES",[...Ie.MUTABLE_META_PROPERTIES,...Ie.INMUTABLE_META_PROPERTIES]),p(Ie,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),p(Ie,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Ie,"UPSTREAM_PROPERTIES",[...Ie.MUTABLE_UPSTREAM_PROPERTIES,...Ie.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ie,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),p(Ie,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ie,"DOWNSTREAM_PROPERTIES",[...Ie.MUTABLE_DOWNSTREAM_PROPERTIES,...Ie.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ie,"PROPERTIES",[...Ie.META_PROPERTIES,...Ie.UPSTREAM_PROPERTIES,...Ie.DOWNSTREAM_PROPERTIES]);let tr=Ie;function U7(i){var a;const s=b6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}function G7(i){var a;const s=T6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var hp=(i=>(i.Parent="parent",i))(hp||{});const Ue=class Ue extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.ContinueStatement);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"throws",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),o=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),l=e.calledByError.map(y=>{const v=g(y);return t.get(v)}),c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},f=O(c,t);return f.setParent(a,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
54
+ 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})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ie(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ie(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}propagateChanges(){const e=[this],t=[],r=[],a=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.parent.parent,{updated:o,added:l,removed:c}=d.syncChildren();e.push(...o),t.push(...l),r.push(...c)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=O(this.initialData.implements,this.project);this.setImplements(t,null)}return pi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,this.isError=e.isError||this.isError,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ie.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ie.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ie.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ie.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ie.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ie.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...((d=this.dataType)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatIds(e))||[],...((d=this.dataType)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;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,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,required:this.required,constant:!0,isError:this.isError,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((y=this.implements)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((v=this.readsValue)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatJSON(e))||[],...((d=this.dataType)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.dataType)==null?void 0:d.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=$7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.dataType=null,d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r);l.dataType=c||null;const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(){const e=ap(this);if(e){const t=e.clone(this);t&&(t.inferred=!0,this.setDataType(t))}return this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(d=>d.outputs).filter(d=>U(d,this.project)===U(this,this.project)&&d.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const r=this.parent.parent.returnStatements.flatMap(a=>a.outputs);this.implements?e=r.filter(d=>{var o;return this.implements.id===((o=d.implements)==null?void 0:o.id)}):e=r.filter(d=>U(d,this.project)===U(this,this.project)&&d.id!==this.id)}return e}inferDataTypeFromCounterparts(){var r,a;const e=this.getCounterparts(),t=e.find(d=>{var o;return(o=d.dataType)==null?void 0:o.isResolved});if(t)this.setDataType(t.dataType);else for(let d=0;d<e.length;d++){const o=e[d];if((!o.dataType||!o.dataType.isResolved||(r=o.dataType)!=null&&r.inferred)&&o.readsValue&&o.inferDataType(),(a=o.dataType)!=null&&a.isResolved){this.setDataType(o.dataType);break}}return this}getDataType(){var e;return(!this.dataType||!this.dataType.isResolved||(e=this.dataType)!=null&&e.inferred)&&this.readsValue?this.inferDataType():this.inferDataTypeFromCounterparts(),this.dataType}};p(Ie,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ie,"type",n.ReturnDeclaration),p(Ie,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),p(Ie,"PARENT_TYPES",[...Ie.USER_MANAGED_PARENT_TYPES]),p(Ie,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),p(Ie,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ie,"BASE_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,...Ie.INMUTABLE_BASE_PROPERTIES]),p(Ie,"MUTABLE_META_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,"index"]),p(Ie,"INMUTABLE_META_PROPERTIES",[...Ie.INMUTABLE_BASE_PROPERTIES]),p(Ie,"META_PROPERTIES",[...Ie.MUTABLE_META_PROPERTIES,...Ie.INMUTABLE_META_PROPERTIES]),p(Ie,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),p(Ie,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Ie,"UPSTREAM_PROPERTIES",[...Ie.MUTABLE_UPSTREAM_PROPERTIES,...Ie.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ie,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),p(Ie,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ie,"DOWNSTREAM_PROPERTIES",[...Ie.MUTABLE_DOWNSTREAM_PROPERTIES,...Ie.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ie,"PROPERTIES",[...Ie.META_PROPERTIES,...Ie.UPSTREAM_PROPERTIES,...Ie.DOWNSTREAM_PROPERTIES]);let tr=Ie;function U7(i){var a;const s=b6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}function G7(i){var a;const s=T6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var hp=(i=>(i.Parent="parent",i))(hp||{});const Ue=class Ue extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.ContinueStatement);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"throws",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),o=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),l=e.calledByError.map(y=>{const v=g(y);return t.get(v)}),c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},f=O(c,t);return f.setParent(a,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
55
55
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
56
56
  You shouldn't have to manually update a 'parent' property.
57
- Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=O(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ue.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ue.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),throws:((c=this.throws)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,outputs:this.outputs.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.calledBy.flatMap(a=>a.toFlatJSON(e)),...((r=this.throws)==null?void 0:r.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=G7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.outputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.outputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-return-declaration-"+P+"-id",r));return f.outputs=y,this.throws&&(f.throws=this.throws.clone(f,c+"-throws-id",r)),f}};p(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ue,"type",n.ContinueStatement),p(Ue,"USER_MANAGED_PARENT_TYPES",[n.Loop]),p(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),p(Ue,"MUTABLE_BASE_PROPERTIES",[]),p(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),p(Ue,"MUTABLE_META_PROPERTIES",["x","y"]),p(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),p(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),p(Ue,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),p(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let Ut=Ue;var gd=(i=>(i.Parent="parent",i))(gd||{});const tt=class tt extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.ReturnStatement);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"throws",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),o=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),l=e.calledByError.map(y=>{const v=g(y);return t.get(v)}),c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},f=O(c,t);return f.setParent(a,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:mt}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
57
+ Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=O(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ue.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ue.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),throws:((c=this.throws)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,outputs:this.outputs.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.calledBy.flatMap(a=>a.toFlatJSON(e)),...((r=this.throws)==null?void 0:r.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=G7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.outputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.outputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-return-declaration-"+P+"-id",r));return f.outputs=y,this.throws&&(f.throws=this.throws.clone(f,c+"-throws-id",r)),f}};p(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ue,"type",n.ContinueStatement),p(Ue,"USER_MANAGED_PARENT_TYPES",[n.Loop]),p(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),p(Ue,"MUTABLE_BASE_PROPERTIES",[]),p(Ue,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),p(Ue,"MUTABLE_META_PROPERTIES",["x","y"]),p(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),p(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),p(Ue,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),p(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let Ut=Ue;var gd=(i=>(i.Parent="parent",i))(gd||{});const tt=class tt extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.ReturnStatement);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"throws",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),o=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),l=e.calledByError.map(y=>{const v=g(y);return t.get(v)}),c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},f=O(c,t);return f.setParent(a,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:mt}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
58
58
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
59
59
  You shouldn't have to manually update a 'parent' property.
60
- Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new tt(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new tt(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=O(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await tt.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await tt.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await tt.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await tt.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await tt.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await tt.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=U7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.outputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.outputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-return-declaration-"+P+"-id",r));return f.outputs=y,this.throws&&(f.throws=this.throws.clone(f,c+"-throws-id",r)),f}};p(tt,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(tt,"type",n.ReturnStatement),p(tt,"USER_MANAGED_PARENT_TYPES",[...mt]),p(tt,"PARENT_TYPES",[...tt.USER_MANAGED_PARENT_TYPES]),p(tt,"MUTABLE_BASE_PROPERTIES",[]),p(tt,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(tt,"BASE_PROPERTIES",[...Ut.MUTABLE_BASE_PROPERTIES,...Ut.INMUTABLE_BASE_PROPERTIES]),p(tt,"MUTABLE_META_PROPERTIES",["x","y"]),p(tt,"INMUTABLE_META_PROPERTIES",[...Ut.INMUTABLE_BASE_PROPERTIES]),p(tt,"META_PROPERTIES",[...Ut.MUTABLE_META_PROPERTIES,...Ut.INMUTABLE_META_PROPERTIES]),p(tt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(tt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(tt,"UPSTREAM_PROPERTIES",[...Ut.MUTABLE_UPSTREAM_PROPERTIES,...Ut.INMUTABLE_UPSTREAM_PROPERTIES]),p(tt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),p(tt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(tt,"DOWNSTREAM_PROPERTIES",[...Ut.MUTABLE_DOWNSTREAM_PROPERTIES,...Ut.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(tt,"PROPERTIES",[...tr.META_PROPERTIES,...tr.UPSTREAM_PROPERTIES,...tr.DOWNSTREAM_PROPERTIES]);let Ci=tt;function j7(i){const s=T5(),e=i.toJSON();s.safeParse(e).success;const r=F7(i),a=x7(i),d=rr(i);i.inputs.forEach(l=>l.validate()),d.forEach(l=>l.validate());const o=[...r,...a];if(i.id==="getCompanyByIdEndpointReachedEntityEvent"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});o.push(l.error)}return Ye(i.errors,o)}function F7(i){const s=[];if(!i.calls.length){const e=pe({id:`${i.id}--${Z.ScopeWithoutLogic}`,message:`Action "${U(i,i.project)}" with id "${i.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:R.Warning,code:Z.ScopeWithoutLogic,entity:i});s.push(e.error)}return Ye(i.errors,s)}function x7(i){const s=[];return i.implements,Ye(i.errors,s)}var x1=(i=>(i.Implements="implements",i))(x1||{});const Re=class Re extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"collapsed");p(this,"private");p(this,"index",null);p(this,"type",n.FunctionDeclaration);p(this,"implements",null);p(this,"inputs",[]);p(this,"calls",[]);p(this,"parent");p(this,"detachedChildren",[]);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a=null;if(e.implements){const l=g(e.implements);a=t.get(l)}const d={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:r.type===n.DefinitionEntity?r.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=O(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var y;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);r=d.modifiedData;const o=dp(r,t),l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DefinitionEntity){const v=l,P=qi(v).filter(V=>!V.interactive);if(P.length){let V=P.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${re(P.map(C=>U(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${U(P[0],P[0].project)}").`;V+=`
60
+ Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new tt(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new tt(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=O(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await tt.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await tt.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await tt.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await tt.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await tt.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await tt.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=U7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.outputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.outputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-return-declaration-"+P+"-id",r));return f.outputs=y,this.throws&&(f.throws=this.throws.clone(f,c+"-throws-id",r)),f}};p(tt,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(tt,"type",n.ReturnStatement),p(tt,"USER_MANAGED_PARENT_TYPES",[...mt]),p(tt,"PARENT_TYPES",[...tt.USER_MANAGED_PARENT_TYPES]),p(tt,"MUTABLE_BASE_PROPERTIES",[]),p(tt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(tt,"BASE_PROPERTIES",[...Ut.MUTABLE_BASE_PROPERTIES,...Ut.INMUTABLE_BASE_PROPERTIES]),p(tt,"MUTABLE_META_PROPERTIES",["x","y"]),p(tt,"INMUTABLE_META_PROPERTIES",[...Ut.INMUTABLE_BASE_PROPERTIES]),p(tt,"META_PROPERTIES",[...Ut.MUTABLE_META_PROPERTIES,...Ut.INMUTABLE_META_PROPERTIES]),p(tt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(tt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(tt,"UPSTREAM_PROPERTIES",[...Ut.MUTABLE_UPSTREAM_PROPERTIES,...Ut.INMUTABLE_UPSTREAM_PROPERTIES]),p(tt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),p(tt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(tt,"DOWNSTREAM_PROPERTIES",[...Ut.MUTABLE_DOWNSTREAM_PROPERTIES,...Ut.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(tt,"PROPERTIES",[...tr.META_PROPERTIES,...tr.UPSTREAM_PROPERTIES,...tr.DOWNSTREAM_PROPERTIES]);let Ci=tt;function j7(i){const s=T5(),e=i.toJSON();s.safeParse(e).success;const r=F7(i),a=x7(i),d=rr(i);i.inputs.forEach(l=>l.validate()),d.forEach(l=>l.validate());const o=[...r,...a];if(i.id==="getCompanyByIdEndpointReachedEntityEvent"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});o.push(l.error)}return Ye(i.errors,o)}function F7(i){const s=[];if(!i.calls.length){const e=pe({id:`${i.id}--${Z.ScopeWithoutLogic}`,message:`Action "${U(i,i.project)}" with id "${i.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:R.Warning,code:Z.ScopeWithoutLogic,entity:i});s.push(e.error)}return Ye(i.errors,s)}function x7(i){const s=[];return i.implements,Ye(i.errors,s)}var x1=(i=>(i.Implements="implements",i))(x1||{});const Re=class Re extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"collapsed");p(this,"private");p(this,"index",null);p(this,"type",n.FunctionDeclaration);p(this,"implements",null);p(this,"inputs",[]);p(this,"calls",[]);p(this,"parent");p(this,"detachedChildren",[]);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a=null;if(e.implements){const l=g(e.implements);a=t.get(l)}const d={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:r.type===n.DefinitionEntity?r.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=O(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var y;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);r=d.modifiedData;const o=dp(r,t),l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DefinitionEntity){const v=l,P=qi(v).filter(V=>!V.interactive);if(P.length){let V=P.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${re(P.map(C=>U(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${U(P[0],P[0].project)}").`;V+=`
61
61
  ${xi}`,a.push(new D({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:R.Error,message:V,issue:null}))}else{const V=v.methods.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===r.implements});V&&a.push(new D({id:`${r.id}--${S.MethodOverwrite}`,code:S.MethodOverwrite,severity:R.Error,message:`The '${n.FunctionDeclaration}' with id "${r.id}" is trying to implement the '${n.ActionDescriptor}' with id "${r.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${V.id}' that implements the same base method.
62
62
  A ${n.FunctionDeclaration} that has a parent of type '${n.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${n.ActionDescriptor}' more than once.
63
63
  ${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
@@ -67,48 +67,48 @@ If you want to implement a new method, you can create a new 'function-declaratio
67
67
  If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${n.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null}))}}else if(l&&l.type===n.Loop){const v=l.body;v&&((y=v.implements)==null?void 0:y.id)===r.implements&&a.push(new D({id:`${r.id}--${S.MethodOverwrite}`,code:S.MethodOverwrite,severity:R.Error,message:`The '${n.FunctionDeclaration}' with id "${r.id}" is being added as the 'body' of the ${n.Loop} with id "${l.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`,issue:null}))}const c=r.parent&&t.get(r.parent)||t.getBuiltIn(r.parent),f=c?Ji(c):null;return f&&a.push(new D({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${U(f,t)}" with id '${f.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===gd.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&(this.parent.type===n.Project?t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
68
68
  This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`,issue:null})):t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
69
69
  This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, 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.
70
- Please consider that any updates might affect the overlap with the signature of the parent entity's action descriptors.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.setImplements(null,r),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(e)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];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),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'parent' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else if(d)throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.indexOf(e);return t!==-1&&this.inputs.splice(t,1),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=O(t,this.project);return r.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.initialData.implements&&(this.implements=O(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.private=e.private||this.private,this.index=e.index||(e.index!==0?this.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Re.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Re.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),rr(this).forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),rr(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=rr(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){var t;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,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(r=>r.toJSON(e)),inputs:this.inputs.map(r=>r.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId: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})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(d=>d.toReference(e)),calls:this.calls.map(d=>d.toReference(e)),implements:((a=this.implements)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;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,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=j7(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=rr(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0,a=!1){var P;let d=ft(e,this);const o=this.toJSON(),l=t||w.UUID.uuid();o.inputs=[],o.calls=[];const c=l.split("-id"),f=c[c.length-1||0]||l;o.id=l;const y=lt(o,d);e?y.setParent(e,null):y.setParent(this.parent,null),r&&y.subscribe(),y.initChildren(null);const v=(P=this.inputs)==null?void 0:P.map((V,C)=>V.clone(y,f+"-argument-declaration-"+C+"-id",r));return y.inputs=v,a&&rr(this).map((V,C)=>V.clone(y,f+"-body-entity-"+C+"-id")),y}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project,t={}){const r={id:t.id||w.UUID.uuid(),version:t.version||"1",createdAt:t.createdAt||"2024-01-01T00:00:00.000Z",author:t.author||"1",previousVersion:t.previousVersion||null,deleted:t.deleted||!1,type:n.FunctionCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},a=O(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addFunctionCall(a),a}createInternalCall(e,t={}){const r={id:t.id||w.UUID.uuid(),version:t.version||"1",type:n.InternalCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toShallowJSON(),index:e.internalCalls.length},a=O(r,this.project);return a.setParent(e,null),a.initChildren(null),a}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],r=[...this.returnStatements].flatMap(a=>a.outputs);if(this.implements){const a=this.implements.outputs;return r.forEach(d=>{const o=a.find(c=>c===d.implements),l=e.find(c=>c.implements===d.implements);o&&!l&&e.push(d)}),u(e)}else return r.forEach(a=>{e.find(o=>o===a||U(o,this.project)===U(a,this.project)&&Ir(o.dataType,a.dataType))||e.push(a)}),u(e)}};p(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Re,"type",n.FunctionDeclaration),p(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),p(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),p(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),p(Re,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),p(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),p(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),p(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),p(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Re,"INMUATABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUATABLE_UPSTREAM_PROPERTIES]),p(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),p(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),p(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),p(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let gi=Re;function k7(i){const s=A3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.entity&&i.andChildrenGroup||i.entity&&i.orChildrenGroup||i.andChildrenGroup&&i.orChildrenGroup){const a=pe({id:i.id+"--"+Z.InvalidPropertiesCombination,message:`Data type with id "${i.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:R.Error,code:Z.InvalidPropertiesCombination,entity:i});r.push(a.error)}return Ye(i.errors,r)}function Z7(i,s){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],r=`'${re(t,"', '","' or '")}'`;if(i.parent)if(i.id===i.parent)e.push(new D({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 a=s.get(i.parent);a?t.includes(a.type)||e.push(new D({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type ${r}.`,issue:null})):e.push(new D({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new D({id:`${i.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${r}.`,issue:null}));if(i.entity){if(i.id===i.entity)return e.push(new D({id:`${i.id}--${i.entity}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const a=s.get(i.entity);a?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(a.type)||e.push(new D({id:`${i.id}--${i.entity}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new D({id:`${i.id}--${i.entity}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var k1=(i=>(i.Entity="entity",i))(k1||{});const be=class be extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"isList",null);p(this,"asType",null);p(this,"type",n.DataType);p(this,"options");p(this,"parentRelationType");p(this,"like");p(this,"implementationChooseOne",!1);p(this,"inferred",!1);p(this,"entity",null);p(this,"andChildrenGroup",null);p(this,"orChildrenGroup",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;e.entity&&(d=t.get(e.entity));const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:d,asType:e.asType,parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var c;let r=JSON.parse(JSON.stringify(e));const a=[],d=Z7(r,t);if(a.push(...d,...ot(r)),r.entity){const f=t.get(r.entity);if(f.type===n.DefinitionEntity){const v=qi(f).filter(E=>!E.interactive);if(v.length){const E=v.length>1?`entities with ids '${re(v.map(P=>P.id),"', '","' and '")}'`:`entity with id '${v[0].id}'`;a.push(new D({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${r.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
70
+ Please consider that any updates might affect the overlap with the signature of the parent entity's action descriptors.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.setImplements(null,r),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(e)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];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),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'parent' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else if(d)throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.indexOf(e);return t!==-1&&this.inputs.splice(t,1),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=O(t,this.project);return r.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.initialData.implements&&(this.implements=O(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.private=e.private||this.private,this.index=e.index||(e.index!==0?this.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Re.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Re.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),rr(this).forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),rr(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=rr(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){var t;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,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(r=>r.toJSON(e)),inputs:this.inputs.map(r=>r.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId: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})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(d=>d.toReference(e)),calls:this.calls.map(d=>d.toReference(e)),implements:((a=this.implements)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;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,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=j7(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=rr(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0,a=!1){var P;let d=ft(e,this);const o=this.toJSON(),l=t||w.UUID.uuid();o.inputs=[],o.calls=[];const c=l.split("-id"),f=c[c.length-1||0]||l;o.id=l;const y=lt(o,d);e?y.setParent(e,null):y.setParent(this.parent,null),r&&y.subscribe(),y.initChildren(null);const v=(P=this.inputs)==null?void 0:P.map((V,C)=>V.clone(y,f+"-argument-declaration-"+C+"-id",r));return y.inputs=v,a&&rr(this).map((V,C)=>V.clone(y,f+"-body-entity-"+C+"-id")),y}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project,t={}){const r={id:t.id||w.UUID.uuid(),version:t.version||"1",createdAt:t.createdAt||"2024-01-01T00:00:00.000Z",author:t.author||"1",previousVersion:t.previousVersion||null,deleted:t.deleted||!1,type:n.FunctionCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},a=O(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addFunctionCall(a),a}createInternalCall(e,t={}){const r={id:t.id||w.UUID.uuid(),version:t.version||"1",type:n.InternalCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toShallowJSON(),index:e.internalCalls.length},a=O(r,this.project);return a.setParent(e,null),a.initChildren(null),a}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],r=[...this.returnStatements].flatMap(a=>a.outputs);if(this.implements){const a=this.implements.outputs;return r.forEach(d=>{const o=a.find(c=>c===d.implements),l=e.find(c=>c.implements===d.implements);o&&!l&&e.push(d)}),u(e)}else return r.forEach(a=>{e.find(o=>o===a||U(o,this.project)===U(a,this.project)&&Ir(o.dataType,a.dataType))||e.push(a)}),u(e)}};p(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Re,"type",n.FunctionDeclaration),p(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),p(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),p(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),p(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),p(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),p(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),p(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),p(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Re,"INMUATABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUATABLE_UPSTREAM_PROPERTIES]),p(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),p(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),p(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),p(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let gi=Re;function k7(i){const s=A3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.entity&&i.andChildrenGroup||i.entity&&i.orChildrenGroup||i.andChildrenGroup&&i.orChildrenGroup){const a=pe({id:i.id+"--"+Z.InvalidPropertiesCombination,message:`Data type with id "${i.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:R.Error,code:Z.InvalidPropertiesCombination,entity:i});r.push(a.error)}return Ye(i.errors,r)}function Z7(i,s){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],r=`'${re(t,"', '","' or '")}'`;if(i.parent)if(i.id===i.parent)e.push(new D({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 a=s.get(i.parent);a?t.includes(a.type)||e.push(new D({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type ${r}.`,issue:null})):e.push(new D({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new D({id:`${i.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${r}.`,issue:null}));if(i.entity){if(i.id===i.entity)return e.push(new D({id:`${i.id}--${i.entity}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const a=s.get(i.entity);a?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(a.type)||e.push(new D({id:`${i.id}--${i.entity}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new D({id:`${i.id}--${i.entity}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var k1=(i=>(i.Entity="entity",i))(k1||{});const be=class be extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"isList",null);p(this,"asType",null);p(this,"type",n.DataType);p(this,"options");p(this,"parentRelationType");p(this,"like");p(this,"implementationChooseOne",!1);p(this,"inferred",!1);p(this,"entity",null);p(this,"andChildrenGroup",null);p(this,"orChildrenGroup",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;e.entity&&(d=t.get(e.entity));const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:d,asType:e.asType,parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var c;let r=JSON.parse(JSON.stringify(e));const a=[],d=Z7(r,t);if(a.push(...d,...ot(r)),r.entity){const f=t.get(r.entity);if(f.type===n.DefinitionEntity){const v=qi(f).filter(E=>!E.interactive);if(v.length){const E=v.length>1?`entities with ids '${re(v.map(P=>P.id),"', '","' and '")}'`:`entity with id '${v[0].id}'`;a.push(new D({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${r.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
71
71
  ${xi}`,issue:null}))}}}const o=r.parent&&t.get(r.parent)||t.getBuiltIn(r.parent),l=o?Ji(o):null;if(l)a.push(new D({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${U(l,t)}" with id '${l.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(o){const f=o.type,y=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(y.includes(f)&&(r.parentRelationType&&a.push(new D({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${f}'.
72
72
  The entitities of type '${re(y,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const v=(c=o.dataType)==null?void 0:c.id;a.push(new D({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${r.parent}' and type '${f}', because it already has a 'data-type' child with id '${v}'.
73
73
  The entitities of type '${re(y,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
74
74
  ${qr({describe_entity:v})}
75
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}f===n.DataType&&(!r.parentRelationType||!(r.parentRelationType===Et.AndDataTypeGroup||r.parentRelationType===Et.OrDataTypeGroup))&&a.push(new D({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:a,modifiedData:r}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const r of e)if(r.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||Ji(this.parent)?!0:!(!this.entity&&!this.isGroup)}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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(null),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`Data type with id '${this.id}' has a parent reference '${d}' that isn't found in the project`)}else throw new Error(`Data type with id '${this.id}' must have a parent`);if(this.initialData.entity){const d=g(this.initialData.entity),o=this.project.get(d);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.type===n.DataType?this.parentRelationType===Et.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Et.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){var t,r;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=a}else this.entity=O(this.initialData.entity,this.project),((r=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:r.id)===this.id&&this.entity.setParent(this,null),this.entity.type===n.DefinitionEntity&&this.entity.initChildren(e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const d=O(a,this.project);return d.setParent(this,null),d.initChildren(null),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const d=O(a,this.project);return d.setParent(this,null),d.initChildren(null),d})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.options=e.options||this.options,this.parentRelationType=e.parentRelationType||this.parentRelationType,this.isList=e.isList!==void 0?e.isList:this.isList,this.inferred=e.inferred!==void 0?e.inferred:this.inferred,this.like=e.like!==void 0?e.like:this.like,this.asType=e.asType!==void 0?e.asType:this.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:this.implementationChooseOne,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await be.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:l,removed:c}=this.entity.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(!e){this.parent.type===n.DataType&&this.parent.removeChildGroup(this);const l=this.parent;if(l.type===n.DataType){if(this.parentRelationType===Et.AndDataTypeGroup){if(Array.isArray(l.andChildrenGroup)){const c=l.andChildrenGroup.findIndex(f=>f.id===this.id);c!==-1&&l.andChildrenGroup.splice(c,1)}}else if(this.parentRelationType===Et.OrDataTypeGroup&&Array.isArray(l.orChildrenGroup)){const c=l.orChildrenGroup.findIndex(f=>f.id===this.id);c!==-1&&l.orChildrenGroup.splice(c,1)}}else this.parent.removeDataType();r.push(l)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);r.push(...o)}if(this.parent.type===n.DataType){const o=this.parent;Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this)}if(this.parent.type===n.DataType){const o=this.parent;this.parentRelationType===Et.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Et.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),r.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlat(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlat(e)))||[],...((d=this.entity)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatIds(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatIds(e)))||[],...((d=this.entity)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;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,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((r=this.orChildrenGroup)==null?void 0:r.map(o=>o.toJSON(e)))||null,entity:((a=this.entity)==null?void 0:a.parent)===this?this.entity.toJSON(e):((d=this.entity)==null?void 0:d.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((c=this.andChildrenGroup)==null?void 0:c.map(E=>E.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(E=>E.toJSONClone({...e,newId:null})))||null,entity:((y=this.entity)==null?void 0:y.parent)===this?this.entity.toJSONClone({...e,newId:null}):((v=this.entity)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(l=>l.toReference(e)))||null,orChildrenGroup:((d=this.orChildrenGroup)==null?void 0:d.map(l=>l.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatJSON(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatJSON(e)))||[],...((d=this.entity)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,r;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(a=>a.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(a=>a.clearErrors()),this.inferred&&((r=this.entity)==null||r.clearErrors()),this}validate(){const e=k7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var P,V,C;let a=ft(e,this),d=e||this.parent;const o=t||w.UUID.uuid(),l=o.split("-id"),c=l[l.length-1||0]||o,f={id:o,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:d.toReference()},y=lt(f,a);e&&y.setParent(e,null),r&&y.subscribe(),y.initChildren(null);const v=(P=this.andChildrenGroup)==null?void 0:P.map((G,j)=>G.clone(y,c+"-and-group-data-type-"+j+"-id",r)),E=(V=this.orChildrenGroup)==null?void 0:V.map((G,j)=>G.clone(y,c+"-or-group-data-type-"+j+"-id",r));if(y.andChildrenGroup=v||null,y.orChildrenGroup=E||null,this.entity&&this.entity.type===n.DefinitionEntity&&((C=this.entity)==null?void 0:C.parent)===this){const G=this.entity.clone(y,w.UUID.uuid(),r);y.setEntity(G)}else this.entity&&y.setEntity(this.entity);return y}merge(e){const t=[],r=[],a=[],d=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},null),t.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},null),t.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},null),t.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const o=e.entity.clone(this,w.UUID.uuid(),!0);this.setEntity(o),r.push(o)}else e.entity&&(this.setEntity(e.entity),t.push(this));this.inferred||(this.metaSync({inferred:!0},null),t.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},null),t.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o,removed:l}=this.entity.remove({ignoreUpstream:!0});a.push(...l),o.push(...o)}e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this));return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===n.DefinitionEntity||this.entity.name===M.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-from-inputs"))){var l;const r=[],a=[],d=[],o=[];if(!this.inferred)return t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&e.length){const c={id:w.UUID.uuid(),type:n.DefinitionEntity,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:U(this.parent,this.project)+" data type definition",description:((l=this.parent)==null?void 0:l.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},f=O(c,this.project);f.setParent(this,t),f.initChildren(t),t==null||t.add(f,b.Added),f.metaSync(c,t),this.setEntity(f),t==null||t.add(this,b.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:c,added:f,removed:y,affected:v}=this.entity.inferFromInputs(e,t);a.push(...c),r.push(...f),d.push(...y),o.push(...v)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:this}}};p(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(be,"type",n.DataType),p(be,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),p(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES]),p(be,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),p(be,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),p(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"inferred"]),p(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),p(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),p(be,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),p(be,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),p(be,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),p(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),p(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let On=be;function q7(i){var o;const s=a3(),e=i.toJSON();s.safeParse(e).success;const r=J7(i),a=ci(i),d=[...r,...a];if(i.id==="exec-sequentially-operation-call-id"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});d.push(l.error)}return i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate(),Ye(i.errors,d)}function J7(i){const s=[];return i.inputs.forEach(e=>{e.validate()}),Ye(i.errors,s)}var Z1=(i=>(i.Parent="parent",i))(Z1||{});const Ae=class Ae extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.Operation);p(this,"declaration");p(this,"inputs",[]);p(this,"outputs",[]);p(this,"process",null);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"error",null);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),f={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:r},y=O(f,t);return y.setParent(r,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=g(r.declaration);if(o){const l=pP(o,t);a.push(...l)}else{const l=`
75
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}f===n.DataType&&(!r.parentRelationType||!(r.parentRelationType===Et.AndDataTypeGroup||r.parentRelationType===Et.OrDataTypeGroup))&&a.push(new D({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:a,modifiedData:r}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const r of e)if(r.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||Ji(this.parent)?!0:!(!this.entity&&!this.isGroup)}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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(null),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`Data type with id '${this.id}' has a parent reference '${d}' that isn't found in the project`)}else throw new Error(`Data type with id '${this.id}' must have a parent`);if(this.initialData.entity){const d=g(this.initialData.entity),o=this.project.get(d);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.type===n.DataType?this.parentRelationType===Et.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Et.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){var t,r;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=a}else this.entity=O(this.initialData.entity,this.project),((r=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:r.id)===this.id&&this.entity.setParent(this,null),this.entity.type===n.DefinitionEntity&&this.entity.initChildren(e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const d=O(a,this.project);return d.setParent(this,null),d.initChildren(null),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const d=O(a,this.project);return d.setParent(this,null),d.initChildren(null),d})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.options=e.options||this.options,this.parentRelationType=e.parentRelationType||this.parentRelationType,this.isList=e.isList!==void 0?e.isList:this.isList,this.inferred=e.inferred!==void 0?e.inferred:this.inferred,this.like=e.like!==void 0?e.like:this.like,this.asType=e.asType!==void 0?e.asType:this.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:this.implementationChooseOne,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await be.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:l,removed:c}=this.entity.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(!e){this.parent.type===n.DataType&&this.parent.removeChildGroup(this);const l=this.parent;if(l.type===n.DataType){if(this.parentRelationType===Et.AndDataTypeGroup){if(Array.isArray(l.andChildrenGroup)){const c=l.andChildrenGroup.findIndex(f=>f.id===this.id);c!==-1&&l.andChildrenGroup.splice(c,1)}}else if(this.parentRelationType===Et.OrDataTypeGroup&&Array.isArray(l.orChildrenGroup)){const c=l.orChildrenGroup.findIndex(f=>f.id===this.id);c!==-1&&l.orChildrenGroup.splice(c,1)}}else this.parent.removeDataType();r.push(l)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);r.push(...o)}if(this.parent.type===n.DataType){const o=this.parent;Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this)}if(this.parent.type===n.DataType){const o=this.parent;this.parentRelationType===Et.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Et.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),r.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlat(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlat(e)))||[],...((d=this.entity)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatIds(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatIds(e)))||[],...((d=this.entity)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;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,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((r=this.orChildrenGroup)==null?void 0:r.map(o=>o.toJSON(e)))||null,entity:((a=this.entity)==null?void 0:a.parent)===this?this.entity.toJSON(e):((d=this.entity)==null?void 0:d.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((c=this.andChildrenGroup)==null?void 0:c.map(E=>E.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(E=>E.toJSONClone({...e,newId:null})))||null,entity:((y=this.entity)==null?void 0:y.parent)===this?this.entity.toJSONClone({...e,newId:null}):((v=this.entity)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(l=>l.toReference(e)))||null,orChildrenGroup:((d=this.orChildrenGroup)==null?void 0:d.map(l=>l.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatJSON(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatJSON(e)))||[],...((d=this.entity)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,r;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(a=>a.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(a=>a.clearErrors()),this.inferred&&((r=this.entity)==null||r.clearErrors()),this}validate(){const e=k7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var P,V,C;let a=ft(e,this),d=e||this.parent;const o=t||w.UUID.uuid(),l=o.split("-id"),c=l[l.length-1||0]||o,f={id:o,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:d.toReference()},y=lt(f,a);e&&y.setParent(e,null),r&&y.subscribe(),y.initChildren(null);const v=(P=this.andChildrenGroup)==null?void 0:P.map((G,j)=>G.clone(y,c+"-and-group-data-type-"+j+"-id",r)),E=(V=this.orChildrenGroup)==null?void 0:V.map((G,j)=>G.clone(y,c+"-or-group-data-type-"+j+"-id",r));if(y.andChildrenGroup=v||null,y.orChildrenGroup=E||null,this.entity&&this.entity.type===n.DefinitionEntity&&((C=this.entity)==null?void 0:C.parent)===this){const G=this.entity.clone(y,w.UUID.uuid(),r);y.setEntity(G)}else this.entity&&y.setEntity(this.entity);return y}merge(e){const t=[],r=[],a=[],d=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},null),t.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},null),t.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},null),t.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const o=e.entity.clone(this,w.UUID.uuid(),!0);this.setEntity(o),r.push(o)}else e.entity&&(this.setEntity(e.entity),t.push(this));this.inferred||(this.metaSync({inferred:!0},null),t.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},null),t.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o,removed:l}=this.entity.remove({ignoreUpstream:!0});a.push(...l),o.push(...o)}e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t.push(this));return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===n.DefinitionEntity||this.entity.name===M.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-from-inputs"))){var l;const r=[],a=[],d=[],o=[];if(!this.inferred)return t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&e.length){const c={id:w.UUID.uuid(),type:n.DefinitionEntity,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:U(this.parent,this.project)+" data type definition",description:((l=this.parent)==null?void 0:l.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},f=O(c,this.project);f.setParent(this,t),f.initChildren(t),t==null||t.add(f,b.Added),f.metaSync(c,t),this.setEntity(f),t==null||t.add(this,b.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:c,added:f,removed:y,affected:v}=this.entity.inferFromInputs(e,t);a.push(...c),r.push(...f),d.push(...y),o.push(...v)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:this}}};p(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(be,"type",n.DataType),p(be,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),p(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES]),p(be,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),p(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),p(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"inferred"]),p(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),p(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),p(be,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),p(be,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),p(be,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),p(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),p(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let On=be;function q7(i){var o;const s=a3(),e=i.toJSON();s.safeParse(e).success;const r=J7(i),a=ci(i),d=[...r,...a];if(i.id==="exec-sequentially-operation-call-id"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});d.push(l.error)}return i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate(),Ye(i.errors,d)}function J7(i){const s=[];return i.inputs.forEach(e=>{e.validate()}),Ye(i.errors,s)}var Z1=(i=>(i.Parent="parent",i))(Z1||{});const Ae=class Ae extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.Operation);p(this,"declaration");p(this,"inputs",[]);p(this,"outputs",[]);p(this,"process",null);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"error",null);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),f={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:r},y=O(f,t);return y.setParent(r,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=g(r.declaration);if(o){const l=pP(o,t);a.push(...l)}else{const l=`
76
76
  All built-in 'action-descriptor' entity ids are:
77
77
  - ${t.operationDeclarations.map(c=>`${c.id} (${U(c,t)})`).join(`
78
78
  - `)}.
79
79
  `;a.push(new D({id:`${r.id}--${I.InvalidReference}`,code:I.InvalidReference,severity:R.Error,message:`Entity of type "${n.Operation}" with id "${r.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'action-descriptor' entity.
80
80
  References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${l}`,issue:null}))}return{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
81
81
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
82
- 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:f,added:y,removed:v}=this.syncMissingFixedOutputs(e),{updated:E,added:P,removed:V}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...f,...E),r.push(...l,...y,...E),a.push(...c,...v,...E),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?r.setParent(this.parent.parent,null):r.type!==n.InternalCall&&r.setParent(this.parent,null),r.initChildren(e),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=O(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ae.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ae.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.process){const{updated:c,removed:f}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}if(this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.outputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.error){const{updated:c,removed:f}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.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,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(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=q7(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=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>y.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id}));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1},e)});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.outputs.filter(y=>y.parentRelationType===_.FixedReturns&&!this.outputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id}));this.outputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.outputs.forEach(P=>{P.index>=y.index&&P.index++});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:y.toJSON(),defaultValue:null,writesValues:[],index:y.index,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.outputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedOutputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ae,"type",n.Operation),p(Ae,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES]),p(Ae,"MUTABLE_BASE_PROPERTIES",[]),p(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),p(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),p(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),p(Ae,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),p(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Bi=Ae;function W7(i){const s=k3(),e=i.toJSON();s.safeParse(e).success;const r=rr(i);i.inputs.forEach(d=>d.validate()),r.forEach(d=>d.validate());const a=[];return Ye(i.errors,a)}const De=class De extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"collapsed");p(this,"type",n.GlobalEvent);p(this,"inputs",[]);p(this,"calls",[]);p(this,"parent");p(this,"implements");p(this,"detachedChildren",[]);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);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.collapsed=e.collapsed}static fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a;e.implements&&(a=t.getBuiltIn(e.implements));const d={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=O(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{},t);if(r=d.modifiedData,a.push(...d.errors,...ot(r)),!e.implements)a.push(new D({id:`${e.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'implements' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
82
+ 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:f,added:y,removed:v}=this.syncMissingFixedOutputs(e),{updated:E,added:P,removed:V}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...f,...E),r.push(...l,...y,...E),a.push(...c,...v,...E),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?r.setParent(this.parent.parent,null):r.type!==n.InternalCall&&r.setParent(this.parent,null),r.initChildren(e),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=O(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ae.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ae.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.process){const{updated:c,removed:f}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}if(this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.outputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.error){const{updated:c,removed:f}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.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,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(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=q7(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=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>y.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id}));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1},e)});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.outputs.filter(y=>y.parentRelationType===_.FixedReturns&&!this.outputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id}));this.outputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.outputs.forEach(P=>{P.index>=y.index&&P.index++});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:y.toJSON(),defaultValue:null,writesValues:[],index:y.index,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.outputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedOutputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ae,"type",n.Operation),p(Ae,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES]),p(Ae,"MUTABLE_BASE_PROPERTIES",[]),p(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),p(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),p(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),p(Ae,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),p(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Bi=Ae;function W7(i){const s=k3(),e=i.toJSON();s.safeParse(e).success;const r=rr(i);i.inputs.forEach(d=>d.validate()),r.forEach(d=>d.validate());const a=[];return Ye(i.errors,a)}const De=class De extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"collapsed");p(this,"type",n.GlobalEvent);p(this,"inputs",[]);p(this,"calls",[]);p(this,"parent");p(this,"implements");p(this,"detachedChildren",[]);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);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.collapsed=e.collapsed}static fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a;e.implements&&(a=t.getBuiltIn(e.implements));const d={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=O(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{},t);if(r=d.modifiedData,a.push(...d.errors,...ot(r)),!e.implements)a.push(new D({id:`${e.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'implements' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
83
83
  ${Sd(t)}`,issue:null}));else if(!t.get(e.implements))a.push(new D({id:`${e.id}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that isn't found in the project. The 'implements' property must point to one of the built-in action descriptors reserved for 'global-event' entities.
84
84
  ${Sd(t)}`,issue:null}));else if(!t.globalEventActionDescriptors.find(c=>c.id===e.implements))a.push(new D({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that isn't pointing to an action descriptor reserved for 'global-event' entities.
85
85
  ${Sd(t)}`,issue:null}));else{const c=t.events.find(f=>f.implements.id===e.implements);c&&a.push(new D({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that points to an action descriptor that is already implemented by another global event with id '${c.id}' in the project. Each global event must implement a unique action descriptor.
86
- You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===gd.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addGlobalEvent(this),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=O(t,this.project);return r.addEntryCaller(this,null),r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.implements=O(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await De.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await De.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),rr(this).forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),rr(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=rr(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}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,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),calls:this.calls.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=W7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=rr(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0,a=!1){var P;let d=ft(e,this);const o=this.toJSON(),l=t||w.UUID.uuid();o.inputs=[];const c=l.split("-id"),f=c[c.length-1||0]||l;o.id=l;const y=lt(o,d);e?y.setParent(e,null):y.setParent(this.parent,null),r&&y.subscribe(),y.initChildren(null);const v=(P=this.inputs)==null?void 0:P.map((V,C)=>V.clone(y,f+"-argument-declaration-"+C+"-id",r));return y.inputs=v,a&&rr(this).map((V,C)=>V.clone(y,f+"-body-entity-"+C+"-id")),y}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};p(De,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(De,"type",n.GlobalEvent),p(De,"USER_MANAGED_PARENT_TYPES",[n.Project]),p(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),p(De,"MUTABLE_BASE_PROPERTIES",["description"]),p(De,"INMUTABLE_BASE_PROPERTIES",["id","version","name","type"]),p(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),p(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),p(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),p(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),p(De,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(De,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),p(De,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),p(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let Vn=De;function Y7(i){var a;const s=g6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var mp=(i=>(i.Parent="parent",i))(mp||{});const Ge=class Ge extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.BreakStatement);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"throws",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),o=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),l=e.calledByError.map(y=>{const v=g(y);return t.get(v)}),c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},f=O(c,t);return f.setParent(a,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
86
+ You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===gd.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addGlobalEvent(this),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=O(t,this.project);return r.addEntryCaller(this,null),r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.implements=O(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await De.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await De.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),rr(this).forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),rr(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=rr(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}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,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),calls:this.calls.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=W7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=rr(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0,a=!1){var P;let d=ft(e,this);const o=this.toJSON(),l=t||w.UUID.uuid();o.inputs=[];const c=l.split("-id"),f=c[c.length-1||0]||l;o.id=l;const y=lt(o,d);e?y.setParent(e,null):y.setParent(this.parent,null),r&&y.subscribe(),y.initChildren(null);const v=(P=this.inputs)==null?void 0:P.map((V,C)=>V.clone(y,f+"-argument-declaration-"+C+"-id",r));return y.inputs=v,a&&rr(this).map((V,C)=>V.clone(y,f+"-body-entity-"+C+"-id")),y}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};p(De,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(De,"type",n.GlobalEvent),p(De,"USER_MANAGED_PARENT_TYPES",[n.Project]),p(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),p(De,"MUTABLE_BASE_PROPERTIES",["description"]),p(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),p(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),p(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),p(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),p(De,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(De,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),p(De,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),p(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let Vn=De;function Y7(i){var a;const s=g6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var mp=(i=>(i.Parent="parent",i))(mp||{});const Ge=class Ge extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.BreakStatement);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"throws",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),o=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),l=e.calledByError.map(y=>{const v=g(y);return t.get(v)}),c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},f=O(c,t);return f.setParent(a,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
87
87
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
88
88
  You shouldn't have to manually update a 'parent' property.
89
- Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addCall(this),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addSuccessCall(this),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addErrorCall(this),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=O(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ge.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,outputs:this.outputs.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=Y7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.outputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.outputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-return-declaration-"+P+"-id",r));return f.outputs=y,this.throws&&(f.throws=this.throws.clone(f,c+"-throws-id",r)),f}};p(Ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ge,"type",n.BreakStatement),p(Ge,"USER_MANAGED_PARENT_TYPES",[n.Loop]),p(Ge,"PARENT_TYPES",[...Ge.USER_MANAGED_PARENT_TYPES]),p(Ge,"MUTABLE_BASE_PROPERTIES",[]),p(Ge,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Ge,"BASE_PROPERTIES",[...Ge.MUTABLE_BASE_PROPERTIES,...Ge.INMUTABLE_BASE_PROPERTIES]),p(Ge,"MUTABLE_META_PROPERTIES",["x","y"]),p(Ge,"INMUTABLE_META_PROPERTIES",[...Ge.INMUTABLE_BASE_PROPERTIES]),p(Ge,"META_PROPERTIES",[...Ge.MUTABLE_META_PROPERTIES,...Ge.INMUTABLE_META_PROPERTIES]),p(Ge,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(Ge,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(Ge,"UPSTREAM_PROPERTIES",[...Ge.MUTABLE_UPSTREAM_PROPERTIES,...Ge.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),p(Ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ge,"DOWNSTREAM_PROPERTIES",[...Ge.MUTABLE_DOWNSTREAM_PROPERTIES,...Ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ge,"PROPERTIES",[...Ge.META_PROPERTIES,...Ge.UPSTREAM_PROPERTIES,...Ge.DOWNSTREAM_PROPERTIES]);let wn=Ge;function z7(i){var d,o;const s=y6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(d=i.error)==null||d.validate(),(o=i.body)==null||o.validate();const a=[...ci(i)];return Ye(i.errors,a)}function H7(i){const s=iD(),e=i.toJSON();s.safeParse(e).success,i.inputs.flatMap(a=>a.validate()),i.outputs.flatMap(a=>a.validate());const r=[];return Ye(i.errors,r)}var q1=(i=>(i.Success="success",i.Error="error",i.Break="break",i.Continue="continue",i.Return="return",i))(q1||{});const Pe=class Pe extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"implementation",null);p(this,"parent",null);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static fromGenerationTarget(e,t){let r=null;if(e.parent){const o=g(e.parent);r=t.get(o)}const a={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:r},d=O(a,t);return r&&d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);r=d.modifiedData;const o=r.parent?t.get(r.parent):null;if(o&&o.type===n.DefinitionEntity){const l=o,f=qi(l).filter(y=>!y.interactive);if(f.length){let y=f.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${re(f.map(v=>U(v,v.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${U(f[0],f[0].project)}").`;y+=`
89
+ Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addCall(this),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addSuccessCall(this),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addErrorCall(this),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=O(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ge.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,outputs:this.outputs.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=Y7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.outputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.outputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-return-declaration-"+P+"-id",r));return f.outputs=y,this.throws&&(f.throws=this.throws.clone(f,c+"-throws-id",r)),f}};p(Ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ge,"type",n.BreakStatement),p(Ge,"USER_MANAGED_PARENT_TYPES",[n.Loop]),p(Ge,"PARENT_TYPES",[...Ge.USER_MANAGED_PARENT_TYPES]),p(Ge,"MUTABLE_BASE_PROPERTIES",[]),p(Ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ge,"BASE_PROPERTIES",[...Ge.MUTABLE_BASE_PROPERTIES,...Ge.INMUTABLE_BASE_PROPERTIES]),p(Ge,"MUTABLE_META_PROPERTIES",["x","y"]),p(Ge,"INMUTABLE_META_PROPERTIES",[...Ge.INMUTABLE_BASE_PROPERTIES]),p(Ge,"META_PROPERTIES",[...Ge.MUTABLE_META_PROPERTIES,...Ge.INMUTABLE_META_PROPERTIES]),p(Ge,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(Ge,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(Ge,"UPSTREAM_PROPERTIES",[...Ge.MUTABLE_UPSTREAM_PROPERTIES,...Ge.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),p(Ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ge,"DOWNSTREAM_PROPERTIES",[...Ge.MUTABLE_DOWNSTREAM_PROPERTIES,...Ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ge,"PROPERTIES",[...Ge.META_PROPERTIES,...Ge.UPSTREAM_PROPERTIES,...Ge.DOWNSTREAM_PROPERTIES]);let wn=Ge;function z7(i){var d,o;const s=y6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(d=i.error)==null||d.validate(),(o=i.body)==null||o.validate();const a=[...ci(i)];return Ye(i.errors,a)}function H7(i){const s=iD(),e=i.toJSON();s.safeParse(e).success,i.inputs.flatMap(a=>a.validate()),i.outputs.flatMap(a=>a.validate());const r=[];return Ye(i.errors,r)}var q1=(i=>(i.Success="success",i.Error="error",i.Break="break",i.Continue="continue",i.Return="return",i))(q1||{});const Pe=class Pe extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"implementation",null);p(this,"parent",null);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static fromGenerationTarget(e,t){let r=null;if(e.parent){const o=g(e.parent);r=t.get(o)}const a={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:r},d=O(a,t);return r&&d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);r=d.modifiedData;const o=r.parent?t.get(r.parent):null;if(o&&o.type===n.DefinitionEntity){const l=o,f=qi(l).filter(y=>!y.interactive);if(f.length){let y=f.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${re(f.map(v=>U(v,v.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${U(f[0],f[0].project)}").`;y+=`
90
90
  ${xi}`,a.push(new D({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:R.Error,message:y,issue:null}))}}else if(o&&o.type===n.DataType){const l=o;l.entity&&a.push(new D({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
91
91
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
92
92
  ${qr({describe_entity:l.entity.id})}
93
93
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}syncOperationInstance(e,t){return{updated:[],added:[],removed:[],affected:[],self:e}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type"))){const r=np(e);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type"))){const r=sp(e);return t==null||t.attemptAutoclose("infer-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
94
- 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}):{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.outputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.error){const l=this.error.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.outputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;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,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}implementAsFunctionDeclaration(e){var a;const t=this.inputs.map((d,o)=>{var c;const l={id:e+"--"+d.id+"--parent-ref",type:n.GenericReference,version:"1",entityType:n.FunctionDeclaration,entityId:e};return{id:w.UUID.uuid(),version:d.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:d.name,required:d.required,implements:d.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:d.description,index:o,dataType:((c=d.dataType)==null?void 0:c.toJSON())||null,parent:l}}),r=[];if(this.outputs.length){const d=this.outputs.map((f,y)=>{var E;const v={id:e+"--return-statement--"+f.id+"--parent-ref",type:n.GenericReference,entityId:e,version:"1",entityType:n.ReturnStatement};return{id:w.UUID.uuid(),version:f.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:f.name,description:f.description,readsValue:null,constant:!0,required:f.required,defaultValue:null,implements:f.toJSON(),isError:!1,index:y,dataType:((E=f.dataType)==null?void 0:E.toJSON())||null,parent:v}}),o={id:e+"--return-statement-parent-ref",type:n.GenericReference,version:"1",entityType:n.FunctionDeclaration,entityId:e},l={id:e+"--return-statement-called-by-ref",type:n.GenericReference,version:"1",entityType:n.FunctionDeclaration,entityId:e},c={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:d,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[l],parent:o,x:0,y:0};r.push(c)}return{id:e,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:t,calls:r,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((a=this.parent)==null?void 0:a.toReference())||null,x:0,y:0}}implementAsLoop(e){const t=e||this.project,r=w.UUID.uuid(),a={id:r,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:t.toReference()};this.inputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Loop}};a.inputs.push(f)}),this.outputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Loop}};a.outputs.push(f)});const d={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"body",description:null,inputs:[],calls:[],implements:null,index:null,collapsed:!1,private:!1,x:0,y:0,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Loop}};d.inputs=[{id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Current iteration number",description:"The number of the current iteration of the loop. Starts at 1.",dataType:null,required:!0,constant:!0,defaultValue:null,writesValues:[],implements:null,index:0,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:"1",entityType:n.FunctionDeclaration}},{id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Previous iterations results",description:"The results of the previous iterations of the loop.",dataType:null,constant:!0,required:!0,defaultValue:null,writesValues:[],implements:null,index:1,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:"1",entityType:n.FunctionDeclaration}}],a.body=d;const o=O(a,this.project);return o.setParent(t,null),o.initChildren(null),o}implementAsOperation(e,t){const r=e||this.project,a=t||w.UUID.uuid(),d={id:a,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,successCalls:[],errorCalls:[],process:null,calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:r.toReference()};if(this.inputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:a,version:"1",entityType:n.Operation}};d.inputs.push(f)}),this.outputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:a,version:"1",entityType:n.Operation}};d.outputs.push(f)}),this.error){const l={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:this.error,writesValues:[],defaultValue:null,index:-1,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:a,version:"1",entityType:n.Operation}};d.error=l}const o=O(d,this.project);return o.setParent(r,null),o.initChildren(null),o}implementAsCondition(e){const t=e||this.project,r=w.UUID.uuid(),a={id:r,version:this.version,type:n.Condition,declaration:this.toJSON(),operator:null,inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:t.toReference()};this.inputs.forEach((o,l)=>{const c={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,declaration:o,defaultValue:null,readsValue:null,index:l,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Condition}};a.inputs.push(c)});const d=O(a,this.project);return d.setParent(t,null),d.initChildren(null),d}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=H7(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())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):this.parent&&f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-argument-value-descriptor-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-return-value-descriptor-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-action-descriptor-id",r)),f}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};p(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Pe,"type",n.ActionDescriptor),p(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),p(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),p(Pe,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(Pe,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),p(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES]),p(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),p(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),p(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),p(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),p(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let Ze=Pe;var J1=(i=>(i.Parent="parent",i))(J1||{});const ne=class ne extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.Loop);p(this,"declaration");p(this,"inputs",[]);p(this,"outputs",[]);p(this,"process",null);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"error",null);p(this,"outputsDeclarations",[]);p(this,"body");p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"parent");p(this,"detachedChildren",[]);p(this,"currentIterationNumberArgumentDeclaration");p(this,"currentValueArgumentDeclaration",null);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),f={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},y=O(f,t);return y.setParent(r,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new D({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
94
+ 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}):{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.outputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.error){const l=this.error.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.outputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;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,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}implementAsFunctionDeclaration(e){var a;const t=this.inputs.map((d,o)=>{var c;const l={id:e+"--"+d.id+"--parent-ref",type:n.GenericReference,version:"1",entityType:n.FunctionDeclaration,entityId:e};return{id:w.UUID.uuid(),version:d.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:d.name,required:d.required,implements:d.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:d.description,index:o,dataType:((c=d.dataType)==null?void 0:c.toJSON())||null,parent:l}}),r=[];if(this.outputs.length){const d=this.outputs.map((f,y)=>{var E;const v={id:e+"--return-statement--"+f.id+"--parent-ref",type:n.GenericReference,entityId:e,version:"1",entityType:n.ReturnStatement};return{id:w.UUID.uuid(),version:f.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:f.name,description:f.description,readsValue:null,constant:!0,required:f.required,defaultValue:null,implements:f.toJSON(),isError:!1,index:y,dataType:((E=f.dataType)==null?void 0:E.toJSON())||null,parent:v}}),o={id:e+"--return-statement-parent-ref",type:n.GenericReference,version:"1",entityType:n.FunctionDeclaration,entityId:e},l={id:e+"--return-statement-called-by-ref",type:n.GenericReference,version:"1",entityType:n.FunctionDeclaration,entityId:e},c={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:d,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[l],parent:o,x:0,y:0};r.push(c)}return{id:e,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:t,calls:r,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((a=this.parent)==null?void 0:a.toReference())||null,x:0,y:0}}implementAsLoop(e){const t=e||this.project,r=w.UUID.uuid(),a={id:r,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:t.toReference()};this.inputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Loop}};a.inputs.push(f)}),this.outputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Loop}};a.outputs.push(f)});const d={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"body",description:null,inputs:[],calls:[],implements:null,index:null,collapsed:!1,private:!1,x:0,y:0,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Loop}};d.inputs=[{id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Current iteration number",description:"The number of the current iteration of the loop. Starts at 1.",dataType:null,required:!0,constant:!0,defaultValue:null,writesValues:[],implements:null,index:0,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:"1",entityType:n.FunctionDeclaration}},{id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Previous iterations results",description:"The results of the previous iterations of the loop.",dataType:null,constant:!0,required:!0,defaultValue:null,writesValues:[],implements:null,index:1,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:"1",entityType:n.FunctionDeclaration}}],a.body=d;const o=O(a,this.project);return o.setParent(t,null),o.initChildren(null),o}implementAsOperation(e,t){const r=e||this.project,a=t||w.UUID.uuid(),d={id:a,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,successCalls:[],errorCalls:[],process:null,calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:r.toReference()};if(this.inputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:a,version:"1",entityType:n.Operation}};d.inputs.push(f)}),this.outputs.forEach((l,c)=>{const f={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:a,version:"1",entityType:n.Operation}};d.outputs.push(f)}),this.error){const l={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:this.error,writesValues:[],defaultValue:null,index:-1,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:a,version:"1",entityType:n.Operation}};d.error=l}const o=O(d,this.project);return o.setParent(r,null),o.initChildren(null),o}implementAsCondition(e){const t=e||this.project,r=w.UUID.uuid(),a={id:r,version:this.version,type:n.Condition,declaration:this.toJSON(),operator:null,inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:t.toReference()};this.inputs.forEach((o,l)=>{const c={id:w.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,declaration:o,defaultValue:null,readsValue:null,index:l,parent:{id:w.UUID.uuid(),type:n.GenericReference,entityId:r,version:"1",entityType:n.Condition}};a.inputs.push(c)});const d=O(a,this.project);return d.setParent(t,null),d.initChildren(null),d}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=H7(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())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):this.parent&&f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-argument-value-descriptor-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-return-value-descriptor-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-action-descriptor-id",r)),f}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};p(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Pe,"type",n.ActionDescriptor),p(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),p(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),p(Pe,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),p(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES]),p(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),p(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),p(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),p(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),p(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let Ze=Pe;var J1=(i=>(i.Parent="parent",i))(J1||{});const ne=class ne extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.Loop);p(this,"declaration");p(this,"inputs",[]);p(this,"outputs",[]);p(this,"process",null);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"error",null);p(this,"outputsDeclarations",[]);p(this,"body");p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"parent");p(this,"detachedChildren",[]);p(this,"currentIterationNumberArgumentDeclaration");p(this,"currentValueArgumentDeclaration",null);p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),f={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},y=O(f,t);return y.setParent(r,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new D({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
95
95
  ${$d(t)}`,issue:null})):a.push(new D({id:`${e.id}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
96
96
  ${$d(t)}`,issue:null})):a.push(new D({id:`${e.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
97
97
  ${$d(t)}`,issue:null})),{errors:a,modifiedData:r}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${U(e,e.project)}'`}static fromBodyArgumentDeclarationToReturnDeclarationName(e){const t=e.name.replace("Previous iteration results of '","");return t.slice(0,t.length-1)}static fromReturnDeclarationToLoopOutputDeclarationName(e){return`Result list of '${U(e,e.project)}'`}static fromLoopOutputDeclarationToReturnDeclarationName(e){const t=e.name.replace("Result list of '","");return t.slice(0,t.length-1)}static fromLoopOutputDeclarationToBodyArgumentDeclarationName(e){return e.name.replace("Result list of '","Previous iteration results of '")}static fromBodyArgumentDeclarationToLoopOutputDeclarationName(e){return e.name.replace("Previous iteration results of '","Result list of '")}get continueStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===hp.Parent&&t.entity.type===n.ContinueStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}get breakStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===mp.Parent&&t.entity.type===n.BreakStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
98
98
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
99
- 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ne(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ne(c,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.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncChildren(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=O(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ne.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ne.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ne.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.body.restore({},e),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(r=>r.toFlat(e)),...this.breakStatements.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(r=>r.toFlatIds(e)),...this.breakStatements.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;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,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),error:((r=this.error)==null?void 0:r.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:((c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),error:((f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,declaration:((a=this.declaration)==null?void 0:a.toReference(e))||null,body:((d=this.body)==null?void 0:d.toReference(e))||null,inputs:this.inputs.map(c=>c.toReference(e)),outputs:this.outputs.map(c=>c.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(c=>c.toReference(e)),successCalls:this.successCalls.map(c=>c.toReference(e)),errorCalls:this.errorCalls.map(c=>c.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(c=>c.toReference(e)),calledByError:this.calledByError.map(c=>c.toReference(e)),calledByEntry:this.calledByEntry.map(c=>c.toReference(e)),error:((l=this.error)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.body)==null?void 0:r.toFlatJSON(e))||[],...this.successCalls.flatMap(a=>a.toFlatJSON(e)),...this.errorCalls.flatMap(a=>a.toFlatJSON(e)),...this.inputs.flatMap(a=>a.toFlatJSON(e)),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.continueStatements.flatMap(a=>a.toFlatJSON(e)),...this.breakStatements.flatMap(a=>a.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,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){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.body)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.inputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.outputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.continueStatements.forEach(r=>r.clearErrors()),this.breakStatements.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=z7(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.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.body&&(f.body=this.body.clone(f,c+"-body-id",r,!0)),this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}getVariableInstances(){return this.body?We(this.body).filter(r=>r.type===n.VariableInstance):[]}addReturnStatement(e){return at.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return at.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(r=>{r.outputs.forEach(d=>{e.find(l=>l===d||U(l,this.project)===U(d,this.project)&&Ir(l.dataType,d.dataType))||e.push(d)})}),u(e)}syncTerminationStatements(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(c=>{const f=c.outputs,y=o.filter(v=>!f.find(E=>U(v,this.project)===U(E,this.project)&&Ir(v.dataType,E.dataType)));y.length&&t.push(c),y.forEach(v=>{const E=v.clone(c);e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],r=[],a=[],d=[];return this.body.inputs.sort((l,c)=>l.index-c.index),this.body.inputs.forEach((l,c)=>{l.index!==c&&(l.metaSync({index:c},e),t.push(l))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),r.push(...l),a.push(...c);const f=this.getUniqueReturnDeclarations(),y=this.body.inputs;f.sort((V,C)=>V.index-C.index),f.forEach(V=>{const C=V.getDataType();let j=y.find(oe=>U(oe,this.project)===ne.fromReturnDeclarationToBodyArgumentDeclarationName(V)&&Ir(oe.dataType,V.dataType));if(!j){const oe=ne.fromReturnDeclarationToBodyArgumentDeclarationName(V),qe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe,description:`Aggretated list of all previously outputted values from each iteration by the output '${U(V,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:V.index,required:V.required,parent:this.body.toReference(),writesValues:[]},ee=O(qe,this.project);ee.setParent(this.body,e),ee.initChildren(e),e==null||e.add(ee,b.Added),ee.addSelfToProject(e),r.push(ee),j=ee}const B=this.body.inputs.find(oe=>oe.index===j.index&&oe!==j),$=this.body.inputs.filter(oe=>oe!==j);let z=j.index;B&&(z=Math.max(...$.map(oe=>oe.index))+1),j.index!==z&&(j.metaSync({index:z},e),t.push(j));const X=j.getDataType();let me=X;if(C)if(!X||!Ir(X,C)){if(!me){const oe=C.clone(j);e==null||e.add(oe,b.Added),oe.addSelfToProject(e),me=oe,r.push(oe),t.push(j)}me.merge(C),me.metaSync({isList:!0},e)}else me.isList||(me.metaSync({isList:!0},e),t.push(me));if(!C&&!me){const oe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},qe=O(oe,this.project);qe.metaSync({isList:!0},e),qe.setParent(j,e),qe.initChildren(e),e==null||e.add(qe,b.Added),qe.addSelfToProject(e),r.push(qe)}});const{updated:v,added:E,removed:P}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...v),r.push(...E),a.push(...P),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations(),l=this.outputsDeclarations;return o.forEach((f,y)=>{f.index!==y&&(f.metaSync({index:y},e),t.push(f))}),o.forEach(f=>{const y=f.getDataType();let E=l.find(C=>U(C,this.project)===ne.fromReturnDeclarationToLoopOutputDeclarationName(f)&&Ir(C.dataType,f.dataType));if(!E){const C=ne.fromReturnDeclarationToLoopOutputDeclarationName(f),G={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:C,description:`Aggretated list of all previously outputted values from each iteration by the output '${U(f,this.project)}'`,defaultValue:null,dataType:null,index:f.index,required:f.required,parentRelationType:_.FixedReturns,parent:this.toReference()},j=O(G,this.project);j.setParent(this,e),j.initChildren(e),e==null||e.add(j,b.Added),j.addSelfToProject(e),r.push(j),E=j}E.index!==f.index&&(E.metaSync({index:f.index},e),t.push(E));let V=E.getDataType();if(y)if(!V||!Ir(V,y)){if(!V){const C=y.clone(E);e==null||e.add(C,b.Added),C.addSelfToProject(e),V=C,r.push(C),t.push(E)}V.merge(y),V.metaSync({isList:!0},e)}else V.isList||(V.metaSync({isList:!0},e),t.push(V));if(!y&&!V){const C={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:E.toReference()},G=O(C,this.project);G.metaSync({isList:!0},e),G.setParent(E,e),G.initChildren(e),e==null||e.add(G,b.Added),G.addSelfToProject(e),r.push(G)}}),l.filter(f=>!o.find(v=>U(f,this.project)===ne.fromReturnDeclarationToLoopOutputDeclarationName(v))).forEach(f=>{const{updated:y,removed:v}=f.remove({ignoreUpstream:!1},e);t.push(...y),a.push(...v)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.outputsDeclarations,l=this.outputs;return o.forEach(f=>{var E;let v=l.find(P=>{var V,C;return((V=P.declaration)==null?void 0:V.id)===f.id&&Ir((C=P.declaration)==null?void 0:C.dataType,f.dataType)});if(v)((E=v.declaration)==null?void 0:E.id)!==f.id&&(v.setDeclaration(f),t.push(v));else{const P={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:f.index,declaration:f.toJSON(),writesValues:[],parent:this.toReference()},V=O(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,b.Added),V.addSelfToProject(e),r.push(V),v=V}v.index!==f.index&&(v.metaSync({index:f.index},e),t.push(v))}),l.filter(f=>!o.find(v=>{var E;return((E=f.declaration)==null?void 0:E.id)===v.id})).forEach(f=>{const{updated:y,removed:v}=f.remove({ignoreUpstream:!1},e);t.push(...y),a.push(...v)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],r=[],a=[],d=[];let l=this.body.inputs.find(v=>{var E;return v.name===ne.CURRENT_ITERATION_NUMBER_ARG_NAME||v.id===((E=this.currentIterationNumberArgumentDeclaration)==null?void 0:E.id)});const c=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!l){const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:c==null?void 0:c.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},E=O(v,this.project);E.setParent(this.body,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),l=E}!l.index&&l.index!==0&&(l.metaSync({index:0},e),t.push(l)),(!l.implements||l.implements.id!==c.id)&&(l.setImplements(c,e),t.push(l));let y=l.getDataType();if(!y){const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:l.toReference()},E=O(v,this.project);E.setParent(l,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),y=E}if(!y.entity||y.entity.type!==n.PrimitiveEntity||y.entity.name!==M.Number||y.entity.id!==F["primitive-entity"].number.id){const v=this.project.getBuiltIn(F["primitive-entity"].number.id);y.setEntity(v),t.push(y)}return this.currentIterationNumberArgumentDeclaration=l,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],r=[],a=[],d=[],o=this.body.inputs,l=this.getUniqueReturnDeclarations();return o.filter(f=>f===this.currentIterationNumberArgumentDeclaration||f===this.currentValueArgumentDeclaration?!1:!l.find(v=>U(f,this.project)===ne.fromReturnDeclarationToBodyArgumentDeclarationName(v))).forEach(f=>{const{updated:y,removed:v}=f.remove({ignoreUpstream:!1},e);t.push(...y),a.push(...v)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var f,y,v,E,P;const t=[],r=[],a=[],d=[];switch(this.declaration.id){case H.List:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.List].body.inputs.currentValue.id}),C=this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.List].inputs.list.id});if(!C)break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop][H.List].inputs.list.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G,e),t.push(V));let $=V.getDataType();if(!$){const X={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},me=O(X,this.project);me.setParent(j,e),me.initChildren(e),e==null||e.add(me,b.Added),me.addSelfToProject(e),r.push(me),$=me}const z=C.getDataType();$.merge(z),$.metaSync({isList:!1},e)}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case H.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case H.Counted:{this.currentValueArgumentDeclaration=null;break}case H.ObjectKeys:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.ObjectKeys].inputs.object.id}))break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop][H.ObjectKeys].inputs.object.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G),t.push(V));let $=V.getDataType();if($){const z=this.project.getBuiltIn(F["primitive-entity"].string.id);((f=$.entity)==null?void 0:f.id)!==z.id&&($.setEntity(z),t.push($))}else{const z={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},X=O(z,this.project);X.setParent(j,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),$=X}}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case H.ObjectValues:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.ObjectValues].body.inputs.currentValue.id}),C=this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.ObjectValues].inputs.object.id});if(!C)break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop][H.ObjectValues].inputs.object.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G,e),t.push(V));let $=V.getDataType();if($){const z=C.getDataType(),X=((v=z==null?void 0:z.entity)==null?void 0:v.properties)||[];(E=$.orChildrenGroup)==null||E.forEach(me=>{const{updated:oe,removed:qe}=me.remove({ignoreUpstream:!1},e);t.push(...oe),a.push(...qe)}),X.forEach(me=>{const oe=me.getDataType();if(oe){const qe=oe.clone($);qe.metaSync({parentRelationType:Et.OrDataTypeGroup},e),qe.addSelfToProject(e),r.push(qe)}else{const qe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Et.OrDataTypeGroup,parent:$.toReference()},ee=O(qe,this.project);ee.setParent($,e),ee.initChildren(e),e==null||e.add(ee,b.Added),ee.addSelfToProject(e),r.push(ee)}})}else{const z={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},X=O(z,this.project);X.setParent(j,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),$=X;const me=C.getDataType();(((y=me==null?void 0:me.entity)==null?void 0:y.properties)||[]).forEach(qe=>{const ee=qe.getDataType();if(ee){const fe=ee.clone(X);fe.metaSync({parentRelationType:Et.OrDataTypeGroup},e),fe.addSelfToProject(e),r.push(fe)}else{const fe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Et.OrDataTypeGroup,parent:X.toReference()},fr=O(fe,this.project);fr.setParent(X,e),fr.initChildren(e),e==null||e.add(fr,b.Added),fr.addSelfToProject(e),r.push(fr)}})}}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case H.String:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.String].body.inputs.currentValue.id});if(!this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.String].inputs.string.id}))break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G,e),t.push(V));let $=V.getDataType();if($){const z=this.project.getBuiltIn(F["primitive-entity"].string.id);((P=$.entity)==null?void 0:P.id)!==z.id&&($.setEntity(z),t.push($))}else{const z={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},X=O(z,this.project);X.setParent(j,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),r.push(X),$=X}}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:l,removed:c}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),r.push(...l),a.push(...c);const{updated:f,added:y,removed:v}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...f),r.push(...y),a.push(...v),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];switch(this.declaration.id){case H.List:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["list-loop"].inputs.list.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["list-loop"].inputs.list.id){const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),a.push(o)});break}case H.Counted:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["counted-loop"].inputs.number.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["counted-loop"].inputs.number.id){const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.ObjectKeys:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-keys-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-keys-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.ObjectValues:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-values-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-values-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.String:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["string-loop"].inputs.string.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["string-loop"].inputs.string.id){const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=F[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=F[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body"))){var c;const t=[],r=[],a=[],d=[],o=F[n.Loop][this.declaration.id].body.id,l=this.project.getBuiltIn(o);if(this.body)((c=this.body.implements)==null?void 0:c.id)!==l.id&&(this.body.setImplements(l,e),this.body.setParent(this,e),t.push(this.body));else{const f={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:l.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:l.toJSON(),x:0,y:0,parent:this.toReference()},y=O(f,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,b.Added),y.addSelfToProject(e),r.push(y)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}syncChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-children"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncBody(e);t.push(...o),r.push(...l),a.push(...c);const{updated:f,added:y,removed:v}=this.syncInputMaps(e);t.push(...f),r.push(...y),a.push(...v);const{updated:E,added:P,removed:V}=this.syncTerminationStatements(e);t.push(...E),r.push(...P),a.push(...V);const{updated:C,added:G,removed:j}=this.syncBodyArgumentsDeclarations(e);t.push(...C),r.push(...G),a.push(...j);const{updated:B,added:$,removed:z}=this.syncBodyInputIndexes(e);t.push(...B),r.push(...$),a.push(...z);const{updated:X,added:me,removed:oe}=this.syncOutputsDeclarations(e);t.push(...X),r.push(...me),a.push(...oe);const{updated:qe,added:ee,removed:fe}=this.syncOutputMaps(e);return t.push(...qe),r.push(...ee),a.push(...fe),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}};p(ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(ne,"type",n.Loop),p(ne,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(ne,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),p(ne,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),p(ne,"CURRENT_VALUE_ARG_NAME","Current value"),p(ne,"MUTABLE_BASE_PROPERTIES",[]),p(ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(ne,"BASE_PROPERTIES",[...ne.MUTABLE_BASE_PROPERTIES,...ne.INMUTABLE_BASE_PROPERTIES]),p(ne,"MUTABLE_META_PROPERTIES",[...ne.MUTABLE_BASE_PROPERTIES,"x","y"]),p(ne,"INMUTABLE_META_PROPERTIES",[...ne.INMUTABLE_BASE_PROPERTIES]),p(ne,"META_PROPERTIES",[...ne.MUTABLE_META_PROPERTIES,...ne.INMUTABLE_META_PROPERTIES]),p(ne,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(ne,"UPSTREAM_PROPERTIES",[...ne.MUTABLE_UPSTREAM_PROPERTIES,...ne.INMUTABLE_UPSTREAM_PROPERTIES]),p(ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),p(ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(ne,"DOWNSTREAM_PROPERTIES",[...ne.MUTABLE_DOWNSTREAM_PROPERTIES,...ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(ne,"PROPERTIES",[...ne.META_PROPERTIES,...ne.UPSTREAM_PROPERTIES,...ne.DOWNSTREAM_PROPERTIES]);let _i=ne;function K7(i){const s=k6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(d=>d.validate());const a=[...ci(i)];return Ye(i.errors,a)}var W1=(i=>(i.Parent="parent",i))(W1||{});const je=class je extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.Condition);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"declaration");p(this,"inputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const y=g(e.parent);r=t.get(y)}const a=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),d=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),o=e.calledByError.map(y=>{const v=g(y);return t.get(v)});let l;if(e.declaration){const y=g(e.declaration);l=t.get(y)}const c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Condition,declaration:l,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:r},f=O(c,t);return f.setParent(r,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new D({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
99
+ 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ne(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ne(c,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.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncChildren(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=O(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ne.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ne.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ne.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.body.restore({},e),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(r=>r.toFlat(e)),...this.breakStatements.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(r=>r.toFlatIds(e)),...this.breakStatements.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;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,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),error:((r=this.error)==null?void 0:r.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:((c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),error:((f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,declaration:((a=this.declaration)==null?void 0:a.toReference(e))||null,body:((d=this.body)==null?void 0:d.toReference(e))||null,inputs:this.inputs.map(c=>c.toReference(e)),outputs:this.outputs.map(c=>c.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(c=>c.toReference(e)),successCalls:this.successCalls.map(c=>c.toReference(e)),errorCalls:this.errorCalls.map(c=>c.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(c=>c.toReference(e)),calledByError:this.calledByError.map(c=>c.toReference(e)),calledByEntry:this.calledByEntry.map(c=>c.toReference(e)),error:((l=this.error)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.body)==null?void 0:r.toFlatJSON(e))||[],...this.successCalls.flatMap(a=>a.toFlatJSON(e)),...this.errorCalls.flatMap(a=>a.toFlatJSON(e)),...this.inputs.flatMap(a=>a.toFlatJSON(e)),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.continueStatements.flatMap(a=>a.toFlatJSON(e)),...this.breakStatements.flatMap(a=>a.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,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){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.body)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.inputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.outputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.continueStatements.forEach(r=>r.clearErrors()),this.breakStatements.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=z7(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.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.body&&(f.body=this.body.clone(f,c+"-body-id",r,!0)),this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}getVariableInstances(){return this.body?We(this.body).filter(r=>r.type===n.VariableInstance):[]}addReturnStatement(e){return at.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return at.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(r=>{r.outputs.forEach(d=>{e.find(l=>l===d||U(l,this.project)===U(d,this.project)&&Ir(l.dataType,d.dataType))||e.push(d)})}),u(e)}syncTerminationStatements(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(c=>{const f=c.outputs,y=o.filter(v=>!f.find(E=>U(v,this.project)===U(E,this.project)&&Ir(v.dataType,E.dataType)));y.length&&t.push(c),y.forEach(v=>{const E=v.clone(c);e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],r=[],a=[],d=[];return this.body.inputs.sort((l,c)=>l.index-c.index),this.body.inputs.forEach((l,c)=>{l.index!==c&&(l.metaSync({index:c},e),t.push(l))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),r.push(...l),a.push(...c);const f=this.getUniqueReturnDeclarations(),y=this.body.inputs;f.sort((V,C)=>V.index-C.index),f.forEach(V=>{const C=V.getDataType();let j=y.find(oe=>U(oe,this.project)===ne.fromReturnDeclarationToBodyArgumentDeclarationName(V)&&Ir(oe.dataType,V.dataType));if(!j){const oe=ne.fromReturnDeclarationToBodyArgumentDeclarationName(V),qe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe,description:`Aggretated list of all previously outputted values from each iteration by the output '${U(V,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:V.index,required:V.required,parent:this.body.toReference(),writesValues:[]},ee=O(qe,this.project);ee.setParent(this.body,e),ee.initChildren(e),e==null||e.add(ee,b.Added),ee.addSelfToProject(e),r.push(ee),j=ee}const B=this.body.inputs.find(oe=>oe.index===j.index&&oe!==j),$=this.body.inputs.filter(oe=>oe!==j);let z=j.index;B&&(z=Math.max(...$.map(oe=>oe.index))+1),j.index!==z&&(j.metaSync({index:z},e),t.push(j));const X=j.getDataType();let me=X;if(C)if(!X||!Ir(X,C)){if(!me){const oe=C.clone(j);e==null||e.add(oe,b.Added),oe.addSelfToProject(e),me=oe,r.push(oe),t.push(j)}me.merge(C),me.metaSync({isList:!0},e)}else me.isList||(me.metaSync({isList:!0},e),t.push(me));if(!C&&!me){const oe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},qe=O(oe,this.project);qe.metaSync({isList:!0},e),qe.setParent(j,e),qe.initChildren(e),e==null||e.add(qe,b.Added),qe.addSelfToProject(e),r.push(qe)}});const{updated:v,added:E,removed:P}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...v),r.push(...E),a.push(...P),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations(),l=this.outputsDeclarations;return o.forEach((f,y)=>{f.index!==y&&(f.metaSync({index:y},e),t.push(f))}),o.forEach(f=>{const y=f.getDataType();let E=l.find(C=>U(C,this.project)===ne.fromReturnDeclarationToLoopOutputDeclarationName(f)&&Ir(C.dataType,f.dataType));if(!E){const C=ne.fromReturnDeclarationToLoopOutputDeclarationName(f),G={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:C,description:`Aggretated list of all previously outputted values from each iteration by the output '${U(f,this.project)}'`,defaultValue:null,dataType:null,index:f.index,required:f.required,parentRelationType:_.FixedReturns,parent:this.toReference()},j=O(G,this.project);j.setParent(this,e),j.initChildren(e),e==null||e.add(j,b.Added),j.addSelfToProject(e),r.push(j),E=j}E.index!==f.index&&(E.metaSync({index:f.index},e),t.push(E));let V=E.getDataType();if(y)if(!V||!Ir(V,y)){if(!V){const C=y.clone(E);e==null||e.add(C,b.Added),C.addSelfToProject(e),V=C,r.push(C),t.push(E)}V.merge(y),V.metaSync({isList:!0},e)}else V.isList||(V.metaSync({isList:!0},e),t.push(V));if(!y&&!V){const C={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:E.toReference()},G=O(C,this.project);G.metaSync({isList:!0},e),G.setParent(E,e),G.initChildren(e),e==null||e.add(G,b.Added),G.addSelfToProject(e),r.push(G)}}),l.filter(f=>!o.find(v=>U(f,this.project)===ne.fromReturnDeclarationToLoopOutputDeclarationName(v))).forEach(f=>{const{updated:y,removed:v}=f.remove({ignoreUpstream:!1},e);t.push(...y),a.push(...v)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.outputsDeclarations,l=this.outputs;return o.forEach(f=>{var E;let v=l.find(P=>{var V,C;return((V=P.declaration)==null?void 0:V.id)===f.id&&Ir((C=P.declaration)==null?void 0:C.dataType,f.dataType)});if(v)((E=v.declaration)==null?void 0:E.id)!==f.id&&(v.setDeclaration(f),t.push(v));else{const P={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:f.index,declaration:f.toJSON(),writesValues:[],parent:this.toReference()},V=O(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,b.Added),V.addSelfToProject(e),r.push(V),v=V}v.index!==f.index&&(v.metaSync({index:f.index},e),t.push(v))}),l.filter(f=>!o.find(v=>{var E;return((E=f.declaration)==null?void 0:E.id)===v.id})).forEach(f=>{const{updated:y,removed:v}=f.remove({ignoreUpstream:!1},e);t.push(...y),a.push(...v)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],r=[],a=[],d=[];let l=this.body.inputs.find(v=>{var E;return v.name===ne.CURRENT_ITERATION_NUMBER_ARG_NAME||v.id===((E=this.currentIterationNumberArgumentDeclaration)==null?void 0:E.id)});const c=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!l){const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:c==null?void 0:c.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},E=O(v,this.project);E.setParent(this.body,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),l=E}!l.index&&l.index!==0&&(l.metaSync({index:0},e),t.push(l)),(!l.implements||l.implements.id!==c.id)&&(l.setImplements(c,e),t.push(l));let y=l.getDataType();if(!y){const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:l.toReference()},E=O(v,this.project);E.setParent(l,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),y=E}if(!y.entity||y.entity.type!==n.PrimitiveEntity||y.entity.name!==M.Number||y.entity.id!==F["primitive-entity"].number.id){const v=this.project.getBuiltIn(F["primitive-entity"].number.id);y.setEntity(v),t.push(y)}return this.currentIterationNumberArgumentDeclaration=l,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],r=[],a=[],d=[],o=this.body.inputs,l=this.getUniqueReturnDeclarations();return o.filter(f=>f===this.currentIterationNumberArgumentDeclaration||f===this.currentValueArgumentDeclaration?!1:!l.find(v=>U(f,this.project)===ne.fromReturnDeclarationToBodyArgumentDeclarationName(v))).forEach(f=>{const{updated:y,removed:v}=f.remove({ignoreUpstream:!1},e);t.push(...y),a.push(...v)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var f,y,v,E,P;const t=[],r=[],a=[],d=[];switch(this.declaration.id){case H.List:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.List].body.inputs.currentValue.id}),C=this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.List].inputs.list.id});if(!C)break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop][H.List].inputs.list.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G,e),t.push(V));let $=V.getDataType();if(!$){const X={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},me=O(X,this.project);me.setParent(j,e),me.initChildren(e),e==null||e.add(me,b.Added),me.addSelfToProject(e),r.push(me),$=me}const z=C.getDataType();$.merge(z),$.metaSync({isList:!1},e)}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case H.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case H.Counted:{this.currentValueArgumentDeclaration=null;break}case H.ObjectKeys:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.ObjectKeys].inputs.object.id}))break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop][H.ObjectKeys].inputs.object.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G),t.push(V));let $=V.getDataType();if($){const z=this.project.getBuiltIn(F["primitive-entity"].string.id);((f=$.entity)==null?void 0:f.id)!==z.id&&($.setEntity(z),t.push($))}else{const z={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},X=O(z,this.project);X.setParent(j,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),$=X}}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case H.ObjectValues:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.ObjectValues].body.inputs.currentValue.id}),C=this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.ObjectValues].inputs.object.id});if(!C)break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop][H.ObjectValues].inputs.object.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G,e),t.push(V));let $=V.getDataType();if($){const z=C.getDataType(),X=((v=z==null?void 0:z.entity)==null?void 0:v.properties)||[];(E=$.orChildrenGroup)==null||E.forEach(me=>{const{updated:oe,removed:qe}=me.remove({ignoreUpstream:!1},e);t.push(...oe),a.push(...qe)}),X.forEach(me=>{const oe=me.getDataType();if(oe){const qe=oe.clone($);qe.metaSync({parentRelationType:Et.OrDataTypeGroup},e),qe.addSelfToProject(e),r.push(qe)}else{const qe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Et.OrDataTypeGroup,parent:$.toReference()},ee=O(qe,this.project);ee.setParent($,e),ee.initChildren(e),e==null||e.add(ee,b.Added),ee.addSelfToProject(e),r.push(ee)}})}else{const z={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},X=O(z,this.project);X.setParent(j,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),$=X;const me=C.getDataType();(((y=me==null?void 0:me.entity)==null?void 0:y.properties)||[]).forEach(qe=>{const ee=qe.getDataType();if(ee){const fe=ee.clone(X);fe.metaSync({parentRelationType:Et.OrDataTypeGroup},e),fe.addSelfToProject(e),r.push(fe)}else{const fe={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Et.OrDataTypeGroup,parent:X.toReference()},fr=O(fe,this.project);fr.setParent(X,e),fr.initChildren(e),e==null||e.add(fr,b.Added),fr.addSelfToProject(e),r.push(fr)}})}}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case H.String:{const V=this.body.inputs.find(j=>{var B;return((B=j.implements)==null?void 0:B.id)===F[n.Loop][H.String].body.inputs.currentValue.id});if(!this.inputs.find(j=>{var B;return((B=j.declaration)==null?void 0:B.id)===F[n.Loop][H.String].inputs.string.id}))break;const G=this.getCurrentValueBuiltInValueDescriptor();if(V){this.currentValueArgumentDeclaration=V;const j=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);G&&(!V.implements||V.implements.id!==G.id)&&(V.setImplements(G,e),t.push(V));let $=V.getDataType();if($){const z=this.project.getBuiltIn(F["primitive-entity"].string.id);((P=$.entity)==null?void 0:P.id)!==z.id&&($.setEntity(z),t.push($))}else{const z={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:j.toReference()},X=O(z,this.project);X.setParent(j,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),r.push(X),$=X}}else{const j={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ne.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:G,writesValues:[],dataType:null,parent:this.body.toReference()},B=O(j,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),G&&(!B.implements||B.implements.id!==G.id)&&(B.setImplements(G,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:l,removed:c}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),r.push(...l),a.push(...c);const{updated:f,added:y,removed:v}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...f),r.push(...y),a.push(...v),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];switch(this.declaration.id){case H.List:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["list-loop"].inputs.list.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["list-loop"].inputs.list.id){const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),a.push(o)});break}case H.Counted:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["counted-loop"].inputs.number.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["counted-loop"].inputs.number.id){const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.ObjectKeys:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-keys-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-keys-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.ObjectValues:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-values-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-values-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}case H.String:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["string-loop"].inputs.string.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["string-loop"].inputs.string.id){const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id),c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=O(c,this.project);f.initChildren(e),f.setParent(this,e),e==null||e.add(f,b.Added),f.addSelfToProject(e),r.push(f)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=F[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=F[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body"))){var c;const t=[],r=[],a=[],d=[],o=F[n.Loop][this.declaration.id].body.id,l=this.project.getBuiltIn(o);if(this.body)((c=this.body.implements)==null?void 0:c.id)!==l.id&&(this.body.setImplements(l,e),this.body.setParent(this,e),t.push(this.body));else{const f={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:l.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:l.toJSON(),x:0,y:0,parent:this.toReference()},y=O(f,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,b.Added),y.addSelfToProject(e),r.push(y)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}syncChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-children"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncBody(e);t.push(...o),r.push(...l),a.push(...c);const{updated:f,added:y,removed:v}=this.syncInputMaps(e);t.push(...f),r.push(...y),a.push(...v);const{updated:E,added:P,removed:V}=this.syncTerminationStatements(e);t.push(...E),r.push(...P),a.push(...V);const{updated:C,added:G,removed:j}=this.syncBodyArgumentsDeclarations(e);t.push(...C),r.push(...G),a.push(...j);const{updated:B,added:$,removed:z}=this.syncBodyInputIndexes(e);t.push(...B),r.push(...$),a.push(...z);const{updated:X,added:me,removed:oe}=this.syncOutputsDeclarations(e);t.push(...X),r.push(...me),a.push(...oe);const{updated:qe,added:ee,removed:fe}=this.syncOutputMaps(e);return t.push(...qe),r.push(...ee),a.push(...fe),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}};p(ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(ne,"type",n.Loop),p(ne,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(ne,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),p(ne,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),p(ne,"CURRENT_VALUE_ARG_NAME","Current value"),p(ne,"MUTABLE_BASE_PROPERTIES",[]),p(ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(ne,"BASE_PROPERTIES",[...ne.MUTABLE_BASE_PROPERTIES,...ne.INMUTABLE_BASE_PROPERTIES]),p(ne,"MUTABLE_META_PROPERTIES",[...ne.MUTABLE_BASE_PROPERTIES,"x","y"]),p(ne,"INMUTABLE_META_PROPERTIES",[...ne.INMUTABLE_BASE_PROPERTIES]),p(ne,"META_PROPERTIES",[...ne.MUTABLE_META_PROPERTIES,...ne.INMUTABLE_META_PROPERTIES]),p(ne,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(ne,"UPSTREAM_PROPERTIES",[...ne.MUTABLE_UPSTREAM_PROPERTIES,...ne.INMUTABLE_UPSTREAM_PROPERTIES]),p(ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),p(ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(ne,"DOWNSTREAM_PROPERTIES",[...ne.MUTABLE_DOWNSTREAM_PROPERTIES,...ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(ne,"PROPERTIES",[...ne.META_PROPERTIES,...ne.UPSTREAM_PROPERTIES,...ne.DOWNSTREAM_PROPERTIES]);let _i=ne;function K7(i){const s=k6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(d=>d.validate());const a=[...ci(i)];return Ye(i.errors,a)}var W1=(i=>(i.Parent="parent",i))(W1||{});const je=class je extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.Condition);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"declaration");p(this,"inputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const y=g(e.parent);r=t.get(y)}const a=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),d=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),o=e.calledByError.map(y=>{const v=g(y);return t.get(v)});let l;if(e.declaration){const y=g(e.declaration);l=t.get(y)}const c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Condition,declaration:l,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:r},f=O(c,t);return f.setParent(r,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new D({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
100
100
  ${Ud(t)}`,issue:null})):a.push(new D({id:`${e.id}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
101
101
  ${Ud(t)}`,issue:null})):a.push(new D({id:`${e.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
102
102
  ${Ud(t)}`,issue:null})),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
103
- If an entity is called by another, they must be in the same scope, which means they have the same parent.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new je(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new je(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await je.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await je.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await je.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e))])}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,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,declaration:this.declaration.toJSON(),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})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=K7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.inputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-input-map-"+P+"-id",r));return f.inputs=y,f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!0},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>y.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>v.declaration.id===y.id));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1})});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(je,"type",n.Condition),p(je,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(je,"PARENT_TYPES",[...je.USER_MANAGED_PARENT_TYPES]),p(je,"MUTABLE_BASE_PROPERTIES",["operator"]),p(je,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(je,"BASE_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES,...je.INMUTABLE_BASE_PROPERTIES]),p(je,"MUTABLE_META_PROPERTIES",["x","y"]),p(je,"INMUTABLE_META_PROPERTIES",[...je.INMUTABLE_BASE_PROPERTIES]),p(je,"META_PROPERTIES",[...je.MUTABLE_META_PROPERTIES,...je.INMUTABLE_META_PROPERTIES]),p(je,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(je,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(je,"UPSTREAM_PROPERTIES",[...je.MUTABLE_UPSTREAM_PROPERTIES,...je.INMUTABLE_UPSTREAM_PROPERTIES]),p(je,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),p(je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(je,"DOWNSTREAM_PROPERTIES",[...je.MUTABLE_DOWNSTREAM_PROPERTIES,...je.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(je,"PROPERTIES",[...je.META_PROPERTIES,...je.UPSTREAM_PROPERTIES,...je.DOWNSTREAM_PROPERTIES]);let Mi=je;function X7(i){var o;const s=w3(),e=i.toJSON();s.safeParse(e).success,(o=i.dataType)==null||o.validate(),i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),i.internalCalls.forEach(l=>l.validate());const a=[...ci(i)];if(i.id==="random-company-employee-test-variable-id"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}if(i.id==="company-dto-variable-one-id"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}function Q7(i){const s=M3(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),i.internalCalls.forEach(o=>o.validate());const a=[...ci(i)];if(i.id==="exec-sequentially-result-variable-id"){const o=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}var vp=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i.VarDeclaration="var-declaration",i))(vp||{});const Oe=class Oe extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.VariableInstance);p(this,"defaultValue",null);p(this,"writesValues",[]);p(this,"readsValue",null);p(this,"declaration");p(this,"inputs",[]);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"internalCalls",[]);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const E=g(e.parent);r=t.get(E)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(E=>{const P=g(E);return t.get(P)}),l=e.calledBySuccess.map(E=>{const P=g(E);return t.get(P)}),c=e.calledByError.map(E=>{const P=g(E);return t.get(P)});let f=null;if(e.readsValue){const E=g(e.readsValue);f=t.get(E)}const y={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:d.toReference(),calledByEntry:o,calledBySuccess:l,calledByError:c,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:f,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},v=O(y,t);return v.setParent(r,null),v.initChildren(null),v}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=Os(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
103
+ If an entity is called by another, they must be in the same scope, which means they have the same parent.`,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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new je(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new je(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await je.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await je.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await je.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e))])}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,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,declaration:this.declaration.toJSON(),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})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=K7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(v=this.inputs)==null?void 0:v.map((E,P)=>E.clone(f,c+"-input-map-"+P+"-id",r));return f.inputs=y,f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!0},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>y.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>v.declaration.id===y.id));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1})});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(je,"type",n.Condition),p(je,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(je,"PARENT_TYPES",[...je.USER_MANAGED_PARENT_TYPES]),p(je,"MUTABLE_BASE_PROPERTIES",["operator"]),p(je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(je,"BASE_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES,...je.INMUTABLE_BASE_PROPERTIES]),p(je,"MUTABLE_META_PROPERTIES",["x","y"]),p(je,"INMUTABLE_META_PROPERTIES",[...je.INMUTABLE_BASE_PROPERTIES]),p(je,"META_PROPERTIES",[...je.MUTABLE_META_PROPERTIES,...je.INMUTABLE_META_PROPERTIES]),p(je,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),p(je,"INMUTABLE_UPSTREAM_PROPERTIES",[]),p(je,"UPSTREAM_PROPERTIES",[...je.MUTABLE_UPSTREAM_PROPERTIES,...je.INMUTABLE_UPSTREAM_PROPERTIES]),p(je,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),p(je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(je,"DOWNSTREAM_PROPERTIES",[...je.MUTABLE_DOWNSTREAM_PROPERTIES,...je.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(je,"PROPERTIES",[...je.META_PROPERTIES,...je.UPSTREAM_PROPERTIES,...je.DOWNSTREAM_PROPERTIES]);let Mi=je;function X7(i){var o;const s=w3(),e=i.toJSON();s.safeParse(e).success,(o=i.dataType)==null||o.validate(),i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),i.internalCalls.forEach(l=>l.validate());const a=[...ci(i)];if(i.id==="random-company-employee-test-variable-id"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}if(i.id==="company-dto-variable-one-id"){const l=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}function Q7(i){const s=M3(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),i.internalCalls.forEach(o=>o.validate());const a=[...ci(i)];if(i.id==="exec-sequentially-result-variable-id"){const o=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}var vp=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i.VarDeclaration="var-declaration",i))(vp||{});const Oe=class Oe extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"x");p(this,"y");p(this,"type",n.VariableInstance);p(this,"defaultValue",null);p(this,"writesValues",[]);p(this,"readsValue",null);p(this,"declaration");p(this,"inputs",[]);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"internalCalls",[]);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const E=g(e.parent);r=t.get(E)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(E=>{const P=g(E);return t.get(P)}),l=e.calledBySuccess.map(E=>{const P=g(E);return t.get(P)}),c=e.calledByError.map(E=>{const P=g(E);return t.get(P)});let f=null;if(e.readsValue){const E=g(e.readsValue);f=t.get(E)}const y={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:d.toReference(),calledByEntry:o,calledBySuccess:l,calledByError:c,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:f,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},v=O(y,t);return v.setParent(r,null),v.initChildren(null),v}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=Os(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
104
104
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
105
105
  Specifically for variables, their scope is also calculated from their value readers and value writters.
106
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="var-declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="var-declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,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=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:f}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...f);const{added:y,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...y),t.push(...v),a.push(...E),d.push(...P);const{added:V,updated:C,removed:G,affected:j}=this.generateUnusedInternalCalls(e);if(r.push(...V),t.push(...C),a.push(...G),d.push(...j),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:$,updated:z,removed:X,affected:me}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...$),t.push(...z),a.push(...X),d.push(...me)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(r=>!(e.find(o=>o.id===r.id)||e.find(o=>o.declaration===r.declaration)))}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration.type===n.GenericReference){const t=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!t)return this;this.declaration=t}else this.declaration=O(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return _s.initWritesValues(this,this.parent),pi.initReadsValue(this),this.initialData.inputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.internalCalls=this.initialData.internalCalls.reduce((t,r)=>{if(r.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(r);if(!a)return t;const d=a;return d.setParent(this,null),[...t,d]}else{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(e),[...t,a]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Oe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Oe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...this.successCalls.flatMap(d=>d.toFlat(e)),...this.errorCalls.flatMap(d=>d.toFlat(e)),...this.inputs.flatMap(d=>d.toFlat(e)),...this.outputs.flatMap(d=>d.toFlat(e)),...this.internalCalls.flatMap(d=>d.toFlat(e))])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(a=>a.toFlatIds(e)),...this.successCalls.flatMap(a=>a.toFlatIds(e)),...this.errorCalls.flatMap(a=>a.toFlatIds(e)),...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.outputs.flatMap(a=>a.toFlatIds(e)),...this.internalCalls.flatMap(a=>a.toFlatIds(e))])}toJSON(e=new Set){var t,r;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,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((r=this.readsValue)==null?void 0:r.toReference())||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),internalCalls:this.internalCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((f=this.readsValue)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(y=>y.toJSONClone({...e,newId:null})),inputs:[],outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(y=>this.calledBy.length||this.readsValue?y.toJSONClone({...e,newId:null}):y.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.declaration)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e)),...this.calledBy.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.declaration)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.readsValue)==null?void 0:d.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=Q7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(a=>a.getErrors()),...this.internalCalls.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...((r=this.readsValue)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var V,C,G,j;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(V=this.defaultValue)==null?void 0:V.clone(f,w.UUID.uuid(),r);f.defaultValue=y||null;const v=(C=this.inputs)==null?void 0:C.map((B,$)=>B.clone(f,c+"-input-map-"+$+"-id",r));f.inputs=v;const E=(G=this.outputs)==null?void 0:G.map((B,$)=>B.clone(f,c+"-output-map-"+$+"-id",r));f.outputs=E;const P=(j=this.internalCalls)==null?void 0:j.map((B,$)=>B.clone(f,c+"-internal-call-"+$+"-id",r));return f.internalCalls=P,f}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(y=>!y.getDataType()).forEach(y=>{const v=this.inputs.find(V=>U(V,this.project)===U(y,this.project));if(!v)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);y.setDataType(P),v.setDeclaration(y)}),o.filter(y=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id})).forEach(y=>{const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:y,defaultValue:null,index:y.index,readsValue:null},E=O(v,this.project);return E.setParent(this,e),E.initChildren(e),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(y=>!y.declaration).forEach(y=>{const v=o.find(E=>U(E,this.project)===U(y,this.project));v&&y.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(c=>!this.outputs.find(f=>f.declaration===c)).map(c=>{const f={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:c,index:c.index,writesValues:[]},y=O(f,this.project);return y.setParent(this,e),y.initChildren(e),y.suggestion=!0,this.addOutput(y),y});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(y=>{var E,P,V,C,G;return(((E=y.declaration)==null?void 0:E.id)||((V=(P=y.initialData)==null?void 0:P.declaration)==null?void 0:V.entityId)||((G=(C=y.initialData)==null?void 0:C.declaration)==null?void 0:G.id))===c.id})).map(c=>{const f=c.createInternalCall(this);return f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}getDataType(){var e;return((e=this.declaration)==null?void 0:e.getDataType())||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};p(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Oe,"type",n.VariableInstance),p(Oe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),p(Oe,"MUTABLE_BASE_PROPERTIES",[]),p(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),p(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),p(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),p(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),p(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),p(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),p(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),p(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let Ni=Oe;var Y1=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i))(Y1||{});const Ve=class Ve extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"required",!1);p(this,"constant",!1);p(this,"x");p(this,"y");p(this,"type",n.VariableDeclaration);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"writesValues",[]);p(this,"readsValue",null);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"internalCalls",[]);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const y=g(e.parent);r=t.get(y)}const a=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),d=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),o=e.calledByError.map(y=>{const v=g(y);return t.get(v)});let l=null;if(e.readsValue){const y=g(e.readsValue);l=t.get(y)}const c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:d,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:l,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},f=O(c,t);return f.setParent(r,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData;const o=lp(r,t);return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===vp.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=Os(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
106
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="var-declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="var-declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,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=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:f}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...f);const{added:y,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...y),t.push(...v),a.push(...E),d.push(...P);const{added:V,updated:C,removed:G,affected:j}=this.generateUnusedInternalCalls(e);if(r.push(...V),t.push(...C),a.push(...G),d.push(...j),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:$,updated:z,removed:X,affected:me}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...$),t.push(...z),a.push(...X),d.push(...me)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(r=>!(e.find(o=>o.id===r.id)||e.find(o=>o.declaration===r.declaration)))}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration.type===n.GenericReference){const t=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!t)return this;this.declaration=t}else this.declaration=O(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return _s.initWritesValues(this,this.parent),pi.initReadsValue(this),this.initialData.inputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.internalCalls=this.initialData.internalCalls.reduce((t,r)=>{if(r.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(r);if(!a)return t;const d=a;return d.setParent(this,null),[...t,d]}else{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(e),[...t,a]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Oe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Oe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...this.successCalls.flatMap(d=>d.toFlat(e)),...this.errorCalls.flatMap(d=>d.toFlat(e)),...this.inputs.flatMap(d=>d.toFlat(e)),...this.outputs.flatMap(d=>d.toFlat(e)),...this.internalCalls.flatMap(d=>d.toFlat(e))])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(a=>a.toFlatIds(e)),...this.successCalls.flatMap(a=>a.toFlatIds(e)),...this.errorCalls.flatMap(a=>a.toFlatIds(e)),...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.outputs.flatMap(a=>a.toFlatIds(e)),...this.internalCalls.flatMap(a=>a.toFlatIds(e))])}toJSON(e=new Set){var t,r;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,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((r=this.readsValue)==null?void 0:r.toReference())||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),internalCalls:this.internalCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((f=this.readsValue)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(y=>y.toJSONClone({...e,newId:null})),inputs:[],outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(y=>this.calledBy.length||this.readsValue?y.toJSONClone({...e,newId:null}):y.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.declaration)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e)),...this.calledBy.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.declaration)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.readsValue)==null?void 0:d.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=Q7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(a=>a.getErrors()),...this.internalCalls.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...((r=this.readsValue)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var V,C,G,j;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(V=this.defaultValue)==null?void 0:V.clone(f,w.UUID.uuid(),r);f.defaultValue=y||null;const v=(C=this.inputs)==null?void 0:C.map((B,$)=>B.clone(f,c+"-input-map-"+$+"-id",r));f.inputs=v;const E=(G=this.outputs)==null?void 0:G.map((B,$)=>B.clone(f,c+"-output-map-"+$+"-id",r));f.outputs=E;const P=(j=this.internalCalls)==null?void 0:j.map((B,$)=>B.clone(f,c+"-internal-call-"+$+"-id",r));return f.internalCalls=P,f}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(y=>!y.getDataType()).forEach(y=>{const v=this.inputs.find(V=>U(V,this.project)===U(y,this.project));if(!v)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);y.setDataType(P),v.setDeclaration(y)}),o.filter(y=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id})).forEach(y=>{const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:y,defaultValue:null,index:y.index,readsValue:null},E=O(v,this.project);return E.setParent(this,e),E.initChildren(e),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(y=>!y.declaration).forEach(y=>{const v=o.find(E=>U(E,this.project)===U(y,this.project));v&&y.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(c=>!this.outputs.find(f=>f.declaration===c)).map(c=>{const f={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:c,index:c.index,writesValues:[]},y=O(f,this.project);return y.setParent(this,e),y.initChildren(e),y.suggestion=!0,this.addOutput(y),y});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(y=>{var E,P,V,C,G;return(((E=y.declaration)==null?void 0:E.id)||((V=(P=y.initialData)==null?void 0:P.declaration)==null?void 0:V.entityId)||((G=(C=y.initialData)==null?void 0:C.declaration)==null?void 0:G.id))===c.id})).map(c=>{const f=c.createInternalCall(this);return f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}getDataType(){var e;return((e=this.declaration)==null?void 0:e.getDataType())||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};p(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Oe,"type",n.VariableInstance),p(Oe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),p(Oe,"MUTABLE_BASE_PROPERTIES",[]),p(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),p(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),p(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),p(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),p(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),p(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),p(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),p(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let Ni=Oe;var Y1=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i))(Y1||{});const Ve=class Ve extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"required",!1);p(this,"constant",!1);p(this,"x");p(this,"y");p(this,"type",n.VariableDeclaration);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"writesValues",[]);p(this,"readsValue",null);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"internalCalls",[]);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const y=g(e.parent);r=t.get(y)}const a=e.calledByEntry.map(y=>{const v=g(y);return t.get(v)}),d=e.calledBySuccess.map(y=>{const v=g(y);return t.get(v)}),o=e.calledByError.map(y=>{const v=g(y);return t.get(v)});let l=null;if(e.readsValue){const y=g(e.readsValue);l=t.get(y)}const c={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:d,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:l,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},f=O(c,t);return f.setParent(r,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData;const o=lp(r,t);return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===vp.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=Os(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
107
107
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
108
108
  Specifically for variables, their scope is also calculated from their value readers and value writters.
109
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:f}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...f);const{added:y,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...y),t.push(...v),a.push(...E),d.push(...P);const{added:V,updated:C,removed:G,affected:j}=this.generateUnusedInternalCalls(e);if(r.push(...V),t.push(...C),a.push(...G),d.push(...j),!this.dataType||this.dataType.inferred){const{added:B,updated:$,removed:z,affected:X}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...B),t.push(...$),a.push(...z),d.push(...X)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),_s.initWritesValues(this,this.parent),pi.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.initialData.inputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(t);if(!a)return;a.setParent(this,null),a.initChildren(e),this.addInternalCall(a);return}const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInternalCall(r),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return u([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>U(a,this.project)===U(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var G,j;const t=[],r=[],a=[],d=[];if(!this.dataType){const B=O({id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);B.setParent(this,e),B.initChildren(e),e==null||e.add(B,b.Added),B.metaSync({inferred:!0,like:!0},e),this.setDataType(B)}if(this.readsValue){const B=(G=this.readsValue.getDataType())==null?void 0:G.clone(this);return B&&(B.metaSync({inferred:!0,like:!0},e),this.setDataType(B)),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}const o=u([...this.inputs,...this.variableInstances.flatMap(B=>B.inputs)]),l=[];if(o.forEach(B=>{l.find(z=>U(z,this.project)===U(B,this.project))||l.push(B)}),!l.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};if((j=this.dataType)==null||j.inferFromInputs(l,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};const{updated:c,added:f,removed:y,affected:v}=this.generateUnusedInputs(e);t.push(...f),r.push(...c),a.push(...y),d.push(...v);const{updated:E,added:P,removed:V,affected:C}=this.generateUnusedOutputs(e);return t.push(...P),r.push(...E),a.push(...V),d.push(...C),this.variableInstances.forEach(B=>{const{updated:$,added:z,removed:X,affected:me}=B.generateUnusedInputs(e);t.push(...z),r.push(...$),a.push(...X),d.push(...me);const{updated:oe,added:qe,removed:ee,affected:fe}=B.generateUnusedOutputs(e);t.push(...qe),r.push(...oe),a.push(...ee),d.push(...fe)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ve.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ve.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...((d=this.readsValue)==null?void 0:d.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.successCalls.flatMap(d=>d.toFlatIds(e)),...this.errorCalls.flatMap(d=>d.toFlatIds(e)),...this.inputs.flatMap(d=>d.toFlatIds(e)),...this.outputs.flatMap(d=>d.toFlatIds(e)),...this.internalCalls.flatMap(d=>d.toFlatIds(e))])}toJSON(e=new Set){var t,r,a;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,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),inputs:this.inputs.map(d=>d.toJSON(e)),outputs:this.outputs.map(d=>d.toJSON(e)),successCalls:this.successCalls.map(d=>d.toJSON(e)),errorCalls:this.errorCalls.map(d=>d.toJSON(e)),internalCalls:this.internalCalls.map(d=>d.toJSON(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference()),calledByError:this.calledByError.map(d=>d.toReference()),calledByEntry:this.calledByEntry.map(d=>d.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=k){var r,a,d,o,l,c,f,y;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.successCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.inputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.outputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(d=>d.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.internalCalls.forEach(r=>r.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=X7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[],...this.inputs.flatMap(d=>d.getErrors()),...this.internalCalls.flatMap(d=>d.getErrors()),...this.outputs.flatMap(d=>d.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var C,G,j,B,$;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(C=this.dataType)==null?void 0:C.clone(f,w.UUID.uuid(),r);f.dataType=y||null;const v=(G=this.defaultValue)==null?void 0:G.clone(f,w.UUID.uuid(),r);f.defaultValue=v||null;const E=(j=this.inputs)==null?void 0:j.map((z,X)=>z.clone(f,c+"-input-map-"+X+"-id",r));f.inputs=E;const P=(B=this.outputs)==null?void 0:B.map((z,X)=>z.clone(f,c+"-output-map-"+X+"-id",r));f.outputs=P;const V=($=this.internalCalls)==null?void 0:$.map((z,X)=>z.clone(f,c+"-internal-call-"+X+"-id",r));return f.internalCalls=V,f}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t={}){const r={id:t.id||w.UUID.uuid(),version:t.version||"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:t.defaultValue||null,successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],writesValues:t.writesValues||[],internalCalls:t.internalCalls||[],readsValue:t.readsValue||null,calledByEntry:t.calledByEntry||[],calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],declaration:this.toJSON(),x:0,y:0},a=O(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addVariableInstance(a),a}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(y=>!y.getDataType()).forEach(y=>{const v=this.inputs.find(V=>U(V,this.project)===U(y,this.project));if(!v)return;const E=this.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);y.setDataType(P),v.setDeclaration(y)}),o.filter(y=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id})).forEach(y=>{const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:y,defaultValue:null,index:y.index,readsValue:null},E=O(v,this.project);return E.setParent(this,e),E.initChildren(e),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(y=>!y.declaration).forEach(y=>{const v=o.find(E=>U(E,this.project)===U(y,this.project));v&&y.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(c=>!this.outputs.find(f=>f.declaration===c)).map(c=>{const f={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:c,index:c.index,writesValues:[]},y=O(f,this.project);return y.setParent(this,e),y.initChildren(e),y.suggestion=!0,this.addOutput(y),y});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(y=>{var E,P,V,C,G;return(((E=y.declaration)==null?void 0:E.id)||((V=(P=y.initialData)==null?void 0:P.declaration)==null?void 0:V.entityId)||((G=(C=y.initialData)==null?void 0:C.declaration)==null?void 0:G.id))===c.id})).map(c=>{const f=c.createInternalCall(this);return f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(null),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};p(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ve,"type",n.VariableDeclaration),p(Ve,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),p(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),p(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),p(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),p(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),p(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),p(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),p(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Li=Ve;function eq(i){var d;const s=W6(),e=i.toJSON();s.safeParse(e).success,i.inputsDeclarations.forEach(o=>o.validate()),i.inputs.forEach(o=>o.validate()),i.outputsDeclarations.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),(d=i.error)==null||d.validate();const a=[...ci(i)];if(i.id==="search-person-by-id-id"){const o=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return Ye(i.errors,a)}var z1=(i=>(i.Parent="parent",i))(z1||{});const ke=class ke extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"query","");p(this,"type",n.Search);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"inputsDeclarations",[]);p(this,"inputs",[]);p(this,"outputsDeclarations",[]);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"error",null);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static fromGenerationTarget(e,t){let r=t;if(e.parent){const f=g(e.parent);r=t.get(f)}const a=e.calledByEntry.map(f=>{const y=g(f);return t.get(y)}),d=e.calledBySuccess.map(f=>{const y=g(f);return t.get(y)}),o=e.calledByError.map(f=>{const y=g(f);return t.get(y)}),l={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:r},c=O(l,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType();return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
109
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:f}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...f);const{added:y,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...y),t.push(...v),a.push(...E),d.push(...P);const{added:V,updated:C,removed:G,affected:j}=this.generateUnusedInternalCalls(e);if(r.push(...V),t.push(...C),a.push(...G),d.push(...j),!this.dataType||this.dataType.inferred){const{added:B,updated:$,removed:z,affected:X}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...B),t.push(...$),a.push(...z),d.push(...X)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),_s.initWritesValues(this,this.parent),pi.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.initialData.inputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(t);if(!a)return;a.setParent(this,null),a.initChildren(e),this.addInternalCall(a);return}const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInternalCall(r),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return u([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>U(a,this.project)===U(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var G,j;const t=[],r=[],a=[],d=[];if(!this.dataType){const B=O({id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);B.setParent(this,e),B.initChildren(e),e==null||e.add(B,b.Added),B.metaSync({inferred:!0,like:!0},e),this.setDataType(B)}if(this.readsValue){const B=(G=this.readsValue.getDataType())==null?void 0:G.clone(this);return B&&(B.metaSync({inferred:!0,like:!0},e),this.setDataType(B)),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}const o=u([...this.inputs,...this.variableInstances.flatMap(B=>B.inputs)]),l=[];if(o.forEach(B=>{l.find(z=>U(z,this.project)===U(B,this.project))||l.push(B)}),!l.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};if((j=this.dataType)==null||j.inferFromInputs(l,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};const{updated:c,added:f,removed:y,affected:v}=this.generateUnusedInputs(e);t.push(...f),r.push(...c),a.push(...y),d.push(...v);const{updated:E,added:P,removed:V,affected:C}=this.generateUnusedOutputs(e);return t.push(...P),r.push(...E),a.push(...V),d.push(...C),this.variableInstances.forEach(B=>{const{updated:$,added:z,removed:X,affected:me}=B.generateUnusedInputs(e);t.push(...z),r.push(...$),a.push(...X),d.push(...me);const{updated:oe,added:qe,removed:ee,affected:fe}=B.generateUnusedOutputs(e);t.push(...qe),r.push(...oe),a.push(...ee),d.push(...fe)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ve.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ve.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...((d=this.readsValue)==null?void 0:d.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.successCalls.flatMap(d=>d.toFlatIds(e)),...this.errorCalls.flatMap(d=>d.toFlatIds(e)),...this.inputs.flatMap(d=>d.toFlatIds(e)),...this.outputs.flatMap(d=>d.toFlatIds(e)),...this.internalCalls.flatMap(d=>d.toFlatIds(e))])}toJSON(e=new Set){var t,r,a;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,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),inputs:this.inputs.map(d=>d.toJSON(e)),outputs:this.outputs.map(d=>d.toJSON(e)),successCalls:this.successCalls.map(d=>d.toJSON(e)),errorCalls:this.errorCalls.map(d=>d.toJSON(e)),internalCalls:this.internalCalls.map(d=>d.toJSON(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference()),calledByError:this.calledByError.map(d=>d.toReference()),calledByEntry:this.calledByEntry.map(d=>d.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=k){var r,a,d,o,l,c,f,y;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.successCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.inputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.outputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(d=>d.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.internalCalls.forEach(r=>r.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=X7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[],...this.inputs.flatMap(d=>d.getErrors()),...this.internalCalls.flatMap(d=>d.getErrors()),...this.outputs.flatMap(d=>d.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var C,G,j,B,$;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(C=this.dataType)==null?void 0:C.clone(f,w.UUID.uuid(),r);f.dataType=y||null;const v=(G=this.defaultValue)==null?void 0:G.clone(f,w.UUID.uuid(),r);f.defaultValue=v||null;const E=(j=this.inputs)==null?void 0:j.map((z,X)=>z.clone(f,c+"-input-map-"+X+"-id",r));f.inputs=E;const P=(B=this.outputs)==null?void 0:B.map((z,X)=>z.clone(f,c+"-output-map-"+X+"-id",r));f.outputs=P;const V=($=this.internalCalls)==null?void 0:$.map((z,X)=>z.clone(f,c+"-internal-call-"+X+"-id",r));return f.internalCalls=V,f}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t={}){const r={id:t.id||w.UUID.uuid(),version:t.version||"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:t.defaultValue||null,successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],writesValues:t.writesValues||[],internalCalls:t.internalCalls||[],readsValue:t.readsValue||null,calledByEntry:t.calledByEntry||[],calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],declaration:this.toJSON(),x:0,y:0},a=O(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addVariableInstance(a),a}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(y=>!y.getDataType()).forEach(y=>{const v=this.inputs.find(V=>U(V,this.project)===U(y,this.project));if(!v)return;const E=this.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);y.setDataType(P),v.setDeclaration(y)}),o.filter(y=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===y.id})).forEach(y=>{const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:y,defaultValue:null,index:y.index,readsValue:null},E=O(v,this.project);return E.setParent(this,e),E.initChildren(e),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(y=>!y.declaration).forEach(y=>{const v=o.find(E=>U(E,this.project)===U(y,this.project));v&&y.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(c=>!this.outputs.find(f=>f.declaration===c)).map(c=>{const f={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:c,index:c.index,writesValues:[]},y=O(f,this.project);return y.setParent(this,e),y.initChildren(e),y.suggestion=!0,this.addOutput(y),y});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(y=>{var E,P,V,C,G;return(((E=y.declaration)==null?void 0:E.id)||((V=(P=y.initialData)==null?void 0:P.declaration)==null?void 0:V.entityId)||((G=(C=y.initialData)==null?void 0:C.declaration)==null?void 0:G.id))===c.id})).map(c=>{const f=c.createInternalCall(this);return f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(null),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};p(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ve,"type",n.VariableDeclaration),p(Ve,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),p(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),p(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),p(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),p(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),p(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),p(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),p(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Li=Ve;function eq(i){var d;const s=W6(),e=i.toJSON();s.safeParse(e).success,i.inputsDeclarations.forEach(o=>o.validate()),i.inputs.forEach(o=>o.validate()),i.outputsDeclarations.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),(d=i.error)==null||d.validate();const a=[...ci(i)];if(i.id==="search-person-by-id-id"){const o=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return Ye(i.errors,a)}var z1=(i=>(i.Parent="parent",i))(z1||{});const ke=class ke extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"query","");p(this,"type",n.Search);p(this,"successCalls",[]);p(this,"errorCalls",[]);p(this,"inputsDeclarations",[]);p(this,"inputs",[]);p(this,"outputsDeclarations",[]);p(this,"outputs",[]);p(this,"calledBySuccess",[]);p(this,"calledByError",[]);p(this,"calledByEntry",[]);p(this,"error",null);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static fromGenerationTarget(e,t){let r=t;if(e.parent){const f=g(e.parent);r=t.get(f)}const a=e.calledByEntry.map(f=>{const y=g(f);return t.get(y)}),d=e.calledBySuccess.map(f=>{const y=g(f);return t.get(y)}),o=e.calledByError.map(f=>{const y=g(f);return t.get(y)}),l={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:r},c=O(l,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType();return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
110
110
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
111
- 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncInputMaps(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(a=>a.id===e.id);t>-1&&this.inputs.splice(t,1);const r=this.inputsDeclarations.findIndex(a=>{var d;return a.id===((d=e.declaration)==null?void 0:d.id)});return r>-1&&this.inputsDeclarations.splice(r,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.inputsDeclarations.splice(t,1),this}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,this.name=e.name||this.name,this.description=e.description||this.description,e.query!==void 0&&(this.query=e.query),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ke.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ke.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.inputsDeclarations.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputsDeclarations.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.inputsDeclarations.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t;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,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(r=>r.toJSON()),errorCalls:this.errorCalls.map(r=>r.toJSON()),calledBySuccess:this.calledBySuccess.map(r=>r.toReference()),calledByError:this.calledByError.map(r=>r.toReference()),calledByEntry:this.calledByEntry.map(r=>r.toReference()),inputsDeclarations:this.inputsDeclarations.map(r=>r.toJSON()),inputs:this.inputs.map(r=>r.toJSON()),outputsDeclarations:this.outputsDeclarations.map(r=>r.toJSON()),outputs:this.outputs.map(r=>r.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(f=>f.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(f=>f.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),inputs:this.inputs.map(f=>f.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),outputs:this.outputs.map(f=>f.toJSONClone({...e,newId:null})),error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(a=>a.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.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,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=eq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputsDeclarations.flatMap(t=>t.getErrors()),...this.inputs.flatMap(t=>t.getErrors()),...this.outputsDeclarations.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var V,C,G,j;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(V=this.inputsDeclarations)==null?void 0:V.map((B,$)=>B.clone(this,c+"-input-declaration-"+$+"-id",r));f.inputsDeclarations=y;const v=(C=this.outputsDeclarations)==null?void 0:C.map((B,$)=>B.clone(this,c+"-output-declaration-"+$+"-id",r));f.outputsDeclarations=v;const E=(G=this.inputs)==null?void 0:G.map((B,$)=>B.clone(f,c+"-input-map-"+$+"-id",r));f.inputs=E;const P=(j=this.outputs)==null?void 0:j.map((B,$)=>B.clone(f,c+"-output-map-"+$+"-id",r));return f.outputs=P,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),f}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(c=>{var f;return((f=c.declaration)==null?void 0:f.id)===o.id})){const c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},f=O(c,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,b.Added),f.addSelfToProject(e),t.push(this),r.push(f)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const{updated:c,removed:f}=o.remove({ignoreUpstream:!1},e);c.push(...c),a.push(...f)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(ke,"type",n.Search),p(ke,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),p(ke,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),p(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),p(ke,"MUTABLE_META_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,"x","y"]),p(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),p(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),p(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(ke,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),p(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),p(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(ke,"PROPERTIES",[...tr.META_PROPERTIES,...tr.UPSTREAM_PROPERTIES,...tr.DOWNSTREAM_PROPERTIES]);let Si=ke;function tq(i){const s=U3(),e=i.toJSON();s.safeParse(e).success,i.functions.forEach(a=>a.validate()),i.events.forEach(a=>a.validate());const r=[];return Ye(i.errors,r)}const Fe=class Fe extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"type",n.InstalledProject);p(this,"implements");p(this,"functions",[]);p(this,"events",[]);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);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.implements=e.implements}static fromGenerationTarget(e,t){const r=t,a={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:"1",entityType:n.Project,type:n.GenericReference,id:w.UUID.uuid()},x:0,y:0,parent:r},d=O(a,t);return d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an installed project, 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addInstalledProject(this),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Fe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Fe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.functions.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...f)}),this.events.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...f)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){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.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e))])}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,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,implements:this.implements,functions:this.functions.map(c=>c.toJSONClone({...e,newId:null})),events:this.events.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=tq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.functions=[],d.events=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e&&f.setParent(e,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.functions)==null?void 0:E.map((V,C)=>V.clone(f,c+"-exported-function-declaration-"+C+"-id",r));f.functions=y;const v=(P=this.events)==null?void 0:P.map((V,C)=>V.clone(f,c+"-exported-event-"+C+"-id",r));return f.events=v,f}};p(Fe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Fe,"type",n.InstalledProject),p(Fe,"USER_MANAGED_PARENT_TYPES",[n.Project]),p(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),p(Fe,"MUTABLE_BASE_PROPERTIES",[]),p(Fe,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type"]),p(Fe,"BASE_PROPERTIES",[...Fe.MUTABLE_BASE_PROPERTIES,...Fe.INMUTABLE_BASE_PROPERTIES]),p(Fe,"MUTABLE_META_PROPERTIES",["x","y"]),p(Fe,"INMUTABLE_META_PROPERTIES",[...Fe.INMUTABLE_BASE_PROPERTIES]),p(Fe,"META_PROPERTIES",[...Fe.MUTABLE_META_PROPERTIES,...Fe.INMUTABLE_META_PROPERTIES]),p(Fe,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Fe,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),p(Fe,"UPSTREAM_PROPERTIES",[...Fe.MUTABLE_UPSTREAM_PROPERTIES,...Fe.INMUTABLE_UPSTREAM_PROPERTIES]),p(Fe,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),p(Fe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Fe,"DOWNSTREAM_PROPERTIES",[...Fe.MUTABLE_DOWNSTREAM_PROPERTIES,...Fe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Fe,"PROPERTIES",[...Fe.META_PROPERTIES,...Fe.UPSTREAM_PROPERTIES,...Fe.DOWNSTREAM_PROPERTIES]);let $i=Fe;function rq(i){var o;const s=K6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate();const r=ci(i),a=iq(i),d=[...r,...a];return Ye(i.errors,d)}function iq(i){const s=[],e=Pd(i.parent),t=e==null?void 0:e.entity;if(!t)s.push(pe({id:`${i.id}--${S.InternalCallParentMissingDataType}`,code:S.InternalCallParentMissingDataType,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${i.declaration}".`,issue:null,entity:i}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))s.push(pe({id:`${i.id}--${S.InternalCallParentDeclarationEntityInvalidType}`,code:S.InternalCallParentDeclarationEntityInvalidType,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
111
+ 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncInputMaps(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(a=>a.id===e.id);t>-1&&this.inputs.splice(t,1);const r=this.inputsDeclarations.findIndex(a=>{var d;return a.id===((d=e.declaration)==null?void 0:d.id)});return r>-1&&this.inputsDeclarations.splice(r,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.inputsDeclarations.splice(t,1),this}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,this.name=e.name||this.name,this.description=e.description||this.description,e.query!==void 0&&(this.query=e.query),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ke.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ke.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.inputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.inputsDeclarations.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputs.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.outputsDeclarations.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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.inputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.inputsDeclarations.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t;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,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(r=>r.toJSON()),errorCalls:this.errorCalls.map(r=>r.toJSON()),calledBySuccess:this.calledBySuccess.map(r=>r.toReference()),calledByError:this.calledByError.map(r=>r.toReference()),calledByEntry:this.calledByEntry.map(r=>r.toReference()),inputsDeclarations:this.inputsDeclarations.map(r=>r.toJSON()),inputs:this.inputs.map(r=>r.toJSON()),outputsDeclarations:this.outputsDeclarations.map(r=>r.toJSON()),outputs:this.outputs.map(r=>r.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(f=>f.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(f=>f.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),inputs:this.inputs.map(f=>f.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),outputs:this.outputs.map(f=>f.toJSONClone({...e,newId:null})),error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(a=>a.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.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,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=eq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputsDeclarations.flatMap(t=>t.getErrors()),...this.inputs.flatMap(t=>t.getErrors()),...this.outputsDeclarations.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var V,C,G,j;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(V=this.inputsDeclarations)==null?void 0:V.map((B,$)=>B.clone(this,c+"-input-declaration-"+$+"-id",r));f.inputsDeclarations=y;const v=(C=this.outputsDeclarations)==null?void 0:C.map((B,$)=>B.clone(this,c+"-output-declaration-"+$+"-id",r));f.outputsDeclarations=v;const E=(G=this.inputs)==null?void 0:G.map((B,$)=>B.clone(f,c+"-input-map-"+$+"-id",r));f.inputs=E;const P=(j=this.outputs)==null?void 0:j.map((B,$)=>B.clone(f,c+"-output-map-"+$+"-id",r));return f.outputs=P,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),f}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(c=>{var f;return((f=c.declaration)==null?void 0:f.id)===o.id})){const c={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},f=O(c,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,b.Added),f.addSelfToProject(e),t.push(this),r.push(f)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const{updated:c,removed:f}=o.remove({ignoreUpstream:!1},e);c.push(...c),a.push(...f)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(ke,"type",n.Search),p(ke,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),p(ke,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),p(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),p(ke,"MUTABLE_META_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,"x","y"]),p(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),p(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),p(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(ke,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),p(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),p(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(ke,"PROPERTIES",[...tr.META_PROPERTIES,...tr.UPSTREAM_PROPERTIES,...tr.DOWNSTREAM_PROPERTIES]);let Si=ke;function tq(i){const s=U3(),e=i.toJSON();s.safeParse(e).success,i.functions.forEach(a=>a.validate()),i.events.forEach(a=>a.validate());const r=[];return Ye(i.errors,r)}const Fe=class Fe extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"type",n.InstalledProject);p(this,"implements");p(this,"functions",[]);p(this,"events",[]);p(this,"parent");p(this,"errors",[]);p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);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.implements=e.implements}static fromGenerationTarget(e,t){const r=t,a={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:"1",entityType:n.Project,type:n.GenericReference,id:w.UUID.uuid()},x:0,y:0,parent:r},d=O(a,t);return d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an installed project, 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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addInstalledProject(this),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Fe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Fe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.functions.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...f)}),this.events.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...f)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){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.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e))])}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,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,implements:this.implements,functions:this.functions.map(c=>c.toJSONClone({...e,newId:null})),events:this.events.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=tq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.functions=[],d.events=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e&&f.setParent(e,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.functions)==null?void 0:E.map((V,C)=>V.clone(f,c+"-exported-function-declaration-"+C+"-id",r));f.functions=y;const v=(P=this.events)==null?void 0:P.map((V,C)=>V.clone(f,c+"-exported-event-"+C+"-id",r));return f.events=v,f}};p(Fe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Fe,"type",n.InstalledProject),p(Fe,"USER_MANAGED_PARENT_TYPES",[n.Project]),p(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),p(Fe,"MUTABLE_BASE_PROPERTIES",[]),p(Fe,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),p(Fe,"BASE_PROPERTIES",[...Fe.MUTABLE_BASE_PROPERTIES,...Fe.INMUTABLE_BASE_PROPERTIES]),p(Fe,"MUTABLE_META_PROPERTIES",["x","y"]),p(Fe,"INMUTABLE_META_PROPERTIES",[...Fe.INMUTABLE_BASE_PROPERTIES]),p(Fe,"META_PROPERTIES",[...Fe.MUTABLE_META_PROPERTIES,...Fe.INMUTABLE_META_PROPERTIES]),p(Fe,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Fe,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),p(Fe,"UPSTREAM_PROPERTIES",[...Fe.MUTABLE_UPSTREAM_PROPERTIES,...Fe.INMUTABLE_UPSTREAM_PROPERTIES]),p(Fe,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),p(Fe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Fe,"DOWNSTREAM_PROPERTIES",[...Fe.MUTABLE_DOWNSTREAM_PROPERTIES,...Fe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Fe,"PROPERTIES",[...Fe.META_PROPERTIES,...Fe.UPSTREAM_PROPERTIES,...Fe.DOWNSTREAM_PROPERTIES]);let $i=Fe;function rq(i){var o;const s=K6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate();const r=ci(i),a=iq(i),d=[...r,...a];return Ye(i.errors,d)}function iq(i){const s=[],e=Pd(i.parent),t=e==null?void 0:e.entity;if(!t)s.push(pe({id:`${i.id}--${S.InternalCallParentMissingDataType}`,code:S.InternalCallParentMissingDataType,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${i.declaration}".`,issue:null,entity:i}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))s.push(pe({id:`${i.id}--${S.InternalCallParentDeclarationEntityInvalidType}`,code:S.InternalCallParentDeclarationEntityInvalidType,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
112
112
  This variable's data-type has an 'entity' field that references an entity with id '${t.id}' and of type '${t.type}'.`,issue:null,entity:i}).error);else{const r=jp(t),a=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&a.push(...t.getAllInteractiveMethods());let d="";r?t.methods.length?d=`
113
113
  All 'function-declaration' entities attached as methods to the parent data-type 'entity' field, available to be called as 'internal-calls' in this variable are:
114
114
  - ${t.methods.map(c=>c.id).join(`
@@ -137,7 +137,7 @@ ${xi}`);const E=r.declaration;if(!t.get(E))a.push(new D({id:`${r.id}--${I.Refere
137
137
  The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${v}`,issue:null})):a.push(new D({id:`${r.id}--${S.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:S.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:R.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${r.declaration}".${v}`,issue:null}))}}(l.inputs.length||l.outputs.length||l.internalCalls.length)&&a.push(new D({id:`${r.id}--${I.InvalidInternalCallParentRelation}`,code:I.InvalidInternalCallParentRelation,severity:R.Error,message:`Entity of type "${r.type}" with id "${r.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
138
138
  If you need a new variable-instance for this, consider using the 'implement_variable_instance' generation action to create one and give it a caller.
139
139
  The you can attach the new internal-call to it.`,issue:null}))}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
140
- 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return 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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new we(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:f,added:y,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),r.push(...l,...y),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=O(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const r=this.calledBy.find(a=>!!a.parent&&mt.includes(a.parent.type));if(r){const a=O(r.parent,this.project);this.parent.setParent(a,null)}else if(!r&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=O(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await we.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await we.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.process){const{updated:c,removed:f}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}if(this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.outputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.error){const{updated:c,removed:f}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r;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,index:this.index,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=rq(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=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>!this.inputs.find(v=>v.declaration.id===y.id));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1},e)});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=O(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(G=>{G.index>=v.index&&G.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,V={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=O(V,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:f,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...f),a.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(we,"type",n.InternalCall),p(we,"USER_MANAGED_PARENT_TYPES",[...Qe]),p(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),p(we,"MUTABLE_BASE_PROPERTIES",[]),p(we,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(we,"BASE_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,...we.INMUTABLE_BASE_PROPERTIES]),p(we,"MUTABLE_META_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,"index"]),p(we,"INMUTABLE_META_PROPERTIES",[...we.INMUTABLE_BASE_PROPERTIES]),p(we,"META_PROPERTIES",[...we.MUTABLE_META_PROPERTIES,...we.INMUTABLE_META_PROPERTIES]),p(we,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(we,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),p(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),p(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Cn=we;function nq(i){const s=t3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-argument-map-id"){const a=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var K1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(K1||{});const Ce=class Ce extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"index");p(this,"name",null);p(this,"description",null);p(this,"type",n.InputMap);p(this,"defaultValue",null);p(this,"readsValue",null);p(this,"dataType",null);p(this,"declaration",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.declaration){const f=g(e.declaration);d=t.get(f)}let o=null;if(e.readsValue){const f=g(e.readsValue);o=t.get(f)}const l={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(a.inputs||[]).length,description:e.description||null,declaration:d,readsValue:o,defaultValue:null,parent:a},c=O(l,t);return c.setParent(a,null),c.initChildren(null),c}static validateGenerationTarget(e,t){var f;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...nt,n.InputMap]}},t);r=d.modifiedData;const o=t.get(r.parent),l=r.declaration&&(t.get(r.declaration)||t.getBuiltIn(r.declaration)),c=((o==null?void 0:o.inputs)||[]).find(y=>{var v;return r.declaration&&((v=y.declaration)==null?void 0:v.id)===r.declaration});if(r.declaration?l?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(l.type)?o&&l.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?a.push(new D({id:`${r.id}--${I.InvalidInputMapDeclaration}`,code:I.InvalidInputMapDeclaration,severity:R.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${r.declaration}'.
140
+ 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return 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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new we(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:f,added:y,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),r.push(...l,...y),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=O(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const r=this.calledBy.find(a=>!!a.parent&&mt.includes(a.parent.type));if(r){const a=O(r.parent,this.project);this.parent.setParent(a,null)}else if(!r&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=O(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=O(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await we.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await we.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.process){const{updated:c,removed:f}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}if(this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.outputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.error){const{updated:c,removed:f}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r;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,index:this.index,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=rq(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=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>!this.inputs.find(v=>v.declaration.id===y.id));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1},e)});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=O(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(G=>{G.index>=v.index&&G.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,V={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=O(V,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:f,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...f),a.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(we,"type",n.InternalCall),p(we,"USER_MANAGED_PARENT_TYPES",[...Qe]),p(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),p(we,"MUTABLE_BASE_PROPERTIES",[]),p(we,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(we,"BASE_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,...we.INMUTABLE_BASE_PROPERTIES]),p(we,"MUTABLE_META_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,"index"]),p(we,"INMUTABLE_META_PROPERTIES",[...we.INMUTABLE_BASE_PROPERTIES]),p(we,"META_PROPERTIES",[...we.MUTABLE_META_PROPERTIES,...we.INMUTABLE_META_PROPERTIES]),p(we,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(we,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),p(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),p(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Cn=we;function nq(i){const s=t3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-argument-map-id"){const a=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var K1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(K1||{});const Ce=class Ce extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"index");p(this,"name",null);p(this,"description",null);p(this,"type",n.InputMap);p(this,"defaultValue",null);p(this,"readsValue",null);p(this,"dataType",null);p(this,"declaration",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.declaration){const f=g(e.declaration);d=t.get(f)}let o=null;if(e.readsValue){const f=g(e.readsValue);o=t.get(f)}const l={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(a.inputs||[]).length,description:e.description||null,declaration:d,readsValue:o,defaultValue:null,parent:a},c=O(l,t);return c.setParent(a,null),c.initChildren(null),c}static validateGenerationTarget(e,t){var f;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[...nt,n.InputMap]}},t);r=d.modifiedData;const o=t.get(r.parent),l=r.declaration&&(t.get(r.declaration)||t.getBuiltIn(r.declaration)),c=((o==null?void 0:o.inputs)||[]).find(y=>{var v;return r.declaration&&((v=y.declaration)==null?void 0:v.id)===r.declaration});if(r.declaration?l?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(l.type)?o&&l.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?a.push(new D({id:`${r.id}--${I.InvalidInputMapDeclaration}`,code:I.InvalidInputMapDeclaration,severity:R.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${r.declaration}'.
141
141
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
142
142
  Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`,issue:null})):o&&l.type===n.Property&&!Qe.includes(o.type)?a.push(new D({id:`${r.id}--${I.InvalidInputMapDeclaration}`,code:I.InvalidInputMapDeclaration,severity:R.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' has a 'declaration' property pointing to an entity with type '${n.Property}' with id '${r.declaration}'.
143
143
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
@@ -155,7 +155,7 @@ Input maps can only be added to variables which hold an entity with properties.`
155
155
  The entity of the data-type has the following properties that can be reads as input maps, ids: '${re(P.properties.map(C=>C.id),"', '","' and '")}'`,issue:null})))}else if(nt.filter(y=>Qe.includes(y)).includes(o.type)){const v=Lp(o),E=v.find(V=>V.id===r.declaration),P=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${re(v.map(V=>V.id),"', '","' and '")}'`;E||a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent entity does not have an 'argument-declaration' with id '${r.declaration}'.
156
156
  You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
157
157
  ${P}`,issue:null}))}}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=Os(r,this);return r=a.modifiedData,t.push(...a.errors),r.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
158
- 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})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];if(this.parent.addInput(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),Qe.includes(this.parent.type)&&((l=this.parent.getDataType())!=null&&l.inferred)){const c=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:f,added:y,removed:v,affected:E}=c.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...f),r.push(...y),a.push(...v),d.push(...E),t.push(c,...c.variableInstances)}return this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration&&(this.declaration=O(this.initialData.declaration,this.project)),pi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ce.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ce.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),e||(r.push(this.parent),this.parent.removeInput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.restore({},e)),r.push(this.parent),this.parent.addInput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;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,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v,E,P;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((y=this.declaration)==null?void 0:y.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,readsValue:((P=this.readsValue)==null?void 0:P.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.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):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=nq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var f;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.defaultValue=null,d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(f=this.defaultValue)==null?void 0:f.clone(l,w.UUID.uuid(),r);return l.defaultValue=c||null,l}getDataType(){var t;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this).self;if(Qe.includes(this.parent.type)){const r=Pn(this.parent),a=r.getDataType();(!a||a.inferred)&&r.inferDataTypeAndSyncInstancesInputsAndOutputs(null)}const e=(t=this.declaration)==null?void 0:t.getDataType();if(!e){const r=xr(this);if(r)return r}return e||null}};p(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ce,"type",n.InputMap),p(Ce,"USER_MANAGED_PARENT_TYPES",[...nt]),p(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES]),p(Ce,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(Ce,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),p(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,"index"]),p(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),p(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),p(Ce,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),p(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),p(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let kr=Ce;class aq extends kr{constructor(e,t){super(e,t);p(this,"declaration",null);p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class sq extends kr{constructor(e,t){super(e,t);p(this,"name",null);p(this,"description",null);p(this,"declaration");p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function oq(i){const s=N6(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-return-map-id"){const a=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var X1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(X1||{});const ge=class ge extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"index");p(this,"type",n.OutputMap);p(this,"parentRelationType");p(this,"defaultValue",null);p(this,"declaration");p(this,"writesValues",[]);p(this,"dataType");p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d;if(e.declaration){const c=g(e.declaration);d=t.get(c)}const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,index:(a.outputs||[]).length,defaultValue:null,declaration:d,writesValues:[],parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:nt.filter(c=>c!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);r=d.modifiedData;const o=t.get(r.parent);if(o&&nt.filter(c=>c!==n.Condition).includes(o.type)){const c=o.outputs.find(f=>f.declaration.id===(r.declaration?g(r.declaration):null));if(c)a.push(new D({id:`${r.id}--${I.OutputOverwrite}`,code:I.OutputOverwrite,severity:R.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${c.id}' that points to the same base 'return-declaration'.
158
+ 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})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return pi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];if(this.parent.addInput(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),Qe.includes(this.parent.type)&&((l=this.parent.getDataType())!=null&&l.inferred)){const c=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:f,added:y,removed:v,affected:E}=c.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...f),r.push(...y),a.push(...v),d.push(...E),t.push(c,...c.variableInstances)}return this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration&&(this.declaration=O(this.initialData.declaration,this.project)),pi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ce.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ce.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),e||(r.push(this.parent),this.parent.removeInput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.restore({},e)),r.push(this.parent),this.parent.addInput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;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,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v,E,P;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((y=this.declaration)==null?void 0:y.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,readsValue:((P=this.readsValue)==null?void 0:P.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.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):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=nq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var f;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.defaultValue=null,d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(f=this.defaultValue)==null?void 0:f.clone(l,w.UUID.uuid(),r);return l.defaultValue=c||null,l}getDataType(){var t;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this).self;if(Qe.includes(this.parent.type)){const r=Pn(this.parent),a=r.getDataType();(!a||a.inferred)&&r.inferDataTypeAndSyncInstancesInputsAndOutputs(null)}const e=(t=this.declaration)==null?void 0:t.getDataType();if(!e){const r=xr(this);if(r)return r}return e||null}};p(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ce,"type",n.InputMap),p(Ce,"USER_MANAGED_PARENT_TYPES",[...nt]),p(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES]),p(Ce,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),p(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,"index"]),p(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),p(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),p(Ce,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),p(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),p(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let kr=Ce;class aq extends kr{constructor(e,t){super(e,t);p(this,"declaration",null);p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class sq extends kr{constructor(e,t){super(e,t);p(this,"name",null);p(this,"description",null);p(this,"declaration");p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function oq(i){const s=N6(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-return-map-id"){const a=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var X1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(X1||{});const ge=class ge extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"index");p(this,"type",n.OutputMap);p(this,"parentRelationType");p(this,"defaultValue",null);p(this,"declaration");p(this,"writesValues",[]);p(this,"dataType");p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d;if(e.declaration){const c=g(e.declaration);d=t.get(c)}const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,index:(a.outputs||[]).length,defaultValue:null,declaration:d,writesValues:[],parent:a},l=O(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l;let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:nt.filter(c=>c!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);r=d.modifiedData;const o=t.get(r.parent);if(o&&nt.filter(c=>c!==n.Condition).includes(o.type)){const c=o.outputs.find(f=>f.declaration.id===(r.declaration?g(r.declaration):null));if(c)a.push(new D({id:`${r.id}--${I.OutputOverwrite}`,code:I.OutputOverwrite,severity:R.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${c.id}' that points to the same base 'return-declaration'.
159
159
  Any value reads can be done with that output-map instead.
160
160
  You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}));else{const f=r.declaration?t.get(r.declaration):null;if(f&&Qe.includes(o.type)){const y=Pn(o),v=y.dataType,E=(l=y.dataType)==null?void 0:l.entity;v?E?E.type===n.ActionDescriptor?a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The data type of the 'variable-declaration' is a 'action-descriptor' entity.
161
161
  This means it can hold a function-call or operation as its value, to be executed programatically.
@@ -165,7 +165,7 @@ ${bp}`,issue:null})):a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSign
165
165
  ${bp}`,issue:null}))}else if(f){const y=o.outputs.find(v=>v.declaration.id===r.declaration);y&&a.push(new D({id:`${r.id}--${I.OutputOverwrite}`,code:I.OutputOverwrite,severity:R.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${y.id}' that points to the same declaration.
166
166
  Any value reads can be done with that output-map instead.
167
167
  You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}))}}}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
168
- 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parentRelationType===Ln.Error?Qe.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===F["value-descriptor"][Us.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this),this.writesValues.forEach(l=>{l.setValueWriter(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),_s.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=O(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ge.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parentRelationType===Ln.Error?Qe.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parentRelationType===Ln.Error?Qe.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v,E;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(P=>P.toJSONClone({...e,newId:null})),declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((y=this.declaration)==null?void 0:y.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:(d=this.declaration)==null?void 0:d.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.declaration?this.declaration.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=oq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r);l.dataType=c||null;const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}getDataType(){var t;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this).self:((t=this.declaration)==null?void 0:t.getDataType())||null}};p(ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(ge,"type",n.OutputMap),p(ge,"USER_MANAGED_PARENT_TYPES",[...Yp]),p(ge,"PARENT_TYPES",[...ge.USER_MANAGED_PARENT_TYPES]),p(ge,"MUTABLE_BASE_PROPERTIES",[]),p(ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(ge,"BASE_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,...ge.INMUTABLE_BASE_PROPERTIES]),p(ge,"MUTABLE_META_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,"index"]),p(ge,"INMUTABLE_META_PROPERTIES",[...ge.INMUTABLE_BASE_PROPERTIES]),p(ge,"META_PROPERTIES",[...ge.MUTABLE_META_PROPERTIES,...ge.INMUTABLE_META_PROPERTIES]),p(ge,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(ge,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(ge,"UPSTREAM_PROPERTIES",[...ge.MUTABLE_UPSTREAM_PROPERTIES,...ge.INMUTABLE_UPSTREAM_PROPERTIES]),p(ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),p(ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(ge,"DOWNSTREAM_PROPERTIES",[...ge.MUTABLE_DOWNSTREAM_PROPERTIES,...ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(ge,"PROPERTIES",[...ge.META_PROPERTIES,...ge.UPSTREAM_PROPERTIES,...ge.DOWNSTREAM_PROPERTIES]);let Zr=ge;class dq extends Zr{constructor(e,t){super(e,t);p(this,"declaration");p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class lq extends Zr{constructor(e,t){super(e,t);p(this,"declaration");p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function uq(i){var a;const s=y5(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="company-dto-func-declaration-argument-dcl-id"){const d=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}if(i.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const d=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var Q1=(i=>(i.DataTypeEntity="data-type-entity",i.Implements="implements",i))(Q1||{});const Be=class Be extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"index");p(this,"required");p(this,"constant",!0);p(this,"type",n.ArgumentDeclaration);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"writesValues",[]);p(this,"implements",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:a.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:a},o=O(d,t);return o.setParent(a,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);r=d.modifiedData;const o=cp(r,t);if(r.parent){const l=t.get(g(r.parent));if(l&&at.includes(l.type)){const c=l.implements;if(c){const f=c.inputs.find(C=>C.name===r.name),y=c.inputs.filter(C=>!l.inputs.find(j=>j.type===n.ArgumentDeclaration&&j.name===C.name)),v=l.inputs.filter(C=>C.type===n.ArgumentDeclaration),E=v.find(C=>C.name===r.name),P=v.length?`The parent entity already implements the following arguments: ${re(v.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",V=y.length?`The parent entity is still missing the following arguments in the implementation: ${re(y.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";f?E&&a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${l.type}' with id '${l.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
168
+ 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parentRelationType===Ln.Error?Qe.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===F["value-descriptor"][Us.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this),this.writesValues.forEach(l=>{l.setValueWriter(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),_s.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=O(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ge.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parentRelationType===Ln.Error?Qe.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parentRelationType===Ln.Error?Qe.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c,f,y,v,E;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(P=>P.toJSONClone({...e,newId:null})),declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((y=this.declaration)==null?void 0:y.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:(d=this.declaration)==null?void 0:d.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.declaration?this.declaration.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=oq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r);l.dataType=c||null;const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}getDataType(){var t;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this).self:((t=this.declaration)==null?void 0:t.getDataType())||null}};p(ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(ge,"type",n.OutputMap),p(ge,"USER_MANAGED_PARENT_TYPES",[...Yp]),p(ge,"PARENT_TYPES",[...ge.USER_MANAGED_PARENT_TYPES]),p(ge,"MUTABLE_BASE_PROPERTIES",[]),p(ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(ge,"BASE_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,...ge.INMUTABLE_BASE_PROPERTIES]),p(ge,"MUTABLE_META_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,"index"]),p(ge,"INMUTABLE_META_PROPERTIES",[...ge.INMUTABLE_BASE_PROPERTIES]),p(ge,"META_PROPERTIES",[...ge.MUTABLE_META_PROPERTIES,...ge.INMUTABLE_META_PROPERTIES]),p(ge,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(ge,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),p(ge,"UPSTREAM_PROPERTIES",[...ge.MUTABLE_UPSTREAM_PROPERTIES,...ge.INMUTABLE_UPSTREAM_PROPERTIES]),p(ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),p(ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(ge,"DOWNSTREAM_PROPERTIES",[...ge.MUTABLE_DOWNSTREAM_PROPERTIES,...ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(ge,"PROPERTIES",[...ge.META_PROPERTIES,...ge.UPSTREAM_PROPERTIES,...ge.DOWNSTREAM_PROPERTIES]);let Zr=ge;class dq extends Zr{constructor(e,t){super(e,t);p(this,"declaration");p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class lq extends Zr{constructor(e,t){super(e,t);p(this,"declaration");p(this,"parent");p(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function uq(i){var a;const s=y5(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="company-dto-func-declaration-argument-dcl-id"){const d=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}if(i.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const d=pe({id:`${i.id}--${Z.PropertyImplementsNonAbstact}`,message:`Property "${U(i,i.project)}" with id "${i.id}" implements a non-abstract property "${U(i,i.project)}" with id "${i.id}".`,issue:null,severity:R.Error,code:Z.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var Q1=(i=>(i.DataTypeEntity="data-type-entity",i.Implements="implements",i))(Q1||{});const Be=class Be extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"index");p(this,"required");p(this,"constant",!0);p(this,"type",n.ArgumentDeclaration);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"writesValues",[]);p(this,"implements",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:a.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:a},o=O(d,t);return o.setParent(a,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);r=d.modifiedData;const o=cp(r,t);if(r.parent){const l=t.get(g(r.parent));if(l&&at.includes(l.type)){const c=l.implements;if(c){const f=c.inputs.find(C=>C.name===r.name),y=c.inputs.filter(C=>!l.inputs.find(j=>j.type===n.ArgumentDeclaration&&j.name===C.name)),v=l.inputs.filter(C=>C.type===n.ArgumentDeclaration),E=v.find(C=>C.name===r.name),P=v.length?`The parent entity already implements the following arguments: ${re(v.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",V=y.length?`The parent entity is still missing the following arguments in the implementation: ${re(y.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";f?E&&a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${l.type}' with id '${l.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
169
169
  Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
170
170
  ${P}
171
171
  ${V}`,issue:null})):a.push(new D({id:`${r.id}--${S.NoOverlapWithImplementedSignature}`,code:S.NoOverlapWithImplementedSignature,severity:R.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${l.type}' with id '${l.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
@@ -174,7 +174,7 @@ ${P}
174
174
  ${V}`,issue:null}))}}}return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
175
175
  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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.implements=this.implements,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.writesValues=this.writesValues,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.implements=o.implements,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.writesValues=o.writesValues,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addInputDeclaration(this,e),t.push(this.parent),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=O(this.initialData.implements,this.project);this.setImplements(t,null)}return _s.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Be.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parent.removeInputDeclaration(this)),this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}if(this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parent.addInputDeclaration(this,e),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.dataType)==null?void 0:a.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a;return e instanceof Set?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,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),parent:this.parent.toReference()}):(console.error("ArgumentDeclarationState.toJSON was called without a valid Set of seenEntities.",`
176
176
  Received type: ${typeof e}
177
- `,e),{})}toJSONClone(e=k){var r,a,d,o,l,c,f,y;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((y=this.implements)==null?void 0:y.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),implements:((d=this.implements)==null?void 0:d.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...((a=this.dataType)==null?void 0:a.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=uq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.dataType=null,d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r);l.dataType=c||null;const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}getDataType(){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};p(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Be,"type",n.ArgumentDeclaration),p(Be,"USER_MANAGED_PARENT_TYPES",[...at]),p(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),p(Be,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),p(Be,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),p(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),p(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),p(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),p(Be,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),p(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),p(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let Ui=Be;function cq(i){const s=Ec(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}function pq(i,s){var t,r;const e=[];if(i.parent)if(i.parent){const a=s.get(i.parent);a?[n.InputMap,n.DataType].includes(a.type)?a.type===n.DataType&&a.entity?e.push(new D({id:`${i.id}--${i.parent}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a 'parent' of type 'data-type' which already has an existing default value entity with id "${a.entity.id}".
177
+ `,e),{})}toJSONClone(e=k){var r,a,d,o,l,c,f,y;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((y=this.implements)==null?void 0:y.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),implements:((d=this.implements)==null?void 0:d.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...((a=this.dataType)==null?void 0:a.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=uq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.dataType=null,d.id=o;const l=lt(d,a);e?l.setParent(e,null):l.setParent(this.parent,null),r&&l.subscribe(),l.initChildren(null);const c=(y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r);l.dataType=c||null;const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}getDataType(){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};p(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Be,"type",n.ArgumentDeclaration),p(Be,"USER_MANAGED_PARENT_TYPES",[...at]),p(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),p(Be,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),p(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),p(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),p(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),p(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),p(Be,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),p(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),p(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),p(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let Ui=Be;function cq(i){const s=Ec(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}function pq(i,s){var t,r;const e=[];if(i.parent)if(i.parent){const a=s.get(i.parent);a?[n.InputMap,n.DataType].includes(a.type)?a.type===n.DataType&&a.entity?e.push(new D({id:`${i.id}--${i.parent}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a 'parent' of type 'data-type' which already has an existing default value entity with id "${a.entity.id}".
178
178
  Data types can only have one 'literal-value' entity as 'entity'.
179
179
  You can update the existing 'literal-value' with the 'update' action, for example, like so:
180
180
  \`\`\`json
@@ -199,12 +199,12 @@ You can update the existing 'literal-value' with the 'update' action, for exampl
199
199
  }
200
200
  }\`\`\`
201
201
  Or 'delete' and then 'post' actions to replace it.`,issue:null})):e.push(new D({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'input-map' or 'data-type'.`,issue:null})):e.push(new D({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new D({id:`${i.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null}));else return e.push(new D({id:`${i.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null})),e;if(i.valueAsTypeSingle){const a=[],d=[],o=i.valueAsTypeSingle;Array.isArray(o)?o.forEach(l=>{typeof l=="string"?d.push(l):a.push(l)}):typeof o=="string"?d.push(o):a.push(o),a.forEach(l=>{const c=_d(l);e.push(...c),c.length===0&&d.push(l.entityId)}),d.forEach(l=>{const c=s.get(l);c?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(c.type)||e.push(new D({id:`${i.id}--${l}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'valueAsTypeSingle' reference that isn't pointing to an entity of type 'definition-entity', 'function-declaration' or 'operation'.`,issue:null})):e.push(new D({id:`${i.id}--${l}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${l}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))})}return e}var eP=(i=>(i.ValueAsTypeSingle="value-as-type-single",i.ValueAsTypeList="value-as-type-list",i))(eP||{});const _e=class _e extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"type",n.LiteralValue);p(this,"id");p(this,"name");p(this,"autogeneration",null);p(this,"value",null);p(this,"valueAsTypeSingle",null);p(this,"valueAsTypeList",null);p(this,"errors",[]);p(this,"parent");p(this,"standaloneParent");p(this,"project");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"standalone",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.autogeneration=e.autogeneration,this.value=e.value}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null,o=null;e.valueAsTypeList?Array.isArray(e.valueAsTypeList)&&(o=e.valueAsTypeList.map(f=>t.get(f)||t.getBuiltIn(f))):e.valueAsTypeSingle&&(d=t.get(e.valueAsTypeSingle)||t.getBuiltIn(e.valueAsTypeSingle));const l={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:e.name,autogeneration:e.autogeneration,valueAsTypeSingle:d,valueAsTypeList:o,value:e.value||null,parent:a},c=O(l,t);return c.setParent(a,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=pq(r,t);return a.push(...d,...ot(r)),{errors:a,modifiedData:r}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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.
202
- 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(c=>c.id!==e.id),r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(d=>{const o=g(d),l=this.project.get(o);l&&this.valueAsTypeList.push(l)});else if(this.initialData.valueAsTypeSingle){const d=g(this.initialData.valueAsTypeSingle),o=this.project.get(d);o&&(this.valueAsTypeSingle=o)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(l=this.parent)==null||l.setDefaultValue(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsType(e){return e?(Array.isArray(e)?this.valueAsTypeList=e:this.valueAsTypeSingle=e,this):(this.valueAsTypeSingle=null,this.valueAsTypeList=null,this)}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=r,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=g(this.initialData.valueAsTypeSingle),a=r?this.project.get(r):null;if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=a,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.subscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.autogeneration=e.autogeneration||this.autogeneration,e.value!==void 0&&(this.value=e.value),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await _e.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await _e.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlat(e)):this.valueAsTypeSingle.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlatIds(e)):this.valueAsTypeSingle.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(a=>a.toJSON(e)):null,parent:(r=this.parent)==null?void 0:r.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(f=>this.project.getBuiltIn(f.id)?f.toJSON():f.toJSONClone({...e,newId:null})):this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,parent:(c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(d=this.parent)==null?void 0:d.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlatJSON(e)):this.valueAsTypeSingle.toFlatJSON(e):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(r=>r.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlatGenerationTarget(e)):this.valueAsTypeSingle.toFlatGenerationTarget(e):[]])}clearErrors(){return this.errors=[],this}validate(){const e=cq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.id=o;const l=lt(d,a);return l.initChildren(null),e&&l.setParent(e,null),r&&l.subscribe(),l}merge(e){const t=[],r=[],a=[],d=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle),t.push(this)),this.value!==e.value&&(this.value=e.value,t.push(this)),this.autogeneration!==e.autogeneration&&(this.autogeneration=e.autogeneration,t.push(this)),this.name!==e.name&&(this.name=e.name,t.push(this)),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(_e,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(_e,"type",n.LiteralValue),p(_e,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),p(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),p(_e,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),p(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),p(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES]),p(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),p(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),p(_e,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),p(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle"]),p(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let gn=_e;function fq(i){var a;const s=Y9(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];return Ye(i.errors,r)}var tP=(i=>(i.DataTypeEntity="data-type-entity",i))(tP||{});const Me=class Me extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"index");p(this,"required");p(this,"parentRelationType");p(this,"type",n.ValueDescriptor);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=e.parent?g(e.parent):null,a=r?t.get(r):null,d=e.parentRelationType===_.FixedArguments?a==null?void 0:a.inputs.length:a==null?void 0:a.outputs.length,o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:d||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:a},l=O(o,t);return a&&l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.ActionDescriptor]}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=r.parent&&t.get(r.parent),l=o&&Ji(o);return l&&l.type===n.ActionDescriptor&&a.push(new D({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:R.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${l.name}" of type '${l.type}' with id '${l.id}'.
202
+ 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})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(c=>c.id!==e.id),r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(d=>{const o=g(d),l=this.project.get(o);l&&this.valueAsTypeList.push(l)});else if(this.initialData.valueAsTypeSingle){const d=g(this.initialData.valueAsTypeSingle),o=this.project.get(d);o&&(this.valueAsTypeSingle=o)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(l=this.parent)==null||l.setDefaultValue(this),t.push(this.parent),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsType(e){return e?(Array.isArray(e)?this.valueAsTypeList=e:this.valueAsTypeSingle=e,this):(this.valueAsTypeSingle=null,this.valueAsTypeList=null,this)}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=r,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=g(this.initialData.valueAsTypeSingle),a=r?this.project.get(r):null;if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=a,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.autogeneration=e.autogeneration||this.autogeneration,e.value!==void 0&&(this.value=e.value),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await _e.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await _e.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlat(e)):this.valueAsTypeSingle.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlatIds(e)):this.valueAsTypeSingle.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;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,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(a=>a.toJSON(e)):null,parent:(r=this.parent)==null?void 0:r.toReference()})}toJSONClone(e=k){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(f=>this.project.getBuiltIn(f.id)?f.toJSON():f.toJSONClone({...e,newId:null})):this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,parent:(c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(d=this.parent)==null?void 0:d.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlatJSON(e)):this.valueAsTypeSingle.toFlatJSON(e):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(r=>r.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.flatMap(r=>r.toFlatGenerationTarget(e)):this.valueAsTypeSingle.toFlatGenerationTarget(e):[]])}clearErrors(){return this.errors=[],this}validate(){const e=cq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=null,t=null,r=!0){let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.id=o;const l=lt(d,a);return l.initChildren(null),e&&l.setParent(e,null),r&&l.subscribe(),l}merge(e){const t=[],r=[],a=[],d=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle),t.push(this)),this.value!==e.value&&(this.value=e.value,t.push(this)),this.autogeneration!==e.autogeneration&&(this.autogeneration=e.autogeneration,t.push(this)),this.name!==e.name&&(this.name=e.name,t.push(this)),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(_e,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(_e,"type",n.LiteralValue),p(_e,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),p(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),p(_e,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),p(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),p(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES]),p(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),p(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),p(_e,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),p(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),p(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let gn=_e;function fq(i){var a;const s=Y9(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];return Ye(i.errors,r)}var tP=(i=>(i.DataTypeEntity="data-type-entity",i))(tP||{});const Me=class Me extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"index");p(this,"required");p(this,"parentRelationType");p(this,"type",n.ValueDescriptor);p(this,"defaultValue",null);p(this,"dataType",null);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=e.parent?g(e.parent):null,a=r?t.get(r):null,d=e.parentRelationType===_.FixedArguments?a==null?void 0:a.inputs.length:a==null?void 0:a.outputs.length,o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:d||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:a},l=O(o,t);return a&&l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=It(r,{parent:{list:!1,types:[n.ActionDescriptor]}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=r.parent&&t.get(r.parent),l=o&&Ji(o);return l&&l.type===n.ActionDescriptor&&a.push(new D({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:R.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${l.name}" of type '${l.type}' with id '${l.id}'.
203
203
  You can't modify system entities that are built-in.`,issue:null})),o&&o.type===n.ActionDescriptor&&(!r.parentRelationType||!(r.parentRelationType===_.FixedArguments||r.parentRelationType===_.FixedReturns||r.parentRelationType===_.ReturnedError||r.parentRelationType===_.DynamicArgument||r.parentRelationType===_.DynamicReturn)?a.push(new D({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either '${_.FixedArguments}', '${_.FixedReturns}', or '${_.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`,issue:null})):r.parentRelationType===_.ReturnedError&&o.error&&a.push(new D({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`The entity with id '${e.id}' and type '${e.type}', is being added as an error value-descriptor to an entity of type 'action-descriptor' with id '${o.id}', which already has an error value descriptor with id '${o.error.id}'.
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
- ${qr({describe_entity:o.error.id})}`,issue:null}))),{errors:a,modifiedData:r}}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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r;return(r=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||r.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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l,c,f,y,v,E,P;const t=[this],r=[],a=[],d=[];return this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((l=this.parent)==null?void 0:l.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((f=(c=this.parent)==null?void 0:c.addInput)==null||f.call(c,this),t.push(this.parent)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?((y=this.parent)==null?void 0:y.type)===n.Search||((v=this.parent)==null?void 0:v.type)===n.Loop?(this.parent.addOutputDeclaration(this),t.push(this.parent)):((P=(E=this.parent)==null?void 0:E.addOutput)==null||P.call(E,this),t.push(this.parent)):this.parentRelationType===_.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.index=e.index||(e.index!==0?this.index:0),this.required=e.required||this.required,this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Me.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Me.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l,c,f,y,v,E,P;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(V=>{const{updated:C,removed:G,added:j}=V.entity.onDetachedDependencyRemoved(this,V.field,t);r.push(...C),a.push(...G),d.push(...j)}),this.defaultValue){const{updated:V,removed:C}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...V),a.push(...C)}if(this.dataType){const{updated:V,removed:C}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...V),a.push(...C)}return e||(((l=this.parent)==null?void 0:l.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(c=this.parent)==null||c.removeOutputDeclaration(this):this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?(f=this.parent)==null||f.removeInputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):((y=this.parent)==null?void 0:y.type)===n.Loop?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.removeOutputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(E=this.parent)==null||E.removeOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){var o,l,c,f,y,v,E;const t=[],r=[],a=[],d=[];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:P}=this.defaultValue.restore({},e);r.push(...P)}if(this.dataType){const{updated:P}=this.dataType.restore({},e);r.push(...P)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(l=this.parent)==null||l.addOutputDeclaration(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((c=this.parent)==null||c.addInputDeclaration(this,e)):((f=this.parent)==null?void 0:f.type)===n.Loop?(this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn)&&((y=this.parent)==null||y.addOutputDeclaration(this)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.addOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((E=this.parent)==null||E.addInput(this)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;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:((r=this.dataType)==null?void 0:r.toJSON(e))||null,parent:((a=this.parent)==null?void 0:a.toReference())||null})}toJSONClone(e=k){var r,a,d,o,l,c,f,y;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,parent:((y=this.parent)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.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=fq(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=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=t||w.UUID.uuid(),o=this.toJSON();o.id=d;const l=lt(o,a);e&&l.setParent(e,null),r&&l.subscribe();const c=((y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r))||null;c&&l.setDataType(c);const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}getDataType(){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}};p(Me,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Me,"type",n.ValueDescriptor),p(Me,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),p(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),p(Me,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),p(Me,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType"]),p(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),p(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),p(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),p(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),p(Me,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),p(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),p(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let Gi=Me;function yq(i,s){if(!i.type&&!i.id)return{errors:[new D({id:`last-generated-entity-payload--${I.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:R.Error,code:I.MissingTypeProperty,issue:null}),new D({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:R.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null};if(i.type){if(!i.id)return{errors:[new D({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:`Last generated entity, with type "${i.type}" is missing an 'id' property.`,severity:R.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new D({id:`${i.id}--${I.MissingTypeProperty}`,message:`Entity with id "${i.id}" is missing a 'type' property.`,severity:R.Error,code:I.MissingTypeProperty,issue:null})],modifiedData:null};if(i.type===n.GenericReference)return{errors:[new D({id:`${i.id}--${I.RootReference}`,message:`Generic reference entity with id "${i.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:R.Error,code:I.RootReference,issue:null})],modifiedData:null};const e=i,t=s.instances[e.id],r=s.builtInInstances[e.id];if(t&&!r&&e.type!==n.GenericReference){let a=`A previously generated entity with id "${e.id}" already exists in the project state.
207
+ ${qr({describe_entity:o.error.id})}`,issue:null}))),{errors:a,modifiedData:r}}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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r;return(r=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||r.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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l,c,f,y,v,E,P;const t=[this],r=[],a=[],d=[];return this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((l=this.parent)==null?void 0:l.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((f=(c=this.parent)==null?void 0:c.addInput)==null||f.call(c,this),t.push(this.parent)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?((y=this.parent)==null?void 0:y.type)===n.Search||((v=this.parent)==null?void 0:v.type)===n.Loop?(this.parent.addOutputDeclaration(this),t.push(this.parent)):((P=(E=this.parent)==null?void 0:E.addOutput)==null||P.call(E,this),t.push(this.parent)):this.parentRelationType===_.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=O(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.index=e.index||(e.index!==0?this.index:0),this.required=e.required||this.required,this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Me.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Me.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l,c,f,y,v,E,P;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(V=>{const{updated:C,removed:G,added:j}=V.entity.onDetachedDependencyRemoved(this,V.field,t);r.push(...C),a.push(...G),d.push(...j)}),this.defaultValue){const{updated:V,removed:C}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...V),a.push(...C)}if(this.dataType){const{updated:V,removed:C}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...V),a.push(...C)}return e||(((l=this.parent)==null?void 0:l.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(c=this.parent)==null||c.removeOutputDeclaration(this):this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?(f=this.parent)==null||f.removeInputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):((y=this.parent)==null?void 0:y.type)===n.Loop?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.removeOutputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(E=this.parent)==null||E.removeOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){var o,l,c,f,y,v,E;const t=[],r=[],a=[],d=[];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:P}=this.defaultValue.restore({},e);r.push(...P)}if(this.dataType){const{updated:P}=this.dataType.restore({},e);r.push(...P)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(l=this.parent)==null||l.addOutputDeclaration(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((c=this.parent)==null||c.addInputDeclaration(this,e)):((f=this.parent)==null?void 0:f.type)===n.Loop?(this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn)&&((y=this.parent)==null||y.addOutputDeclaration(this)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.addOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((E=this.parent)==null||E.addInput(this)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;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:((r=this.dataType)==null?void 0:r.toJSON(e))||null,parent:((a=this.parent)==null?void 0:a.toReference())||null})}toJSONClone(e=k){var r,a,d,o,l,c,f,y;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,parent:((y=this.parent)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.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=fq(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=null,t=null,r=!0){var y,v;let a=ft(e,this);const d=t||w.UUID.uuid(),o=this.toJSON();o.id=d;const l=lt(o,a);e&&l.setParent(e,null),r&&l.subscribe();const c=((y=this.dataType)==null?void 0:y.clone(l,w.UUID.uuid(),r))||null;c&&l.setDataType(c);const f=(v=this.defaultValue)==null?void 0:v.clone(l,w.UUID.uuid(),r);return l.defaultValue=f||null,l}getDataType(){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}};p(Me,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Me,"type",n.ValueDescriptor),p(Me,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),p(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),p(Me,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),p(Me,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),p(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),p(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),p(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),p(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),p(Me,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),p(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),p(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let Gi=Me;function yq(i,s){if(!i.type&&!i.id)return{errors:[new D({id:`last-generated-entity-payload--${I.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:R.Error,code:I.MissingTypeProperty,issue:null}),new D({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:R.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null};if(i.type){if(!i.id)return{errors:[new D({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:`Last generated entity, with type "${i.type}" is missing an 'id' property.`,severity:R.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new D({id:`${i.id}--${I.MissingTypeProperty}`,message:`Entity with id "${i.id}" is missing a 'type' property.`,severity:R.Error,code:I.MissingTypeProperty,issue:null})],modifiedData:null};if(i.type===n.GenericReference)return{errors:[new D({id:`${i.id}--${I.RootReference}`,message:`Generic reference entity with id "${i.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:R.Error,code:I.RootReference,issue:null})],modifiedData:null};const e=i,t=s.instances[e.id],r=s.builtInInstances[e.id];if(t&&!r&&e.type!==n.GenericReference){let a=`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: "${fp(e,s)}".`;return{errors:[new D({id:`duplicate--${e.id}--${I.EntityIdNotUnique}`,message:a,severity:R.Error,code:I.EntityIdNotUnique,issue:null})],modifiedData:i}}else if(t&&e.type!==n.GenericReference)return{errors:[new D({id:`${e.id}--${I.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: "${fp(e,s)}".`,severity:R.Error,code:I.EntityIdNotUnique,issue:null})],modifiedData:i};switch(e.type){case n.Project:return w.validateGenerationTarget(e,s);case n.DefinitionEntity:return Wi.validateGenerationTarget(e,s);case n.Property:return wi.validateGenerationTarget(e,s);case n.FunctionDeclaration:return gi.validateGenerationTarget(e,s);case n.DataType:return On.validateGenerationTarget(e,s);case n.Operation:return Bi.validateGenerationTarget(e,s);case n.FunctionCall:return ki.validateGenerationTarget(e,s);case n.VariableDeclaration:return Li.validateGenerationTarget(e,s);case n.VariableInstance:return Ni.validateGenerationTarget(e,s);case n.GlobalEvent:return Vn.validateGenerationTarget(e,s);case n.InputMap:return kr.validateGenerationTarget(e,s);case n.OutputMap:return Zr.validateGenerationTarget(e,s);case n.ArgumentDeclaration:return Ui.validateGenerationTarget(e,s);case n.ReturnDeclaration:return tr.validateGenerationTarget(e,s);case n.Loop:return _i.validateGenerationTarget(e,s);case n.Condition:return Mi.validateGenerationTarget(e,s);case n.Search:return Si.validateGenerationTarget(e,s);case n.InstalledProject:return $i.validateGenerationTarget(e,s);case n.InternalCall:return Cn.validateGenerationTarget(e,s);case n.LiteralValue:return gn.validateGenerationTarget(e,s);case n.ReturnStatement:return Ci.validateGenerationTarget(e,s);case n.BreakStatement:return wn.validateGenerationTarget(e,s);case n.ContinueStatement:return Ut.validateGenerationTarget(e,s);case n.ActionDescriptor:return Ze.validateGenerationTarget(e,s);case n.ValueDescriptor:return Gi.validateGenerationTarget(e,s);case n.BuiltInBaseEntity:case n.PrimitiveEntity:{const a="Did you mean to generate a",o={[n.BuiltInBaseEntity]:`${a} '${n.DefinitionEntity}' instead?`,[n.PrimitiveEntity]:`${a} '${n.DefinitionEntity}' instead?`}[e.type]||"";return{errors:[new D({id:`${e.id}--${I.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.`;a.push(new D({id:`${r.id}--${I.InvalidReference}`,code:I.InvalidReference,severity:R.Error,message:`Entity of type "${n.FunctionCall}" with id "${r.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'.${l}`,issue:null}))}return{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return(r=this.knownVersions)==null||r.set(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=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(c,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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:f,added:y,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),r.push(...l,...y),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",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=O(this.initialData.declaration,this.project);this.declaration=t}else{const t=g(this.initialData.declaration),r=this.project.get(t);this.declaration=r}return this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await xe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await xe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.process){const{updated:c,removed:f}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}if(this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.outputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.error){const{updated:c,removed:f}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;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(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Oq(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=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>!this.inputs.find(v=>v.declaration.id===y.id));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1},e)});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=O(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(G=>{G.index>=v.index&&G.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,V={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=O(V,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:f,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...f),a.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(xe,"type",n.FunctionCall),p(xe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),p(xe,"MUTABLE_BASE_PROPERTIES",[]),p(xe,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),p(xe,"MUTABLE_META_PROPERTIES",["x","y"]),p(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),p(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),p(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(xe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),p(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),p(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),p(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let ki=xe;function wp(i){return i&&typeof i.then=="function"}class Cp{constructor(s){p(this,"order",[]);p(this,"flatRecord",{});p(this,"allBuiltInEntityIds",qd());p(this,"onGoingVisits",{});this.flatten(s),this.orderEntities()}flatten(s){const e=new Set(qd()),t=u(N(s,e,{ignoreBuiltInBaseEntities:!0})),r=new Set;for(const a of t)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}moveEntityAfterDependencies(s){const{upstream:e}=Zd(s,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const r=this.order.indexOf(t),a=this.order.indexOf(s.id);if(r>a)return this.order.splice(a,1),this.order.splice(r,0,s.id),!0}return!1}orderEntities(){let s=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],r=this.flatRecord[t];if(this.moveEntityAfterDependencies(r)){s=!0;break}}s&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(s,e){const{upstream:t}=Zd(this.flatRecord[s],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),r={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([a,d])=>{Object.keys(t).includes(a)&&(r[a]=d)}),r}getDownstreamOngoingDependenciesVisits(s,e){const t=Object.keys(this.onGoingVisits[e]||{}),r=new Set(t.flatMap(d=>Object.keys(Zd(this.flatRecord[d],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),a={};return Array.from(r).forEach(d=>{d===s&&(a[d]=this.onGoingVisits[e][d])}),a}async settlePromises(s,e){const t=Object.values(s);t.length&&await Promise.all(t),Object.keys(s).forEach(r=>{delete this.onGoingVisits[e][r]})}visit(s){const e=this.order;for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}reverseVisit(s){const e=this.order.slice().reverse();for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}async visitAsync(s){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getUpstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);wp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(s){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getDownstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);wp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function hP(i,s){switch(i.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=i.project.entities.filter(l=>!!l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(l=>!!l.properties.find(c=>{var f;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=c.getDefaultValue())==null?void 0:f.value)===!0}))){const c=e[0].properties.find(y=>y.implements&&y.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),f=c==null?void 0:c.defaultValue;if(f)f.value=!0;else if(c!=null&&c.dataType){const y=O({id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:c==null?void 0:c.dataType.toReference()},i.project);return y.setParent(c==null?void 0:c.dataType,s),y.initChildren(s),y.addSelfToProject(s),{newEntities:[y]}}return{newEntities:[]}}const r=i.project.get(F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),a=Gd(r,"Main database",s);if(a.errors.length>0)return{newEntities:[]};const d=a.implemented.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=d==null?void 0:d.defaultValue;if(o)o.value=!0;else if(d!=null&&d.dataType){const l=O({id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s)}return{newEntities:[a.implemented]}}}return{newEntities:[]}}function mP(i,s){return i.implements.filter(t=>t.type===n.BuiltInBaseEntity).map(t=>{switch(t.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const a=i.project.entities.filter(l=>l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(l=>!!l.properties.find(c=>{var f;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=c.getDefaultValue())==null?void 0:f.value)===!0}));if(!a)return{newEntities:[]};const d=i.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),o=d==null?void 0:d.defaultValue;if(d&&(d!=null&&d.dataType)&&!o){const l=O({id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:a,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);return l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s),{newEntities:[l]}}return{newEntities:[]}}}}),{newEntities:[]}}function Gd(i,s,e,t){const r=t||w.UUID.uuid(),a={id:r,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:s,type:n.DefinitionEntity,description:null,static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[i],x:0,y:0,parent:i.project},d=Cd(a,i.project);if(d.length>0)return{errors:d,implemented:null,entitiesChanges:{new:[],updated:[],deleted:[]}};const o=hP(i,e),l=O(a,i.project);l.setParent(i.project,e),l.initChildren(e);const c=i.properties.map(v=>{const E=w.UUID.uuid(),P=v.clone(l,E);return P.abstract=!1,P.implements=v,P.setParent(l,e),l.addProperty(P),P}),f=i.abstractMethods.map(v=>{const E=w.UUID.uuid(),P=v.implementAsFunctionDeclaration(E),V={id:E+"-parent-ref-id",type:n.GenericReference,entityId:r,version:"1",entityType:n.DefinitionEntity},C={...P,implements:v,parent:V},G=O(C,i.project);return l.addMethod(G),G.setParent(l,e),G.initChildren(e),G.implements=v,G});a.properties=c,a.methods=f;const y=mP(l,e);return{implemented:l,errors:[],entitiesChanges:{new:[l,...o.newEntities,...y.newEntities],updated:[l],deleted:[]}}}function gp(i,s){return s.entities.find(r=>{const a=r.properties,d=a.map(y=>y.name),o=i.every(y=>d.includes(y)),l=d.filter(y=>!i.includes(y)),c=a.every(y=>!l.includes(y.name)||!y.required);return o&&c})||null}function vP(i,s,e,t=Et.OrDataTypeGroup){const r=[],a=[],d=[],o=[],c={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:i.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:s.toReference()},f=O(c,i.project);return a.push(f),f.setParent(s,e),f.initChildren(e),f.setEntity(i),f.addSelfToProject(e),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:f}}function Bp(i,s,e,t,r){var c,f,y,v,E,P,V,C;const a=[],d=[],o=[],l=[];switch(typeof i){case"string":let G=!1;const j=new Date(i);if(j instanceof Date&&!isNaN(j.valueOf())&&(G=!0),G){const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.Date].id);s.setEntity(B);break}else{const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id);s.setEntity(B);break}case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":if(i===null){s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else if(Array.isArray(i))if(s.metaSync({isList:!0},t),i.length>0){const B=i.slice(0,5).filter(z=>z!==void 0);if(B.every(z=>typeof z==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else{const z=[];let X=!1;B.forEach(oe=>{var qe,ee,fe,fr;if(Array.isArray(oe)&&(X=!0),typeof oe=="object"&&!Array.isArray(oe)&&oe!==null){const Yi=jd(oe,s.project,{...e,id:w.UUID.uuid()},t,r);Yi.hasCreated&&z.push((qe=Yi.changeSet)==null?void 0:qe.self),a.push(...(ee=Yi.changeSet)==null?void 0:ee.updated),d.push(...(fe=Yi.changeSet)==null?void 0:fe.added),o.push(...(fr=Yi.changeSet)==null?void 0:fr.removed)}});const me=u(z);if(!me.length&&!X){B.forEach(oe=>{const qe={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Et.OrDataTypeGroup,parent:s.toReference()},ee=O(qe,s.project);switch(ee.setParent(s,t),ee.initChildren(t),ee.addSelfToProject(t),typeof oe){case"string":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}});break}else me.length===1&&!X?s.setEntity(me[0]):B.forEach(oe=>{if(typeof oe=="object"&&!Array.isArray(oe)&&oe!==null){const qe=gp(Object.keys(oe),s.project);if(qe){const ee=vP(qe||me[0],s,t,Et.OrDataTypeGroup);a.push(...ee.updated),d.push(...ee.added),o.push(...ee.removed)}}else{const qe={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:Array.isArray(oe),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Et.OrDataTypeGroup,parent:s.toReference()},ee=O(qe,s.project);ee.setParent(s,t),ee.initChildren(t),ee.addSelfToProject(t);const fe=Bp(oe,ee,{...e,id:w.UUID.uuid()},t,r);a.push(...fe.updated),d.push(...fe.added),o.push(...fe.removed)}})}}else{const B=jd(i[0],s.project,{...e},t,r);s.setEntity((c=B.changeSet)==null?void 0:c.self),a.push(...(f=B.changeSet)==null?void 0:f.updated),d.push(...(y=B.changeSet)==null?void 0:y.added),o.push(...(v=B.changeSet)==null?void 0:v.removed);break}else{const B=jd(i,s.project,{...e},t,r);s.setEntity((E=B.changeSet)==null?void 0:E.self),a.push(...(P=B.changeSet)==null?void 0:P.updated),d.push(...(V=B.changeSet)==null?void 0:V.added),o.push(...(C=B.changeSet)==null?void 0:C.removed);break}}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:s}}function jd(i,s,e,t,r){const a=[],d=[],o=[],l=[],c=Object.keys(i),f=gp(c,s);if(f)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:f}};const y=r?e.name+" of "+r.name:e.name,E={id:e.id||w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:y,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:s.toReference()},P=O(E,s);return P.setParent(s,t),P.initChildren(t),P.addSelfToProject(t),d.push(P),c.forEach((V,C)=>{const j={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:V,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:P.toReference()},B=O(j,s);B.setParent(P,t),B.initChildren(t),B.addSelfToProject(t),d.push(B);const $=i[V],X={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},me=O(X,s);me.setParent(B,t),me.initChildren(t),me.addSelfToProject(t),d.push(me);const oe=Bp($,me,{...e,name:V,id:w.UUID.uuid()},t,r||P);a.push(...oe.updated),d.push(...oe.added),o.push(...oe.removed)}),{hasCreated:!0,changeSet:{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:P}}}function Fd(i,s){const e=Bn(i);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(a=>{if(a===s)return t=a,[a];const d=Fd(a,s);return d.last&&(t=d.last),[a,...d.list]}),last:t}}function TP(i,s,e=new Set){const t=Zi(i),r=Zi(s),a=t.filter(l=>!r.includes(l)),d=t.filter(l=>r.includes(l)),o=a.reduce((l,c)=>e.has(c.id)?l:(e.add(c.id),u([...l,...TP(c,s,e)])),[]);return u([...d,...o])}function Vs(i,s){const e=Fd(i,s);return e.last===s&&e.list.length>0&&e.list[0]!==s}function Vq(i,s){return!!Fd(i,s).last}function wq(i){if(at.includes(i.type))return i;if([...wr,n.VariableDeclaration].includes(i.type)){const s=i.parent;return at.includes(s.type)?s:null}return null}function _p(i,s){if(!i||!s)throw new Error("Both entities must be defined to find a common ancestor");if(i===s)return i;const e=i.parent;if(e){if(e===s)return s;if(e.type===n.Project)return null}else return null;const t=s.parent;if(t){if(t===i)return i;if(t.type===n.Project)return null}else return null;return _p(e,t)}function Vt(i){if($s.includes(i.type)){if(i.type===n.FunctionDeclaration){const s=i.parent;if(s.type===n.DefinitionEntity)return s;if(s.type===n.Loop)return s}return i}else{const s=i.parent;return s?Vt(s):null}}function xd(i,s){const e=ws(i,s);if(!e)return null;if($s.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=ws(e.parent,s);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?ws(e.parent,s):null;return t?xd(t,s):null}}function EP(i){if(!i)return null;if(wr.includes(i.type))return i;const s=i.parent;return s?EP(s):null}function IP(i){if(!i)return null;if(nt.includes(i.type))return i;const s=i.parent;return s?IP(s):null}function RP(i){if(!i)return null;if(Cr.includes(i.type))return i;const s=i.parent;return s?RP(s):null}function Cq(i){return i.type===n.VariableDeclaration?[i]:nt.includes(i.type)?[...i.inputs,...i.outputs||[]]:st.includes(i.type)?i.outputs:Sn.includes(i.type)||i.type===n.FunctionDeclaration?i.inputs:[]}function gq(i){const s=Zi(i),e=[],t=[];zp.includes(i.type)&&e.push(...Mp(i));const r=s.filter(a=>{const d=e.includes(a);return d?!1:wr.includes(a.type)&&!d?(t.push(a),!1):!0});return e.sort((a,d)=>Vs(d,a)?-1:0),t.sort((a,d)=>Vs(d,a)?-1:0),[...e,...t,...r]}function bP(i){return[...i].sort((s,e)=>Vs(e,s)?-1:0)}function Bq(i){const s=bP(i),e=[];return s.forEach(t=>{const r=e[e.length-1];if(r){const a=r[r.length-1];Vs(t,a)?e.push([t]):r.push(t)}else e.push([t])}),e}function Yt(i){const s=i.map(e=>Vt(e));return u(s)}function Mp(i){return nt.includes(i.type)?[...Yt(i.successCalls),...Yt(i.errorCalls)]:at.includes(i.type)?Yt(i.calls):[]}function _q(i,s){return Mp(i).includes(s)}function Np(i){return i.writesValues||[]}function Mq(i,s){return Np(i).includes(s)}function AP(i){var s;return Qe.includes((s=i==null?void 0:i.readsValue)==null?void 0:s.type)?i.readsValue:null}function Nq(i){return i.writesValues}function DP(i=[]){return i.map(AP).filter(s=>!!s)}function kd(i=[]){return i.map(s=>s.writesValues).flat().filter(s=>Qe.includes(s.type))}function PP(i=[]){return i.map(s=>s.readsValue).filter(s=>!!s&&Qe.includes(s.type))}function OP(i){return Qe.includes(i.type)?i:null}function VP(i){return i.writesValues.map(OP).filter(s=>!!s)}function wP(i=[]){return i.reduce((s,e)=>e.type===n.OutputMap?[...s,...VP(e)]:s,[])}function it(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function Lq(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function CP(i,s=new Set){return i.writesValues.filter(t=>Qe.includes(t.type)&&!s.has(t.id)).reduce((t,r)=>s.has(r.id)?t:[...t,...We(r,s)],[])}function gP(i,s=new Set){var t;return(((t=i.readsValue)==null?void 0:t.writesValues)||[]).filter(r=>Qe.includes(r.type)&&!s.has(r.id)).reduce((r,a)=>s.has(a.id)?r:[...r,...We(a,s)],[])}function We(i,s=new Set){if(s.has(i.id))return[];if(i.type===n.ReturnStatement)return PP(i.outputs).reduce((t,r)=>[...t,...We(r,s)],[]);if(i.type===n.FunctionCall||i.type===n.Operation||i.type===n.Condition)return[...it(i).reduce((a,d)=>{const o=Vt(d);return[...a,...We(o||d,s)]},[]),...DP(i.inputs),...wP(i.outputs)].reduce((a,d)=>[...a,...We(d,s)],[]);if(Sn.includes(i.type)){const e=kd(i.inputs),r=it(i).reduce((a,d)=>{const o=Vt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d,s)],[])}if(i.type===n.FunctionDeclaration){const e=[...kd(i.inputs)],r=it(i).reduce((a,d)=>{const o=Vt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d)],[])}if(Qe.includes(i.type)){s.add(i.id);const t=it(i).reduce((r,a)=>{const d=Vt(a);return[...r,...We(d||a,s)]},[]);return[i,...t,...gP(i,s),...CP(i,s)]}return[]}function rr(i,s=new Set){return s.has(i.id)?[]:(s.add(i.id),[...Zi(i).reduce((r,a)=>[...r,a,...rr(a,s)],[])])}function Jr(i){return i.reduce((s,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...s,e]:[...s,e,...it(e)],[])}function BP(i){const s=i.entities||[],e=[...s,...i.functions||[],...i.events||[],...i.projects||[]],t=s.reduce((l,c)=>[...l,...c.properties],[]),r=s.reduce((l,c)=>[...l,...c.methods],[]),a=r.reduce((l,c)=>[...l,...kd(c.inputs),...Jr(Yt(c.calls)),...c.returnStatements],[]),d=i.functions.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]),o=i.events.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]);return[...e,...t,...r,...a,...d,...o]}function _P(i,s){return s.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(r=>r.id===i.id)!==void 0||t.outputs.find(r=>r.id===i.id)!==void 0;case n.Condition:return t.successCalls.find(r=>r.id===i.id)!==void 0||t.errorCalls.find(r=>r.id===i.id)!==void 0||t.inputs.find(r=>r.id===i.id)!==void 0;case n.Operation:return t.outputs.find(r=>r.id===i.id)!==void 0;case n.VariableDeclaration:return nt.includes(i.type)?sO(i).find(a=>{var d;return((d=a.readsValue)==null?void 0:d.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(r=>r.id===i.id)!==void 0||t.methods.find(r=>r.id===i.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(r=>r.id===i.id)!==void 0||(t.returnStatements.map(r=>r.outputs).flat()||[]).find(r=>r.id===i.id)!==void 0;default:return!1}})}function Sq(i){const s=BP(i.project);return _P(i,s)}function ws(i,s){return i?typeof i=="string"?s[i]:i.type===n.GenericReference?s[i.entityId]:s[i.id]?s[i.id]:null:null}function Zd(i,s={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||(e.allBuiltInEntityIds||[]).includes(i.id)))return{upstream:{},downstream:{}};const t=i,r=i,a=i,d=i,o=i,l=i,c=i,f=i,y=i,v=i,E=i,P=i,V=i,C=[...V.readsValue?[V.readsValue]:[],...V.declaration?[V.declaration]:[],...(P.calledByEntry||[]).flatMap($=>$),...(P.calledBySuccess||[]).flatMap($=>$),...(P.calledByError||[]).flatMap($=>$),...(a.extends||[]).flatMap($=>$),...v.parent?[v.parent]:[]];Array.isArray(a.implements)?C.push(...a.implements.flatMap($=>$)):y.implements&&C.push(y.implements),Array.isArray(o.valueAsTypeSingle)?C.push(...o.valueAsTypeSingle.flatMap($=>$)):o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const G=[...(t.inputs||[]).flatMap($=>$),...(E.inputsDeclarations||[]).flatMap($=>$),...(t.outputs||[]).flatMap($=>$),...(E.outputsDeclarations||[]).flatMap($=>$),...(V.internalCalls||[]).flatMap($=>$),...V.writesValues||[],...P.dataType?[P.dataType]:[],...l.body?[l.body]:[],...P.defaultValue?[P.defaultValue]:[],...(P.successCalls||[]).flatMap($=>$),...(P.errorCalls||[]).flatMap($=>$),...(a.properties||[]).flatMap($=>$),...(a.methods||[]).flatMap($=>$),...(a.abstractMethods||[]).flatMap($=>$),...c.error?[c.error]:[],...c.process?[c.process]:[],...v.throws?[v.throws]:[],...(r.andChildrenGroup||[]).flatMap($=>$),...(r.orChildrenGroup||[]).flatMap($=>$),...(f.entities||[]).flatMap($=>$),...(f.functions||[]).flatMap($=>$),...(f.functionCalls||[]).flatMap($=>$),...(f.events||[]).flatMap($=>$),...(f.conditions||[]).flatMap($=>$),...(f.operations||[]).flatMap($=>$),...(f.loops||[]).flatMap($=>$),...(f.variableDeclarations||[]).flatMap($=>$),...(f.variableInstances||[]).flatMap($=>$),...(f.searches||[]).flatMap($=>$),...(f.projects||[]).flatMap($=>$),...(d.calls||[]).flatMap($=>$)];i.type===n.DataType&&(r.entity&&s[g(r.entity)]&&s[g(r.entity)].parent&&g(s[g(r.entity)].parent)===i.id?G.push(r.entity):r.entity&&C.push(r.entity));const j={},B={};return C.forEach($=>{const z=g($);if(z&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(z)))return;const X=$.version;z&&(j[z]=X)}),G.forEach($=>{const z=g($);if(z&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(z)))return;const X=$.version;z&&(B[z]=X)}),{upstream:j,downstream:B}}function $q(i,s){const e=[];if(wr.includes(i.type)){cr(i).forEach(a=>{const d=xd(a,s);d&&e.push(d)});const r=[...i.inputs||[],...i.outputs||[]].map(a=>{const d=ws(a,s);return d?dO(d,s):null}).filter(a=>a!==null);e.push(...u(r))}if(Qe.includes(i.type)){const t=Jd(i);t&&e.push(t)}return u(e)}function Bn(i){const s=[];if(wr.includes(i.type)){i.calledBy.forEach(r=>{const a=Vt(r);a&&s.push(a)});const t=[...i.inputs||[],...i.outputs||[]].map(r=>Jd(r)).filter(r=>r!==null);s.push(...u(t))}if(Qe.includes(i.type)){const e=Jd(i);e&&s.push(e)}return u(s)}function cr(i){return[...i.calledByEntry||[],...i.calledByError||[],...i.calledBySuccess||[]].filter(s=>s.type!==n.GenericReference)}function MP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[i,...i.inputs.flatMap(t=>N(t,s,e)),...i.outputs.flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.parent?N(i.parent,s,e):[]]}function NP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s):[],...i.writesValues.flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function LP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function SP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...(i.extends||[]).flatMap(t=>N(t,s,e))]}function $P(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function UP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function GP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[i,...(i.extends||[]).flatMap(t=>N(t,s,e)),...(i.implements||[]).flatMap(t=>N(t,s,e)),...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function jP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[i,...(i.andChildrenGroup||[]).flatMap(t=>N(t,s,e)),...(i.orChildrenGroup||[]).flatMap(t=>N(t,s,e)),...i.entity?N(i.entity,s,e):[],...i.parent?N(i.parent,s,e):[]]}function FP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function xP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function kP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function ZP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function qP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[i,...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function JP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.parent?N(i.parent,s,e):[]]}function WP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[i,...i.valueAsTypeSingle?Array.isArray(i.valueAsTypeSingle)?i.valueAsTypeSingle.flatMap(t=>N(t,s,e)):N(i.valueAsTypeSingle,s,e):[],...i.parent?N(i.parent,s,e):[]]}function YP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.body?N(i.body,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function zP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function HP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[i,...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function KP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e))]}function XP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[i,...(i.entities||[]).flatMap(t=>N(t,s,e)),...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.variableDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.variableInstances||[]).flatMap(t=>N(t,s,e)),...(i.operations||[]).flatMap(t=>N(t,s,e)),...(i.conditions||[]).flatMap(t=>N(t,s,e)),...(i.functionCalls||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.loops||[]).flatMap(t=>N(t,s,e)),...(i.searches||[]).flatMap(t=>N(t,s,e))]}function QP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function eO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function tO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[i,...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function rO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function iO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function nO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function aO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.parent?N(i.parent,s,e):[]]}function qd(){const i=new Set;return WE.flatMap(e=>N(e,i)).map(e=>e.id)}function N(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!i)throw new Error("Entity must be defined to be flattened");if(i.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||qd().includes(i.id)))return[];if(s.has(i.id))return[];switch(i.type){case n.FunctionCall:return FP(i,s,e);case n.Operation:return zP(i,s,e);case n.Condition:return $P(i,s,e);case n.Loop:return YP(i,s,e);case n.Search:return rO(i,s,e);case n.GlobalEvent:return kP(i,s,e);case n.ReturnStatement:return tO(i,s,e);case n.ContinueStatement:return UP(i,s,e);case n.BreakStatement:return LP(i,s,e);case n.VariableDeclaration:return nO(i,s,e);case n.DefinitionEntity:return GP(i,s,e);case n.FunctionDeclaration:return xP(i,s,e);case n.Project:return XP(i,s,e);case n.ActionDescriptor:return MP(i,s,e);case n.ArgumentDeclaration:return NP(i,s,e);case n.ReturnDeclaration:return eO(i,s,e);case n.ValueDescriptor:return iO(i,s,e);case n.InputMap:return ZP(i,s,e);case n.OutputMap:return HP(i,s,e);case n.DataType:return jP(i,s,e);case n.InstalledProject:return qP(i,s,e);case n.InternalCall:return JP(i,s,e);case n.LiteralValue:return WP(i,s,e);case n.Property:return QP(i,s,e);case n.VariableInstance:return aO(i,s,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:SP(i,s,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:KP(i,s,e)}return[]}function Lp(i){return i.type===n.FunctionCall||i.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.inputs:i.type===n.FunctionDeclaration||Sn.includes(i.type)?i.inputs:i.type===n.Search?i.inputsDeclarations:[]}function Uq(i,s){return s.type===n.Condition?s.inputs.find(e=>e.declaration.id===i.id):s.type===n.FunctionCall||s.type===n.Operation?s.inputs.find(e=>e.declaration.id===i.id):null}function sO(i){return nt.includes(i.type)?i.inputs:[]}function oO(i){var s;return i.type===n.FunctionCall?((s=i.declaration.returnStatements[0])==null?void 0:s.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.outputs:i.type===n.Search?i.outputsDeclarations:st.includes(i.type)?i.outputs:[]}function Gq(i,s){return s.type===n.Condition?null:s.type===n.FunctionCall||s.type===n.Operation?s.outputs.find(e=>e.declaration.id===i.id):null}function jq(i){return i.type===n.Condition?[]:nt.includes(i.type)?i.outputs:[]}function Jd(i){const s=i.readsValue;return s?Vt(s):null}function dO(i,s){const e=i.readsValue;return e?xd(e,s):null}function lO(i){const s=i.internalCalls||[];return u(Yt(u(s.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Ra(i){const s=Np(i),e=[];return s.forEach(t=>{if(Qe.includes(t.type))e.push(t);else if(fi.includes(t.type)){const r=t.parent;e.push(r)}}),e}function u(i){const s=new Set;return i.filter(e=>!e||s.has(e.id)?!1:(s.add(e.id),!0))}function Zi(i,s=!1){const e=[];if(i.type===n.Project&&e.push(...(i==null?void 0:i.entities)||[],...(i==null?void 0:i.functions)||[],...(i==null?void 0:i.variableDeclarations)||[],...(i==null?void 0:i.variableInstances)||[],...(i==null?void 0:i.searches)||[],...(i==null?void 0:i.loops)||[],...(i==null?void 0:i.operations)||[],...(i==null?void 0:i.conditions)||[],...(i==null?void 0:i.functionCalls)||[],...(i==null?void 0:i.events)||[],...(i==null?void 0:i.projects)||[]),mt.includes(i.type)&&e.push(...(i==null?void 0:i.detachedChildren)||[]),i.type===n.DefinitionEntity){const t=[...i.suggestedMethods,...i.methods].flatMap(r=>r.collapsed&&s?[]:Zi(r));e.push(...t)}if(i.type===n.Condition){const t=i.successCalls.map(a=>Vt(a)),r=i.errorCalls.map(a=>Vt(a));e.push(...t,...r)}if(Sn.includes(i.type)){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>Vt(a));e.push(...u(t),...r)}if(nt.includes(i.type)&&i.type!==n.Condition&&i.type!==n.Loop){const t=i==null?void 0:i.outputs.map(d=>Ra(d)).flat(),r=i.successCalls.map(d=>Vt(d)),a=i.errorCalls.map(d=>Vt(d));e.push(...u(t),...r,...a)}if(Qe.includes(i.type)){const t=Ra(i),r=lO(i);e.push(...t,...r)}if(i.type===n.Loop){const t=i.outputs.map(d=>Ra(d)).flat();if(i.body){const d=Zi(i.body,s);e.push(...d)}const r=i.errorCalls.map(d=>Vt(d)),a=i.successCalls.map(d=>Vt(d));e.push(...u(t),...a,...r)}if(i.type===n.FunctionDeclaration){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>Vt(a));e.push(...u(t),...r)}return u(e)}function uO(i,s=!1){const e=Zi(i,s),t=[...e,...e.reduce((r,a)=>[...r,...uO(a,s)],[])];return u(t)}function cO(i){const s=Bn(i),e=[...s,...s.reduce((t,r)=>[...t,...cO(r)],[])];return u(e)}function Wd(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Wd(e),...Yd(e)]:[...s,e.name],[])}function Yd(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Yd(e),...Wd(e)]:[...s,e.name],[])}function Sp(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...Sp(e),...$p(e)]:[...s,e],[])}function $p(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...$p(e),...Sp(e)]:[...s,e],[])}function Up(i){return[...Yd(i),...Wd(i)].filter((e,t,r)=>r.indexOf(e)===t)}function pO(i){return i.implements.length===0&&i.extends.length===0?null:i.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===W.PERSISTED_ENTITY)?i:[...i.implements,...i.extends].reduce((t,r)=>{if(r.type===n.DefinitionEntity){const a=pO(r);if(a)return a}return t},null)}function Fq(i){const s=i.extends.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function xq(i){const s=i.implements.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function Gp(i){const s=i.extends.find(e=>e.type===n.DefinitionEntity);return s&&s.type===n.DefinitionEntity?s:null}function qi(i){const s=[...i.implements,...i.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...qi(t)]:e,[]);return u(s)}function jp(i){return i.type===n.PrimitiveEntity?!0:i.type===n.BuiltInBaseEntity?i.interactive:!qi(i).find(t=>!t.interactive)}function kq(i){return i.parent===i.project&&i.project.variableDeclarations.includes(i)}function Fp(i){return i.parent!==i.project?!1:n.VariableDeclaration===i.type?i.project.variableDeclarations.includes(i):n.VariableInstance===i.type?i.project.variableInstances.includes(i):n.FunctionCall===i.type?i.project.functionCalls.includes(i):n.Condition===i.type?i.project.conditions.includes(i):n.Operation===i.type?i.project.operations.includes(i):n.Loop===i.type?i.project.loops.includes(i):n.Search===i.type?i.project.searches.includes(i):!1}function fO(i){if([...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||Fp(i))return!1;const s=Bn(i);return s.length===0?!0:s.some(e=>fO(e))}function xp(i){return[...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||Fp(i)?!1:Bn(i).length===0}function yO(i,s=0){if(xp(i)){const e=Bn(i);return e.length===0?i:e.map(r=>yO(r,s+1)).reduce((r,a)=>r?a&&a.x<r.x?a:r:a,null)}return null}function hO(i){const s=[];if(xp(i))s.push(i);else return[];return Bn(i).forEach(t=>{s.push(...hO(t))}),s}function mO(i){return i.type===n.FunctionDeclaration&&i.parent!==i.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(i.parent.type)}function Zq(i,s){const e=new Map;return i.forEach(t=>{e.set(t.id,t)}),s.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function Cs(i){switch(i){case n.DefinitionEntity:return Wi;case n.FunctionDeclaration:return gi;case n.VariableDeclaration:return Li;case n.VariableInstance:return Ni;case n.FunctionCall:return ki;case n.Operation:return Bi;case n.Condition:return Mi;case n.ReturnStatement:return Ci;case n.Loop:return _i;case n.Search:return Si;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.ArgumentDeclaration:return Ui;case n.ReturnDeclaration:return tr;case n.Property:return wi;case n.InstalledProject:return $i;case n.Project:return w;case n.BuiltInBaseEntity:return Wr;default:return null}}function zt(i,s){if(mt.includes(i.type))return i;if(hr.includes(i.type))return null;const e=i.parent;if(!e)return null;if(e.type===n.GenericReference){const t=g(e);if(!t)return null;const r=s.get(t);return r?zt(r,s):null}else return e===s?s:zt(e,s)}function kp(i,s){if(hr.includes(i.type)||s.getBuiltIn(i.id))return null;const e=ir(i.parent,s);return e?e===s?mt.includes(i.type)?i:null:e.type===n.DefinitionEntity?i:kp(e,s):null}function zd(i,s,e){if(i===s||s===e||i===e)return!1;const t=zt(s.parent,e);return t===i?!0:zd(t,s,e)}var Hd=(i=>(i.SameBothLocal="same-both-local",i.AInB="a-in-b",i.BInA="b-in-a",i.ParallelInCommonParent="parallel-in-common-parent",i.ParallelInProject="parallel-in-project",i.AIsGlobalBIsNot="a-is-global-b-is-not",i.BIsGlobalAIsNot="b-is-global-a-is-not",i.SameBothGlobal="same-both-global",i))(Hd||{});function gs(i,s,e){const t=zt(i,e),r=zt(s,e);if(!t)throw new Error("Could not find scope owner for the entity: "+i.id);if(!r)throw new Error("Could not find scope owner for the entity: "+s.id);if(t===r&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===r&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&r.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&r.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:r};if(zd(t,r,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(zd(r,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:r};const o=_p(t,r);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 vO(i,s,e){const t=gs(i,s,e);if(!t.compatible||t.type!=="same-both-local")return null;if(i===s)return i;let r=zt(i.parent,e);if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;for(;r;){if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;r=zt(r.parent,e)}let a=zt(s.parent,e);if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;for(;a;){if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;a=zt(a.parent,e)}return null}function TO(i){return i.length===0?null:i.length===1?i[0]:i.reduce((e,t)=>{const r=vO(e,t,t.project);return!r||r===t?e:t},i[0])}function ir(i,s){if(!i)return null;let e;return typeof i=="string"?e=i:i.type===n.GenericReference?e=g(i):e=i.id,e===s.id?s:s.get(e)}function Ji(i){if(!i)return null;if(hr.includes(i.type))return i;if(i.type===n.Project)return null;if(i.project.getBuiltIn(i.id))return i;const s=i.parent;return!s||s.type===n.Project?null:Ji(s)}function qq(i,s){var e;if(i.readsValue){const t=ir(i.readsValue,s.project);s.setValueWriter(t),t.addValueReader(s)}else i.readsValue===null&&((e=s.readsValue)==null||e.removeValueReader(s),s.readsValue=null);return s}function Bs(i){const s=[];function e(a,d){return s.some(o=>o.blockedByCaller===a&&o.blockedByCalling===d)}function t(a,d){e(a,d)||s.push({blockedByCaller:a,blockedByCalling:d})}const r=kp(i,i.project);return i.calledBySuccess.forEach(a=>{[...a.successCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(y=>y===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=Bs(o);l.reachable||it(i).find(y=>y===a)||l.blocks.forEach(y=>{t(a,y.blockedByCalling)})}}),i.calledByError.forEach(a=>{[...a.errorCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(y=>y===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=Bs(o);l.reachable||it(i).find(y=>y===a)||l.blocks.forEach(y=>{t(a,y.blockedByCalling)})}}),i.calledByEntry.forEach(a=>{if([...a.calls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(y=>y===l)||t(a,l))}),a===r)return;let o;if(a.type===n.FunctionDeclaration){const l=Vt(a);if(l.type===n.DefinitionEntity)return;l.type===n.Loop&&(o=l)}if(o){const l=Bs(o);l.reachable||l.blocks.forEach(c=>{t(a,c.blockedByCalling)})}}),{reachable:s.length===0,entryPoint:r,blocks:s}}function Jq(i){return $s.includes(i.type)?i.type===n.FunctionDeclaration?!mO(i):!0:!1}function Wq(i){if(n.ActionDescriptor===i.type){if(i.project.operationDeclarations.find(a=>a.id===i.id))return n.Operation;if(i.project.globalEventActionDescriptors.find(a=>a.id===i.id))return n.GlobalEvent;if(i.project.loopDeclarations.find(a=>a.id===i.id))return n.Loop;if(i.project.conditionDeclarations.find(a=>a.id===i.id))return n.Condition}return i.type}function ba(i,s){if(i.type!==n.DefinitionEntity||i.abstract)return!1;const e=Gp(i)||i;return!!Up(e).includes(s)}function Yq(i){const s=[];return i.entities.forEach(e=>{if(ba(e,W.PERSISTED_ENTITY)){s.push(e);return}}),u(s)}function zq(i){const s=[];return i.entities.forEach(e=>{if(ba(e,W.RELATIONAL_DATABASE)){s.push(e);return}}),u(s)}function Hq(i){return i.type!==n.DefinitionEntity||i.abstract||!ba(i,W.PERSISTED_ENTITY)?null:(i==null?void 0:i.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===F[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function Kq(i){if(i.type!==n.DefinitionEntity)return[];if(i.abstract)return[];if(!ba(i,W.PERSISTED_ENTITY))return[];const s=[],e=i.properties.filter(t=>{var r;return((r=t.implements)==null?void 0:r.id)!==F[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return s.push(...e),s}function Xq(i){var e;if(!i||i.type!==n.DefinitionEntity||!ba(i,W.PERSISTED_ENTITY))return null;const s=i.properties.find(t=>{var r;return((r=t.implements)==null?void 0:r.id)===F[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.database.id});return(e=s==null?void 0:s.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function ft(i,s){var t;if(!Kp.includes(s.type)||!i)return s.project||null;let e=s.project;return i.type===n.Project?e=i:((t=s.project)==null?void 0:t.id)!==i.project.id&&(e=i.project),e}function Qq(i){switch(i){case n.Project:return w;case n.InstalledProject:return $i;case n.DefinitionEntity:return Wi;case n.FunctionDeclaration:return gi;case n.GlobalEvent:return Vn;case n.VariableInstance:return Ni;case n.VariableDeclaration:return Li;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.Condition:return Mi;case n.Operation:return Bi;case n.FunctionCall:return ki;case n.ReturnDeclaration:return tr;case n.ArgumentDeclaration:return Ui;case n.PrimitiveEntity:return pr;case n.DataType:return On;case n.Property:return wi;case n.ActionDescriptor:return Ze;case n.ReturnStatement:return Ci;case n.ContinueStatement:return Ut;case n.BreakStatement:return wn;case n.Loop:return _i;case n.Search:return Si;case n.ValueDescriptor:return Gi;case n.InternalCall:return Cn;case n.LiteralValue:return gn}return null}function eJ(i){const s={added:{},updated:{},removed:new Set,affected:new Set,seenEntities:[],self:i==null?void 0:i.self};return i==null||i.added.forEach(e=>{s.added[e.id]=e}),i==null||i.updated.forEach(e=>{s.updated[e.id]=e}),s.removed=new Set(i==null?void 0:i.removed.map(e=>e.id)),s}function dt(i,s){const e=Cs(i.type);return e?!e.MUTABLE_META_PROPERTIES.every(r=>{const a=i[r],d=s[r];return d===void 0||a===d?!0:Array.isArray(a)&&Array.isArray(d)?a.length!==d.length?!1:a.every((o,l)=>o===d[l]):!1}):!1}function tJ(i,s){const e=[];if(i.parent)if(i.id===i.parent)e.push(new D({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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=s.get(i.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new D({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new D({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return i.implements&&Array.isArray(i.implements)?i.implements.forEach(t=>{if(i.id===t){e.push(new D({id:`${i.id}--${t}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract||e.push(new D({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new D({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' property that isn't an array.`,issue:null})),i.extends&&Array.isArray(i.extends)&&i.extends.forEach(t=>{const r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract&&e.push(new D({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 EO=(i=>(i.Extends="extends",i.Implements="implements",i))(EO||{});const Ne=class Ne extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"static");p(this,"abstract");p(this,"type",n.DefinitionEntity);p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"implements",[]);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestedProperties",[]);p(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 fromGenerationTarget(e,t){let r=t;if(e.parent){const c=g(e.parent);r=t.get(c)}const a=[];e.implements&&e.implements.forEach(c=>{a.push(t.get(c)||t.getBuiltIn(c))});const d=[];e.extends&&e.extends.forEach(c=>{d.push(t.get(c)||t.getBuiltIn(c))});const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:d,implements:a,x:0,y:0,parent:r},l=O(o,t);return l.setParent(r,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=tJ(r,t),o=Cd(r,t);a.push(...d,...o,...ot(r));const l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DataType){const c=l;c.entity&&a.push(new D({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${c.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="parent"){const{updated:c,added:f,removed:y}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}if(t==="parent"){const{updated:c,added:f,removed:y}=this.restore({},r);a.push(...c),d.push(...f),o.push(...y)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return(r=this.knownVersions)==null||r.set(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=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(c,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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:f,added:y,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),r.push(...l,...y),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",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=O(this.initialData.declaration,this.project);this.declaration=t}else{const t=g(this.initialData.declaration),r=this.project.get(t);this.declaration=r}return this.successCalls=this.initialData.successCalls.map(t=>{const r=O(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=O(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=O(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=O(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.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await xe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await xe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:f,removed:y,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...f),a.push(...y),d.push(...v)}),this.process){const{updated:c,removed:f}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}if(this.inputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.outputs.forEach(c=>{const{updated:f,removed:y}=c.remove({ignoreUpstream:!0},t);r.push(...f),a.push(...y)}),this.error){const{updated:c,removed:f}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;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(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=k){var r,a,d,o,l,c,f;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(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,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.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(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Oq(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=null,t=null,r=!0){var E,P;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.inputs=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e?f.setParent(e,null):f.setParent(this.parent,null),r&&f.subscribe(),f.initChildren(null);const y=(E=this.inputs)==null?void 0:E.map((V,C)=>V.clone(f,c+"-input-map-"+C+"-id",r));f.inputs=y;const v=(P=this.outputs)==null?void 0:P.map((V,C)=>V.clone(f,c+"-output-map-"+C+"-id",r));return f.outputs=v,this.error&&(f.error=this.error.clone(f,c+"-error-map-id",r)),this.process&&(f.process=this.process.clone(f,c+"-process-id",r)),f}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var f;return c.id===((f=o.declaration)==null?void 0:f.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(y=>!this.inputs.find(v=>v.declaration.id===y.id));this.inputs.sort((y,v)=>y.index-v.index),o.forEach(y=>{this.inputs.forEach(P=>{P.index>=y.index&&P.metaSync({index:P.index+1},e)});const v={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:y.toJSON(),readsValue:null,defaultValue:null,index:y.index,name:null,description:null,parent:this.toReference()},E=O(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((y,v)=>y.index-v.index);const{updated:l,added:c,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=O(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(G=>{G.index>=v.index&&G.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,V={id:w.UUID.uuid(),version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=O(V,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:f,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...f),a.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};p(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(xe,"type",n.FunctionCall),p(xe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),p(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),p(xe,"MUTABLE_BASE_PROPERTIES",[]),p(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),p(xe,"MUTABLE_META_PROPERTIES",["x","y"]),p(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),p(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),p(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),p(xe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),p(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),p(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),p(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let ki=xe;function wp(i){return i&&typeof i.then=="function"}class Cp{constructor(s){p(this,"order",[]);p(this,"flatRecord",{});p(this,"allBuiltInEntityIds",qd());p(this,"onGoingVisits",{});this.flatten(s),this.orderEntities()}flatten(s){const e=new Set(qd()),t=u(N(s,e,{ignoreBuiltInBaseEntities:!0})),r=new Set;for(const a of t)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}moveEntityAfterDependencies(s){const{upstream:e}=Zd(s,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const r=this.order.indexOf(t),a=this.order.indexOf(s.id);if(r>a)return this.order.splice(a,1),this.order.splice(r,0,s.id),!0}return!1}orderEntities(){let s=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],r=this.flatRecord[t];if(this.moveEntityAfterDependencies(r)){s=!0;break}}s&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(s,e){const{upstream:t}=Zd(this.flatRecord[s],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),r={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([a,d])=>{Object.keys(t).includes(a)&&(r[a]=d)}),r}getDownstreamOngoingDependenciesVisits(s,e){const t=Object.keys(this.onGoingVisits[e]||{}),r=new Set(t.flatMap(d=>Object.keys(Zd(this.flatRecord[d],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),a={};return Array.from(r).forEach(d=>{d===s&&(a[d]=this.onGoingVisits[e][d])}),a}async settlePromises(s,e){const t=Object.values(s);t.length&&await Promise.all(t),Object.keys(s).forEach(r=>{delete this.onGoingVisits[e][r]})}visit(s){const e=this.order;for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}reverseVisit(s){const e=this.order.slice().reverse();for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}async visitAsync(s){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getUpstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);wp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(s){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getDownstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);wp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function hP(i,s){switch(i.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=i.project.entities.filter(l=>!!l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(l=>!!l.properties.find(c=>{var f;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=c.getDefaultValue())==null?void 0:f.value)===!0}))){const c=e[0].properties.find(y=>y.implements&&y.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),f=c==null?void 0:c.defaultValue;if(f)f.value=!0;else if(c!=null&&c.dataType){const y=O({id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:c==null?void 0:c.dataType.toReference()},i.project);return y.setParent(c==null?void 0:c.dataType,s),y.initChildren(s),y.addSelfToProject(s),{newEntities:[y]}}return{newEntities:[]}}const r=i.project.get(F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),a=Gd(r,"Main database",s);if(a.errors.length>0)return{newEntities:[]};const d=a.implemented.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=d==null?void 0:d.defaultValue;if(o)o.value=!0;else if(d!=null&&d.dataType){const l=O({id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s)}return{newEntities:[a.implemented]}}}return{newEntities:[]}}function mP(i,s){return i.implements.filter(t=>t.type===n.BuiltInBaseEntity).map(t=>{switch(t.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const a=i.project.entities.filter(l=>l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(l=>!!l.properties.find(c=>{var f;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=c.getDefaultValue())==null?void 0:f.value)===!0}));if(!a)return{newEntities:[]};const d=i.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),o=d==null?void 0:d.defaultValue;if(d&&(d!=null&&d.dataType)&&!o){const l=O({id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:a,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);return l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s),{newEntities:[l]}}return{newEntities:[]}}}}),{newEntities:[]}}function Gd(i,s,e,t){const r=t||w.UUID.uuid(),a={id:r,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:s,type:n.DefinitionEntity,description:null,static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[i],x:0,y:0,parent:i.project},d=Cd(a,i.project);if(d.length>0)return{errors:d,implemented:null,entitiesChanges:{new:[],updated:[],deleted:[]}};const o=hP(i,e),l=O(a,i.project);l.setParent(i.project,e),l.initChildren(e);const c=i.properties.map(v=>{const E=w.UUID.uuid(),P=v.clone(l,E);return P.abstract=!1,P.implements=v,P.setParent(l,e),l.addProperty(P),P}),f=i.abstractMethods.map(v=>{const E=w.UUID.uuid(),P=v.implementAsFunctionDeclaration(E),V={id:E+"-parent-ref-id",type:n.GenericReference,entityId:r,version:"1",entityType:n.DefinitionEntity},C={...P,implements:v,parent:V},G=O(C,i.project);return l.addMethod(G),G.setParent(l,e),G.initChildren(e),G.implements=v,G});a.properties=c,a.methods=f;const y=mP(l,e);return{implemented:l,errors:[],entitiesChanges:{new:[l,...o.newEntities,...y.newEntities],updated:[l],deleted:[]}}}function gp(i,s){return s.entities.find(r=>{const a=r.properties,d=a.map(y=>y.name),o=i.every(y=>d.includes(y)),l=d.filter(y=>!i.includes(y)),c=a.every(y=>!l.includes(y.name)||!y.required);return o&&c})||null}function vP(i,s,e,t=Et.OrDataTypeGroup){const r=[],a=[],d=[],o=[],c={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:i.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:s.toReference()},f=O(c,i.project);return a.push(f),f.setParent(s,e),f.initChildren(e),f.setEntity(i),f.addSelfToProject(e),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:f}}function Bp(i,s,e,t,r){var c,f,y,v,E,P,V,C;const a=[],d=[],o=[],l=[];switch(typeof i){case"string":let G=!1;const j=new Date(i);if(j instanceof Date&&!isNaN(j.valueOf())&&(G=!0),G){const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.Date].id);s.setEntity(B);break}else{const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id);s.setEntity(B);break}case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":if(i===null){s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else if(Array.isArray(i))if(s.metaSync({isList:!0},t),i.length>0){const B=i.slice(0,5).filter(z=>z!==void 0);if(B.every(z=>typeof z==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else{const z=[];let X=!1;B.forEach(oe=>{var qe,ee,fe,fr;if(Array.isArray(oe)&&(X=!0),typeof oe=="object"&&!Array.isArray(oe)&&oe!==null){const Yi=jd(oe,s.project,{...e,id:w.UUID.uuid()},t,r);Yi.hasCreated&&z.push((qe=Yi.changeSet)==null?void 0:qe.self),a.push(...(ee=Yi.changeSet)==null?void 0:ee.updated),d.push(...(fe=Yi.changeSet)==null?void 0:fe.added),o.push(...(fr=Yi.changeSet)==null?void 0:fr.removed)}});const me=u(z);if(!me.length&&!X){B.forEach(oe=>{const qe={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Et.OrDataTypeGroup,parent:s.toReference()},ee=O(qe,s.project);switch(ee.setParent(s,t),ee.initChildren(t),ee.addSelfToProject(t),typeof oe){case"string":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":ee.setEntity(ee.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}});break}else me.length===1&&!X?s.setEntity(me[0]):B.forEach(oe=>{if(typeof oe=="object"&&!Array.isArray(oe)&&oe!==null){const qe=gp(Object.keys(oe),s.project);if(qe){const ee=vP(qe||me[0],s,t,Et.OrDataTypeGroup);a.push(...ee.updated),d.push(...ee.added),o.push(...ee.removed)}}else{const qe={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:Array.isArray(oe),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Et.OrDataTypeGroup,parent:s.toReference()},ee=O(qe,s.project);ee.setParent(s,t),ee.initChildren(t),ee.addSelfToProject(t);const fe=Bp(oe,ee,{...e,id:w.UUID.uuid()},t,r);a.push(...fe.updated),d.push(...fe.added),o.push(...fe.removed)}})}}else{const B=jd(i[0],s.project,{...e},t,r);s.setEntity((c=B.changeSet)==null?void 0:c.self),a.push(...(f=B.changeSet)==null?void 0:f.updated),d.push(...(y=B.changeSet)==null?void 0:y.added),o.push(...(v=B.changeSet)==null?void 0:v.removed);break}else{const B=jd(i,s.project,{...e},t,r);s.setEntity((E=B.changeSet)==null?void 0:E.self),a.push(...(P=B.changeSet)==null?void 0:P.updated),d.push(...(V=B.changeSet)==null?void 0:V.added),o.push(...(C=B.changeSet)==null?void 0:C.removed);break}}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:s}}function jd(i,s,e,t,r){const a=[],d=[],o=[],l=[],c=Object.keys(i),f=gp(c,s);if(f)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:f}};const y=r?e.name+" of "+r.name:e.name,E={id:e.id||w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:y,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:s.toReference()},P=O(E,s);return P.setParent(s,t),P.initChildren(t),P.addSelfToProject(t),d.push(P),c.forEach((V,C)=>{const j={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:V,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:P.toReference()},B=O(j,s);B.setParent(P,t),B.initChildren(t),B.addSelfToProject(t),d.push(B);const $=i[V],X={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},me=O(X,s);me.setParent(B,t),me.initChildren(t),me.addSelfToProject(t),d.push(me);const oe=Bp($,me,{...e,name:V,id:w.UUID.uuid()},t,r||P);a.push(...oe.updated),d.push(...oe.added),o.push(...oe.removed)}),{hasCreated:!0,changeSet:{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:P}}}function Fd(i,s){const e=Bn(i);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(a=>{if(a===s)return t=a,[a];const d=Fd(a,s);return d.last&&(t=d.last),[a,...d.list]}),last:t}}function TP(i,s,e=new Set){const t=Zi(i),r=Zi(s),a=t.filter(l=>!r.includes(l)),d=t.filter(l=>r.includes(l)),o=a.reduce((l,c)=>e.has(c.id)?l:(e.add(c.id),u([...l,...TP(c,s,e)])),[]);return u([...d,...o])}function Vs(i,s){const e=Fd(i,s);return e.last===s&&e.list.length>0&&e.list[0]!==s}function Vq(i,s){return!!Fd(i,s).last}function wq(i){if(at.includes(i.type))return i;if([...wr,n.VariableDeclaration].includes(i.type)){const s=i.parent;return at.includes(s.type)?s:null}return null}function _p(i,s){if(!i||!s)throw new Error("Both entities must be defined to find a common ancestor");if(i===s)return i;const e=i.parent;if(e){if(e===s)return s;if(e.type===n.Project)return null}else return null;const t=s.parent;if(t){if(t===i)return i;if(t.type===n.Project)return null}else return null;return _p(e,t)}function Vt(i){if($s.includes(i.type)){if(i.type===n.FunctionDeclaration){const s=i.parent;if(s.type===n.DefinitionEntity)return s;if(s.type===n.Loop)return s}return i}else{const s=i.parent;return s?Vt(s):null}}function xd(i,s){const e=ws(i,s);if(!e)return null;if($s.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=ws(e.parent,s);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?ws(e.parent,s):null;return t?xd(t,s):null}}function EP(i){if(!i)return null;if(wr.includes(i.type))return i;const s=i.parent;return s?EP(s):null}function IP(i){if(!i)return null;if(nt.includes(i.type))return i;const s=i.parent;return s?IP(s):null}function RP(i){if(!i)return null;if(Cr.includes(i.type))return i;const s=i.parent;return s?RP(s):null}function Cq(i){return i.type===n.VariableDeclaration?[i]:nt.includes(i.type)?[...i.inputs,...i.outputs||[]]:st.includes(i.type)?i.outputs:Sn.includes(i.type)||i.type===n.FunctionDeclaration?i.inputs:[]}function gq(i){const s=Zi(i),e=[],t=[];zp.includes(i.type)&&e.push(...Mp(i));const r=s.filter(a=>{const d=e.includes(a);return d?!1:wr.includes(a.type)&&!d?(t.push(a),!1):!0});return e.sort((a,d)=>Vs(d,a)?-1:0),t.sort((a,d)=>Vs(d,a)?-1:0),[...e,...t,...r]}function bP(i){return[...i].sort((s,e)=>Vs(e,s)?-1:0)}function Bq(i){const s=bP(i),e=[];return s.forEach(t=>{const r=e[e.length-1];if(r){const a=r[r.length-1];Vs(t,a)?e.push([t]):r.push(t)}else e.push([t])}),e}function Yt(i){const s=i.map(e=>Vt(e));return u(s)}function Mp(i){return nt.includes(i.type)?[...Yt(i.successCalls),...Yt(i.errorCalls)]:at.includes(i.type)?Yt(i.calls):[]}function _q(i,s){return Mp(i).includes(s)}function Np(i){return i.writesValues||[]}function Mq(i,s){return Np(i).includes(s)}function AP(i){var s;return Qe.includes((s=i==null?void 0:i.readsValue)==null?void 0:s.type)?i.readsValue:null}function Nq(i){return i.writesValues}function DP(i=[]){return i.map(AP).filter(s=>!!s)}function kd(i=[]){return i.map(s=>s.writesValues).flat().filter(s=>Qe.includes(s.type))}function PP(i=[]){return i.map(s=>s.readsValue).filter(s=>!!s&&Qe.includes(s.type))}function OP(i){return Qe.includes(i.type)?i:null}function VP(i){return i.writesValues.map(OP).filter(s=>!!s)}function wP(i=[]){return i.reduce((s,e)=>e.type===n.OutputMap?[...s,...VP(e)]:s,[])}function it(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function Lq(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function CP(i,s=new Set){return i.writesValues.filter(t=>Qe.includes(t.type)&&!s.has(t.id)).reduce((t,r)=>s.has(r.id)?t:[...t,...We(r,s)],[])}function gP(i,s=new Set){var t;return(((t=i.readsValue)==null?void 0:t.writesValues)||[]).filter(r=>Qe.includes(r.type)&&!s.has(r.id)).reduce((r,a)=>s.has(a.id)?r:[...r,...We(a,s)],[])}function We(i,s=new Set){if(s.has(i.id))return[];if(i.type===n.ReturnStatement)return PP(i.outputs).reduce((t,r)=>[...t,...We(r,s)],[]);if(i.type===n.FunctionCall||i.type===n.Operation||i.type===n.Condition)return[...it(i).reduce((a,d)=>{const o=Vt(d);return[...a,...We(o||d,s)]},[]),...DP(i.inputs),...wP(i.outputs)].reduce((a,d)=>[...a,...We(d,s)],[]);if(Sn.includes(i.type)){const e=kd(i.inputs),r=it(i).reduce((a,d)=>{const o=Vt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d,s)],[])}if(i.type===n.FunctionDeclaration){const e=[...kd(i.inputs)],r=it(i).reduce((a,d)=>{const o=Vt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d)],[])}if(Qe.includes(i.type)){s.add(i.id);const t=it(i).reduce((r,a)=>{const d=Vt(a);return[...r,...We(d||a,s)]},[]);return[i,...t,...gP(i,s),...CP(i,s)]}return[]}function rr(i,s=new Set){return s.has(i.id)?[]:(s.add(i.id),[...Zi(i).reduce((r,a)=>[...r,a,...rr(a,s)],[])])}function Jr(i){return i.reduce((s,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...s,e]:[...s,e,...it(e)],[])}function BP(i){const s=i.entities||[],e=[...s,...i.functions||[],...i.events||[],...i.projects||[]],t=s.reduce((l,c)=>[...l,...c.properties],[]),r=s.reduce((l,c)=>[...l,...c.methods],[]),a=r.reduce((l,c)=>[...l,...kd(c.inputs),...Jr(Yt(c.calls)),...c.returnStatements],[]),d=i.functions.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]),o=i.events.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]);return[...e,...t,...r,...a,...d,...o]}function _P(i,s){return s.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(r=>r.id===i.id)!==void 0||t.outputs.find(r=>r.id===i.id)!==void 0;case n.Condition:return t.successCalls.find(r=>r.id===i.id)!==void 0||t.errorCalls.find(r=>r.id===i.id)!==void 0||t.inputs.find(r=>r.id===i.id)!==void 0;case n.Operation:return t.outputs.find(r=>r.id===i.id)!==void 0;case n.VariableDeclaration:return nt.includes(i.type)?sO(i).find(a=>{var d;return((d=a.readsValue)==null?void 0:d.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(r=>r.id===i.id)!==void 0||t.methods.find(r=>r.id===i.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(r=>r.id===i.id)!==void 0||(t.returnStatements.map(r=>r.outputs).flat()||[]).find(r=>r.id===i.id)!==void 0;default:return!1}})}function Sq(i){const s=BP(i.project);return _P(i,s)}function ws(i,s){return i?typeof i=="string"?s[i]:i.type===n.GenericReference?s[i.entityId]:s[i.id]?s[i.id]:null:null}function Zd(i,s={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||(e.allBuiltInEntityIds||[]).includes(i.id)))return{upstream:{},downstream:{}};const t=i,r=i,a=i,d=i,o=i,l=i,c=i,f=i,y=i,v=i,E=i,P=i,V=i,C=[...V.readsValue?[V.readsValue]:[],...V.declaration?[V.declaration]:[],...(P.calledByEntry||[]).flatMap($=>$),...(P.calledBySuccess||[]).flatMap($=>$),...(P.calledByError||[]).flatMap($=>$),...(a.extends||[]).flatMap($=>$),...v.parent?[v.parent]:[]];Array.isArray(a.implements)?C.push(...a.implements.flatMap($=>$)):y.implements&&C.push(y.implements),Array.isArray(o.valueAsTypeSingle)?C.push(...o.valueAsTypeSingle.flatMap($=>$)):o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const G=[...(t.inputs||[]).flatMap($=>$),...(E.inputsDeclarations||[]).flatMap($=>$),...(t.outputs||[]).flatMap($=>$),...(E.outputsDeclarations||[]).flatMap($=>$),...(V.internalCalls||[]).flatMap($=>$),...V.writesValues||[],...P.dataType?[P.dataType]:[],...l.body?[l.body]:[],...P.defaultValue?[P.defaultValue]:[],...(P.successCalls||[]).flatMap($=>$),...(P.errorCalls||[]).flatMap($=>$),...(a.properties||[]).flatMap($=>$),...(a.methods||[]).flatMap($=>$),...(a.abstractMethods||[]).flatMap($=>$),...c.error?[c.error]:[],...c.process?[c.process]:[],...v.throws?[v.throws]:[],...(r.andChildrenGroup||[]).flatMap($=>$),...(r.orChildrenGroup||[]).flatMap($=>$),...(f.entities||[]).flatMap($=>$),...(f.functions||[]).flatMap($=>$),...(f.functionCalls||[]).flatMap($=>$),...(f.events||[]).flatMap($=>$),...(f.conditions||[]).flatMap($=>$),...(f.operations||[]).flatMap($=>$),...(f.loops||[]).flatMap($=>$),...(f.variableDeclarations||[]).flatMap($=>$),...(f.variableInstances||[]).flatMap($=>$),...(f.searches||[]).flatMap($=>$),...(f.projects||[]).flatMap($=>$),...(d.calls||[]).flatMap($=>$)];i.type===n.DataType&&(r.entity&&s[g(r.entity)]&&s[g(r.entity)].parent&&g(s[g(r.entity)].parent)===i.id?G.push(r.entity):r.entity&&C.push(r.entity));const j={},B={};return C.forEach($=>{const z=g($);if(z&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(z)))return;const X=$.version;z&&(j[z]=X)}),G.forEach($=>{const z=g($);if(z&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(z)))return;const X=$.version;z&&(B[z]=X)}),{upstream:j,downstream:B}}function $q(i,s){const e=[];if(wr.includes(i.type)){cr(i).forEach(a=>{const d=xd(a,s);d&&e.push(d)});const r=[...i.inputs||[],...i.outputs||[]].map(a=>{const d=ws(a,s);return d?dO(d,s):null}).filter(a=>a!==null);e.push(...u(r))}if(Qe.includes(i.type)){const t=Jd(i);t&&e.push(t)}return u(e)}function Bn(i){const s=[];if(wr.includes(i.type)){i.calledBy.forEach(r=>{const a=Vt(r);a&&s.push(a)});const t=[...i.inputs||[],...i.outputs||[]].map(r=>Jd(r)).filter(r=>r!==null);s.push(...u(t))}if(Qe.includes(i.type)){const e=Jd(i);e&&s.push(e)}return u(s)}function cr(i){return[...i.calledByEntry||[],...i.calledByError||[],...i.calledBySuccess||[]].filter(s=>s.type!==n.GenericReference)}function MP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[i,...i.inputs.flatMap(t=>N(t,s,e)),...i.outputs.flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.parent?N(i.parent,s,e):[]]}function NP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s):[],...i.writesValues.flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function LP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function SP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...(i.extends||[]).flatMap(t=>N(t,s,e))]}function $P(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function UP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function GP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[i,...(i.extends||[]).flatMap(t=>N(t,s,e)),...(i.implements||[]).flatMap(t=>N(t,s,e)),...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function jP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[i,...(i.andChildrenGroup||[]).flatMap(t=>N(t,s,e)),...(i.orChildrenGroup||[]).flatMap(t=>N(t,s,e)),...i.entity?N(i.entity,s,e):[],...i.parent?N(i.parent,s,e):[]]}function FP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function xP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function kP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function ZP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function qP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[i,...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function JP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.parent?N(i.parent,s,e):[]]}function WP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[i,...i.valueAsTypeSingle?Array.isArray(i.valueAsTypeSingle)?i.valueAsTypeSingle.flatMap(t=>N(t,s,e)):N(i.valueAsTypeSingle,s,e):[],...i.parent?N(i.parent,s,e):[]]}function YP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.body?N(i.body,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function zP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function HP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[i,...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function KP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e))]}function XP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[i,...(i.entities||[]).flatMap(t=>N(t,s,e)),...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.variableDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.variableInstances||[]).flatMap(t=>N(t,s,e)),...(i.operations||[]).flatMap(t=>N(t,s,e)),...(i.conditions||[]).flatMap(t=>N(t,s,e)),...(i.functionCalls||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.loops||[]).flatMap(t=>N(t,s,e)),...(i.searches||[]).flatMap(t=>N(t,s,e))]}function QP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function eO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function tO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[i,...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function rO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function iO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function nO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function aO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(cr(i)||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.parent?N(i.parent,s,e):[]]}function qd(){const i=new Set;return WE.flatMap(e=>N(e,i)).map(e=>e.id)}function N(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!i)throw new Error("Entity must be defined to be flattened");if(i.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||qd().includes(i.id)))return[];if(s.has(i.id))return[];switch(i.type){case n.FunctionCall:return FP(i,s,e);case n.Operation:return zP(i,s,e);case n.Condition:return $P(i,s,e);case n.Loop:return YP(i,s,e);case n.Search:return rO(i,s,e);case n.GlobalEvent:return kP(i,s,e);case n.ReturnStatement:return tO(i,s,e);case n.ContinueStatement:return UP(i,s,e);case n.BreakStatement:return LP(i,s,e);case n.VariableDeclaration:return nO(i,s,e);case n.DefinitionEntity:return GP(i,s,e);case n.FunctionDeclaration:return xP(i,s,e);case n.Project:return XP(i,s,e);case n.ActionDescriptor:return MP(i,s,e);case n.ArgumentDeclaration:return NP(i,s,e);case n.ReturnDeclaration:return eO(i,s,e);case n.ValueDescriptor:return iO(i,s,e);case n.InputMap:return ZP(i,s,e);case n.OutputMap:return HP(i,s,e);case n.DataType:return jP(i,s,e);case n.InstalledProject:return qP(i,s,e);case n.InternalCall:return JP(i,s,e);case n.LiteralValue:return WP(i,s,e);case n.Property:return QP(i,s,e);case n.VariableInstance:return aO(i,s,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:SP(i,s,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:KP(i,s,e)}return[]}function Lp(i){return i.type===n.FunctionCall||i.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.inputs:i.type===n.FunctionDeclaration||Sn.includes(i.type)?i.inputs:i.type===n.Search?i.inputsDeclarations:[]}function Uq(i,s){return s.type===n.Condition?s.inputs.find(e=>e.declaration.id===i.id):s.type===n.FunctionCall||s.type===n.Operation?s.inputs.find(e=>e.declaration.id===i.id):null}function sO(i){return nt.includes(i.type)?i.inputs:[]}function oO(i){var s;return i.type===n.FunctionCall?((s=i.declaration.returnStatements[0])==null?void 0:s.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.outputs:i.type===n.Search?i.outputsDeclarations:st.includes(i.type)?i.outputs:[]}function Gq(i,s){return s.type===n.Condition?null:s.type===n.FunctionCall||s.type===n.Operation?s.outputs.find(e=>e.declaration.id===i.id):null}function jq(i){return i.type===n.Condition?[]:nt.includes(i.type)?i.outputs:[]}function Jd(i){const s=i.readsValue;return s?Vt(s):null}function dO(i,s){const e=i.readsValue;return e?xd(e,s):null}function lO(i){const s=i.internalCalls||[];return u(Yt(u(s.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Ra(i){const s=Np(i),e=[];return s.forEach(t=>{if(Qe.includes(t.type))e.push(t);else if(fi.includes(t.type)){const r=t.parent;e.push(r)}}),e}function u(i){const s=new Set;return i.filter(e=>!e||s.has(e.id)?!1:(s.add(e.id),!0))}function Zi(i,s=!1){const e=[];if(i.type===n.Project&&e.push(...(i==null?void 0:i.entities)||[],...(i==null?void 0:i.functions)||[],...(i==null?void 0:i.variableDeclarations)||[],...(i==null?void 0:i.variableInstances)||[],...(i==null?void 0:i.searches)||[],...(i==null?void 0:i.loops)||[],...(i==null?void 0:i.operations)||[],...(i==null?void 0:i.conditions)||[],...(i==null?void 0:i.functionCalls)||[],...(i==null?void 0:i.events)||[],...(i==null?void 0:i.projects)||[]),mt.includes(i.type)&&e.push(...(i==null?void 0:i.detachedChildren)||[]),i.type===n.DefinitionEntity){const t=[...i.suggestedMethods,...i.methods].flatMap(r=>r.collapsed&&s?[]:Zi(r));e.push(...t)}if(i.type===n.Condition){const t=i.successCalls.map(a=>Vt(a)),r=i.errorCalls.map(a=>Vt(a));e.push(...t,...r)}if(Sn.includes(i.type)){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>Vt(a));e.push(...u(t),...r)}if(nt.includes(i.type)&&i.type!==n.Condition&&i.type!==n.Loop){const t=i==null?void 0:i.outputs.map(d=>Ra(d)).flat(),r=i.successCalls.map(d=>Vt(d)),a=i.errorCalls.map(d=>Vt(d));e.push(...u(t),...r,...a)}if(Qe.includes(i.type)){const t=Ra(i),r=lO(i);e.push(...t,...r)}if(i.type===n.Loop){const t=i.outputs.map(d=>Ra(d)).flat();if(i.body){const d=Zi(i.body,s);e.push(...d)}const r=i.errorCalls.map(d=>Vt(d)),a=i.successCalls.map(d=>Vt(d));e.push(...u(t),...a,...r)}if(i.type===n.FunctionDeclaration){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>Vt(a));e.push(...u(t),...r)}return u(e)}function uO(i,s=!1){const e=Zi(i,s),t=[...e,...e.reduce((r,a)=>[...r,...uO(a,s)],[])];return u(t)}function cO(i){const s=Bn(i),e=[...s,...s.reduce((t,r)=>[...t,...cO(r)],[])];return u(e)}function Wd(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Wd(e),...Yd(e)]:[...s,e.name],[])}function Yd(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Yd(e),...Wd(e)]:[...s,e.name],[])}function Sp(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...Sp(e),...$p(e)]:[...s,e],[])}function $p(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...$p(e),...Sp(e)]:[...s,e],[])}function Up(i){return[...Yd(i),...Wd(i)].filter((e,t,r)=>r.indexOf(e)===t)}function pO(i){return i.implements.length===0&&i.extends.length===0?null:i.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===W.PERSISTED_ENTITY)?i:[...i.implements,...i.extends].reduce((t,r)=>{if(r.type===n.DefinitionEntity){const a=pO(r);if(a)return a}return t},null)}function Fq(i){const s=i.extends.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function xq(i){const s=i.implements.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function Gp(i){const s=i.extends.find(e=>e.type===n.DefinitionEntity);return s&&s.type===n.DefinitionEntity?s:null}function qi(i){const s=[...i.implements,...i.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...qi(t)]:e,[]);return u(s)}function jp(i){return i.type===n.PrimitiveEntity?!0:i.type===n.BuiltInBaseEntity?i.interactive:!qi(i).find(t=>!t.interactive)}function kq(i){return i.parent===i.project&&i.project.variableDeclarations.includes(i)}function Fp(i){return i.parent!==i.project?!1:n.VariableDeclaration===i.type?i.project.variableDeclarations.includes(i):n.VariableInstance===i.type?i.project.variableInstances.includes(i):n.FunctionCall===i.type?i.project.functionCalls.includes(i):n.Condition===i.type?i.project.conditions.includes(i):n.Operation===i.type?i.project.operations.includes(i):n.Loop===i.type?i.project.loops.includes(i):n.Search===i.type?i.project.searches.includes(i):!1}function fO(i){if([...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||Fp(i))return!1;const s=Bn(i);return s.length===0?!0:s.some(e=>fO(e))}function xp(i){return[...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||Fp(i)?!1:Bn(i).length===0}function yO(i,s=0){if(xp(i)){const e=Bn(i);return e.length===0?i:e.map(r=>yO(r,s+1)).reduce((r,a)=>r?a&&a.x<r.x?a:r:a,null)}return null}function hO(i){const s=[];if(xp(i))s.push(i);else return[];return Bn(i).forEach(t=>{s.push(...hO(t))}),s}function mO(i){return i.type===n.FunctionDeclaration&&i.parent!==i.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(i.parent.type)}function Zq(i,s){const e=new Map;return i.forEach(t=>{e.set(t.id,t)}),s.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function Cs(i){switch(i){case n.DefinitionEntity:return Wi;case n.FunctionDeclaration:return gi;case n.VariableDeclaration:return Li;case n.VariableInstance:return Ni;case n.FunctionCall:return ki;case n.Operation:return Bi;case n.Condition:return Mi;case n.ReturnStatement:return Ci;case n.Loop:return _i;case n.Search:return Si;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.ArgumentDeclaration:return Ui;case n.ReturnDeclaration:return tr;case n.Property:return wi;case n.InstalledProject:return $i;case n.Project:return w;case n.BuiltInBaseEntity:return Wr;default:return null}}function zt(i,s){if(mt.includes(i.type))return i;if(hr.includes(i.type))return null;const e=i.parent;if(!e)return null;if(e.type===n.GenericReference){const t=g(e);if(!t)return null;const r=s.get(t);return r?zt(r,s):null}else return e===s?s:zt(e,s)}function kp(i,s){if(hr.includes(i.type)||s.getBuiltIn(i.id))return null;const e=ir(i.parent,s);return e?e===s?mt.includes(i.type)?i:null:e.type===n.DefinitionEntity?i:kp(e,s):null}function zd(i,s,e){if(i===s||s===e||i===e)return!1;const t=zt(s.parent,e);return t===i?!0:zd(t,s,e)}var Hd=(i=>(i.SameBothLocal="same-both-local",i.AInB="a-in-b",i.BInA="b-in-a",i.ParallelInCommonParent="parallel-in-common-parent",i.ParallelInProject="parallel-in-project",i.AIsGlobalBIsNot="a-is-global-b-is-not",i.BIsGlobalAIsNot="b-is-global-a-is-not",i.SameBothGlobal="same-both-global",i))(Hd||{});function gs(i,s,e){const t=zt(i,e),r=zt(s,e);if(!t)throw new Error("Could not find scope owner for the entity: "+i.id);if(!r)throw new Error("Could not find scope owner for the entity: "+s.id);if(t===r&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===r&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&r.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&r.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:r};if(zd(t,r,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(zd(r,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:r};const o=_p(t,r);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 vO(i,s,e){const t=gs(i,s,e);if(!t.compatible||t.type!=="same-both-local")return null;if(i===s)return i;let r=zt(i.parent,e);if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;for(;r;){if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;r=zt(r.parent,e)}let a=zt(s.parent,e);if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;for(;a;){if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;a=zt(a.parent,e)}return null}function TO(i){return i.length===0?null:i.length===1?i[0]:i.reduce((e,t)=>{const r=vO(e,t,t.project);return!r||r===t?e:t},i[0])}function ir(i,s){if(!i)return null;let e;return typeof i=="string"?e=i:i.type===n.GenericReference?e=g(i):e=i.id,e===s.id?s:s.get(e)}function Ji(i){if(!i)return null;if(hr.includes(i.type))return i;if(i.type===n.Project)return null;if(i.project.getBuiltIn(i.id))return i;const s=i.parent;return!s||s.type===n.Project?null:Ji(s)}function qq(i,s){var e;if(i.readsValue){const t=ir(i.readsValue,s.project);s.setValueWriter(t),t.addValueReader(s)}else i.readsValue===null&&((e=s.readsValue)==null||e.removeValueReader(s),s.readsValue=null);return s}function Bs(i){const s=[];function e(a,d){return s.some(o=>o.blockedByCaller===a&&o.blockedByCalling===d)}function t(a,d){e(a,d)||s.push({blockedByCaller:a,blockedByCalling:d})}const r=kp(i,i.project);return i.calledBySuccess.forEach(a=>{[...a.successCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(y=>y===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=Bs(o);l.reachable||it(i).find(y=>y===a)||l.blocks.forEach(y=>{t(a,y.blockedByCalling)})}}),i.calledByError.forEach(a=>{[...a.errorCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(y=>y===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=Bs(o);l.reachable||it(i).find(y=>y===a)||l.blocks.forEach(y=>{t(a,y.blockedByCalling)})}}),i.calledByEntry.forEach(a=>{if([...a.calls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(y=>y===l)||t(a,l))}),a===r)return;let o;if(a.type===n.FunctionDeclaration){const l=Vt(a);if(l.type===n.DefinitionEntity)return;l.type===n.Loop&&(o=l)}if(o){const l=Bs(o);l.reachable||l.blocks.forEach(c=>{t(a,c.blockedByCalling)})}}),{reachable:s.length===0,entryPoint:r,blocks:s}}function Jq(i){return $s.includes(i.type)?i.type===n.FunctionDeclaration?!mO(i):!0:!1}function Wq(i){if(n.ActionDescriptor===i.type){if(i.project.operationDeclarations.find(a=>a.id===i.id))return n.Operation;if(i.project.globalEventActionDescriptors.find(a=>a.id===i.id))return n.GlobalEvent;if(i.project.loopDeclarations.find(a=>a.id===i.id))return n.Loop;if(i.project.conditionDeclarations.find(a=>a.id===i.id))return n.Condition}return i.type}function ba(i,s){if(i.type!==n.DefinitionEntity||i.abstract)return!1;const e=Gp(i)||i;return!!Up(e).includes(s)}function Yq(i){const s=[];return i.entities.forEach(e=>{if(ba(e,W.PERSISTED_ENTITY)){s.push(e);return}}),u(s)}function zq(i){const s=[];return i.entities.forEach(e=>{if(ba(e,W.RELATIONAL_DATABASE)){s.push(e);return}}),u(s)}function Hq(i){return i.type!==n.DefinitionEntity||i.abstract||!ba(i,W.PERSISTED_ENTITY)?null:(i==null?void 0:i.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===F[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function Kq(i){if(i.type!==n.DefinitionEntity)return[];if(i.abstract)return[];if(!ba(i,W.PERSISTED_ENTITY))return[];const s=[],e=i.properties.filter(t=>{var r;return((r=t.implements)==null?void 0:r.id)!==F[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return s.push(...e),s}function Xq(i){var e;if(!i||i.type!==n.DefinitionEntity||!ba(i,W.PERSISTED_ENTITY))return null;const s=i.properties.find(t=>{var r;return((r=t.implements)==null?void 0:r.id)===F[n.BuiltInBaseEntity][W.PERSISTED_ENTITY].properties.database.id});return(e=s==null?void 0:s.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function ft(i,s){var t;if(!Kp.includes(s.type)||!i)return s.project||null;let e=s.project;return i.type===n.Project?e=i:((t=s.project)==null?void 0:t.id)!==i.project.id&&(e=i.project),e}function Qq(i){switch(i){case n.Project:return w;case n.InstalledProject:return $i;case n.DefinitionEntity:return Wi;case n.FunctionDeclaration:return gi;case n.GlobalEvent:return Vn;case n.VariableInstance:return Ni;case n.VariableDeclaration:return Li;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.Condition:return Mi;case n.Operation:return Bi;case n.FunctionCall:return ki;case n.ReturnDeclaration:return tr;case n.ArgumentDeclaration:return Ui;case n.PrimitiveEntity:return pr;case n.DataType:return On;case n.Property:return wi;case n.ActionDescriptor:return Ze;case n.ReturnStatement:return Ci;case n.ContinueStatement:return Ut;case n.BreakStatement:return wn;case n.Loop:return _i;case n.Search:return Si;case n.ValueDescriptor:return Gi;case n.InternalCall:return Cn;case n.LiteralValue:return gn}return null}function eJ(i){const s={added:{},updated:{},removed:new Set,affected:new Set,seenEntities:[],self:i==null?void 0:i.self};return i==null||i.added.forEach(e=>{s.added[e.id]=e}),i==null||i.updated.forEach(e=>{s.updated[e.id]=e}),s.removed=new Set(i==null?void 0:i.removed.map(e=>e.id)),s}function dt(i,s){const e=Cs(i.type);return e?!e.MUTABLE_META_PROPERTIES.every(r=>{const a=i[r],d=s[r];return d===void 0||a===d?!0:Array.isArray(a)&&Array.isArray(d)?a.length!==d.length?!1:a.every((o,l)=>o===d[l]):!1}):!1}function tJ(i,s){const e=[];if(i.parent)if(i.id===i.parent)e.push(new D({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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=s.get(i.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new D({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new D({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return i.implements&&Array.isArray(i.implements)?i.implements.forEach(t=>{if(i.id===t){e.push(new D({id:`${i.id}--${t}--${I.SelfReference}`,code:I.SelfReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract||e.push(new D({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new D({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${S.InvalidObjectStructure}`,code:S.InvalidObjectStructure,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' property that isn't an array.`,issue:null})),i.extends&&Array.isArray(i.extends)&&i.extends.forEach(t=>{const r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract&&e.push(new D({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 D({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:R.Error,message:`Entity of type "${i.type}" with id "${i.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 EO=(i=>(i.Extends="extends",i.Implements="implements",i))(EO||{});const Ne=class Ne extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"x");p(this,"y");p(this,"static");p(this,"abstract");p(this,"type",n.DefinitionEntity);p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"implements",[]);p(this,"project");p(this,"errors",[]);p(this,"parent");p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(this,"suggestedProperties",[]);p(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 fromGenerationTarget(e,t){let r=t;if(e.parent){const c=g(e.parent);r=t.get(c)}const a=[];e.implements&&e.implements.forEach(c=>{a.push(t.get(c)||t.getBuiltIn(c))});const d=[];e.extends&&e.extends.forEach(c=>{d.push(t.get(c)||t.getBuiltIn(c))});const o={id:e.id,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:d,implements:a,x:0,y:0,parent:r},l=O(o,t);return l.setParent(r,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=tJ(r,t),o=Cd(r,t);a.push(...d,...o,...ot(r));const l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DataType){const c=l;c.entity&&a.push(new D({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:R.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${c.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
  ${qr({describe_entity:c.entity.id})}
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:a,modifiedData:r}}get allBasePropertiesFromExtendedAndImplementedEntities(){return u([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[])])}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[]),...this.implements.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])].filter(e=>!!e.abstract))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{hr.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{hr.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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return(r=this.knownVersions)==null||r.set(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=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(c,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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.extends.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addExtension(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),this.initialData.implements.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addImplementation(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c,affected:f}=this.syncImplementationProperties(e);t.push(...o),r.push(...l),a.push(...c),d.push(...f);const{updated:y,added:v,removed:E,affected:P}=this.addExtendedProperties(e);return t.push(...y),r.push(...v),a.push(...E),d.push(...P),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.methods=this.initialData.methods.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.extends=this.initialData.extends.map(t=>O(t,this.project)),this.implements=this.initialData.implements.map(t=>O(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}syncImplementationProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.implementedPropertiesFromOriginalParents,c=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return l.filter(y=>!c.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===y.id})).forEach(y=>{if(this.properties.find(V=>{var C;return((C=V.implements)==null?void 0:C.id)===y.id}))return;const E=this.properties.find(V=>V.name===y.name&&!!V.abstract&&!V.implements);if(E){E.implements=y,E.abstract=!1;return}const P=y.clone(this,w.UUID.uuid());P.initChildren(e),r.push(P),e==null||e.add(P,b.Added),P.setImplements(y,e),P.metaSync({abstract:!1},e),this.addProperty(P)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addExtendedProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.extendedPropertiesFromOriginalParents,c=l.filter(y=>l.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===y.id})?!1:!y.abstract),f=new Set(o.map(y=>y.name));return c.forEach(y=>{if(f.has(y.name))return;f.add(y.name);const v=y.clone(this,w.UUID.uuid());v.initChildren(e),r.push(v),e==null||e.add(v,b.Added),this.addProperty(v)}),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSuggestions(){return this.implements.forEach(e=>{g5(this,e).forEach(a=>{const d=a.toJSON();d.id=`_suggestion--parent--${this.id}--${a.id}`;const o=O(d,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),B5(this,e).forEach(a=>{const d=`_suggestion--parent--${this.id}--${a.id}`,o=a.implementAsFunctionDeclaration(d),l=O(o,this.project);if(l.suggestion=!0,l.setParent(this,null),l.initChildren(null),l.inputs.forEach(c=>{c.suggestion=!0}),l.returnStatements.length){const c=l.returnStatements[0];c.suggestion=!0,c.outputs.forEach(f=>{f.suggestion=!0})}this.addSuggestedMethod(l)})}),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.x=e.x||this.x,this.y=e.y||this.y,this.static=e.static||this.static,this.abstract=e.abstract||this.abstract,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ne.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ne.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.properties.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.methods.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.abstractMethods.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.suggestedProperties.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.suggestedMethods.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const l=this.parent.setEntity(null);r.push(l)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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:l}=o.restore({},e);r.push(...l)}),this.methods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.abstractMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedProperties.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(r=>r.toFlat(e)),...this.implements.flatMap(r=>r.toFlat(e)),...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(r=>r.toFlatIds(e)),...this.implements.flatMap(r=>r.toFlatIds(e)),...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.parent.toFlatIds(e)])}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=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",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(c=>c.toJSONClone({...e,newId:null})),methods:this.methods.map(c=>c.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(c=>c.toJSONClone({...e,newId:null})),implements:this.implements.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),extends:this.extends.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),methods:this.methods.map(a=>a.toReference(e)),abstractMethods:this.abstractMethods.map(a=>a.toReference(e)),implements:this.implements.map(a=>a.toReference(e)),extends:this.extends.map(a=>a.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(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e)),...this.implements.flatMap(r=>r.toFlatJSON(e)),...this.extends.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.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=C5(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=null,t=null,r=!0){var P,V,C;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.properties=[],d.methods=[],d.abstractMethods=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e&&f.setParent(e,null),r&&f.subscribe(),f.initChildren(null);const y=(P=this.properties)==null?void 0:P.map(G=>G.clone(f,w.UUID.uuid(),r));f.properties=y;const v=(V=this.methods)==null?void 0:V.map((G,j)=>G.clone(f,c+"-method-"+j+"-id",r));f.methods=v;const E=(C=this.abstractMethods)==null?void 0:C.map((G,j)=>G.clone(f,c+"-abstract-method-"+j+"-id",r));return f.abstractMethods=E,f}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"implement-definition-entity")),r){const a=Gd(this,e,t,r);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),a}getAllInteractiveMethods(){const e=this.implements.filter(r=>r.type===n.DefinitionEntity||r.type===n.BuiltInBaseEntity&&r.interactive);return u([...this.methods,...this.extends.flatMap(r=>r.getAllInteractiveMethods()),...e.flatMap(r=>r.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const r=[],a=[],d=[],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 l=[];e.forEach(y=>{l.find(E=>U(E,this.project)===U(y,this.project))||l.push(y)});const c=this.properties.filter(y=>!y.getDataType());l.forEach(y=>{const v=c.find(G=>U(G,this.project)===U(y,this.project));if(!v)return;const P=Pn(y.parent).getMasterInputWithValueWritterFromAllInstances(y),V=xr(P),C=V==null?void 0:V.clone(v,w.UUID.uuid(),!0);C&&v.setDataType(C),y.setDeclaration(v)});const f=[];return l.forEach(y=>{if(!y.declaration){f.push(y);return}}),f.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(f.forEach(y=>{const v=this.properties.find(B=>U(B,this.project)===U(y,this.project));if(v){if(y.setDeclaration(v),!v.getDataType()){const $=Pn(y.parent).getMasterInputWithValueWritterFromAllInstances(y),z=xr($),X=z==null?void 0:z.clone(v,w.UUID.uuid(),!0);X&&v.setDataType(X)}return}const E={id:w.UUID.uuid(),type:n.Property,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:U(y,this.project),description:y.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:y.index,implements:null,dataType:null,parent:this.toReference()},P=O(E,this.project);P.setParent(this,t),P.initChildren(t),t==null||t.add(P,b.Added),t==null||t.add(this,b.Affected);const C=Pn(y.parent).getMasterInputWithValueWritterFromAllInstances(y),G=xr(C),j=G==null?void 0:G.clone(P,w.UUID.uuid(),!0);return j&&(t==null||t.add(j,b.Added),P.setDataType(j)),this.addProperty(P),y.setDeclaration(P),P}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:u(r),updated:u(a),removed:u(d),affected:u(o),self:this})}};p(Ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ne,"type",n.DefinitionEntity),p(Ne,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),p(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),p(Ne,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),p(Ne,"INMUTABLE_BASE_PROPERTIES",["id","version","type"]),p(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),p(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),p(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),p(Ne,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),p(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),p(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Wi=Ne;function rJ(i){const s=o6(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Ms=class Ms extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"version");p(this,"name");p(this,"description",null);p(this,"type",n.BuiltInBaseEntity);p(this,"abstract",!1);p(this,"static");p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"interactive",!1);p(this,"errors",[]);p(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(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.extends=this.initialData.extends.map(r=>O(r,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...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=L,...t){return await Ms.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.extends.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.extends.flatMap(r=>r.toFlatIds(e))])}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=k){return{id:this.id+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=k){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(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.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=rJ(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,"",T().toISOString(),null,!0,"implement-built-in-base-entity")),r){const a=Gd(this,e,t,r);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),a}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Ms&&e.push(...r.getAllInteractiveMethods())})),u(e)}};p(Ms,"repository",{APILoad:async(e,...t)=>null});let Wr=Ms;function iJ(i){const s=X9(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Xd=class Xd extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"type",n.PrimitiveEntity);p(this,"static");p(this,"abstract");p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"errors",[]);p(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(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=O(r,this.project);return a.parent=this,a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=O(r,this.project);return a.parent=this,a})}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...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=L,...t){return await Xd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e))])}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=k){return{id:this.id+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=k){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(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.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=iJ(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(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Wr&&e.push(...r.getAllInteractiveMethods())}),u(e)}};p(Xd,"repository",{APILoad:async(e,...t)=>null});let pr=Xd;function lt(i,s){if(!i)throw new Error("Entity is null");const e=s.get(i.id);switch(i.type){case n.LiteralValue:return e||new gn(i,s);case n.DefinitionEntity:return e||new Wi(i,s);case n.PrimitiveEntity:return e||new pr(i,s);case n.FunctionDeclaration:return e||new gi(i,s);case n.GlobalEvent:return e||new Vn(i,s);case n.DataType:return e||new On(i,s);case n.Property:return e||new wi(i,s);case n.FunctionCall:return e||new ki(i,s);case n.Condition:return e||new Mi(i,s);case n.Operation:return e||new Bi(i,s);case n.VariableDeclaration:return e||new Li(i,s);case n.VariableInstance:return e||new Ni(i,s);case n.OutputMap:return e||new Zr(i,s);case n.ReturnDeclaration:return e||new tr(i,s);case n.ArgumentDeclaration:return e||new Ui(i,s);case n.InputMap:return e||new kr(i,s);case n.Project:return e||new w(i);case n.InstalledProject:return e||new $i(i,s);case n.ActionDescriptor:return e||new Ze(i,s);case n.ReturnStatement:return e||new Ci(i,s);case n.Loop:return e||new _i(i,s);case n.Search:return e||new Si(i,s);case n.ValueDescriptor:return e||new Gi(i,s);case n.BuiltInBaseEntity:return e||new Wr(i,s);case n.InternalCall:return e||new Cn(i,s);case n.ContinueStatement:return e||new Ut(i,s);case n.BreakStatement:return e||new wn(i,s);case n.GenericReference:return s.get(i.entityId);default:throw new Error("Invalid entity type: "+i.type)}}function O(i,s){if(!i)throw new Error("Entity is null");const e=lt(i,s);return e.subscribe(),e}function nJ(i,s){if(!i)throw new Error("Entity is null");switch(i.type){case n.LiteralValue:return gn.fromGenerationTarget(i,s);case n.DefinitionEntity:return Wi.fromGenerationTarget(i,s);case n.FunctionDeclaration:return gi.fromGenerationTarget(i,s);case n.GlobalEvent:return Vn.fromGenerationTarget(i,s);case n.DataType:return On.fromGenerationTarget(i,s);case n.Property:return wi.fromGenerationTarget(i,s);case n.FunctionCall:return ki.fromGenerationTarget(i,s);case n.Condition:return Mi.fromGenerationTarget(i,s);case n.Operation:return Bi.fromGenerationTarget(i,s);case n.VariableDeclaration:return Li.fromGenerationTarget(i,s);case n.VariableInstance:return Ni.fromGenerationTarget(i,s);case n.OutputMap:return Zr.fromGenerationTarget(i,s);case n.ReturnDeclaration:return tr.fromGenerationTarget(i,s);case n.ArgumentDeclaration:return Ui.fromGenerationTarget(i,s);case n.InputMap:return kr.fromGenerationTarget(i,s);case n.InstalledProject:return $i.fromGenerationTarget(i,s);case n.ReturnStatement:return Ci.fromGenerationTarget(i,s);case n.Loop:return _i.fromGenerationTarget(i,s);case n.Search:return Si.fromGenerationTarget(i,s);case n.ActionDescriptor:return Ze.fromGenerationTarget(i,s);case n.ValueDescriptor:return Gi.fromGenerationTarget(i,s);case n.InternalCall:return Cn.fromGenerationTarget(i,s);case n.ContinueStatement:return Ut.fromGenerationTarget(i,s);case n.BreakStatement:return wn.fromGenerationTarget(i,s);default:throw new Error("Invalid entity type: "+i.type)}}const k={seenEntityMaps:new Map,seenEntities:new Set};class IO{constructor(){p(this,"initialData")}}const L={cascade:!1},RO={APILoad:async(i,...s)=>null},aJ={APICreate:async(i,...s)=>i,APIUpdate:async(i,...s)=>i,APIDelete:async(i,...s)=>{},APIClone:async(i,...s)=>{},APILoadVersion:async(i,s,...e)=>null,...RO};class sJ{}class oJ extends IO{}class dJ{}class lJ{}class uJ{}class Zp{}class cJ extends Zp{}class pJ extends Zp{}class fJ{}class pi{static initReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=O(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=ir(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),s.readsValue.initChildren(null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}static hydrateReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=O(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=ir(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}}class _s{static initWritesValues(s,e){const t=s.initialData.writesValues.reduce((a,d)=>{if(d.type===n.GenericReference||s.writesValues.some(l=>l.id===d.id))return a;const o=O(d,s.project);return o.setValueWriter(s),Qe.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...a,o]},[]),r=[...s.writesValues];return s.writesValues=u([...r,...t]),s.writesValues}}class yJ{}const se=class se extends rt{constructor(e){super(e);p(this,"initialData");p(this,"id");p(this,"type",n.Project);p(this,"name",null);p(this,"description",null);p(this,"x");p(this,"y");p(this,"entities",[]);p(this,"projects",[]);p(this,"functions",[]);p(this,"events",[]);p(this,"variableDeclarations",[]);p(this,"variableInstances",[]);p(this,"conditions",[]);p(this,"operations",[]);p(this,"functionCalls",[]);p(this,"loops",[]);p(this,"searches",[]);p(this,"primitives",[]);p(this,"builtInBaseEntities",[]);p(this,"operationDeclarations",[]);p(this,"globalEventActionDescriptors",[]);p(this,"loopDeclarations",[]);p(this,"loopDeclarationsBodies",[]);p(this,"conditionDeclarations",[]);p(this,"valueDescriptors",[]);p(this,"dataTypes",[]);p(this,"project");p(this,"instances",{});p(this,"builtInInstances",{});p(this,"deletedInstances",{});p(this,"errors",[]);p(this,"references",[]);p(this,"history",[]);p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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{(!se.UUID||se.UUID.isBackup)&&(se.UUID=No==null?void 0:No()),se.UUID||(se.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),se.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:r=>r}}}static injectUUIDModule(e){se.UUID=e}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}onCloseChangeSet(e){this.onCloseChangeSetCallback=e}closeChangeSet(e){this.onCloseChangeSetCallback&&this.onCloseChangeSetCallback(e)}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(a=>a.id===(e==null?void 0:e.id));if(t)return t;const r=this.history.findIndex(a=>T(a.timestamp).isBefore(T(e==null?void 0:e.timestamp)));return r===-1?this.history.push(e):this.history.splice(r,0,e),e}discardChangeSet(e){const t=this.history.findIndex(r=>r.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}redo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async r=>{await t.init(this),r(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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=se.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new se(this);return(r=this.knownVersions)==null||r.set(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=[],r=[],a=[],d=[];return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new se(c)}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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=null){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e){const t=[],r=[],a=[],d=[];return this.subscribeToDependencies(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.projects=this.initialData.projects.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableInstances=this.initialData.variableInstances.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.conditions=this.initialData.conditions.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.operations=this.initialData.operations.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functions=this.initialData.functions.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functionCalls=this.initialData.functionCalls.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.loops=this.initialData.loops.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.searches=this.initialData.searches.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),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}getManaged(e){return 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,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await se.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await se.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await se.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",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(r=>r.toFlat(e)),...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e)),...this.projects.flatMap(r=>r.toFlat(e)),...this.variableDeclarations.flatMap(r=>r.toFlat(e)),...this.variableInstances.flatMap(r=>r.toFlat(e)),...this.conditions.flatMap(r=>r.toFlat(e)),...this.operations.flatMap(r=>r.toFlat(e)),...this.functionCalls.flatMap(r=>r.toFlat(e)),...this.loops.flatMap(r=>r.toFlat(e)),...this.searches.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),Array.from(e))}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,r=new Set,a=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(d=>{if(a.includes(d)){t.set(d,d);return}t.set(d,se.UUID.uuid())}),r.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(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),projects:this.projects.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableDeclarations:this.variableDeclarations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableInstances:this.variableInstances.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),conditions:this.conditions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),operations:this.operations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functions:this.functions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),events:this.events.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functionCalls:this.functionCalls.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),loops:this.loops.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),searches:this.searches.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null}))}}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+se.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),projects:this.projects.map(a=>a.toReference(e)),variableDeclarations:this.variableDeclarations.map(a=>a.toReference(e)),variableInstances:this.variableInstances.map(a=>a.toReference(e)),conditions:this.conditions.map(a=>a.toReference(e)),operations:this.operations.map(a=>a.toReference(e)),functionCalls:this.functionCalls.map(a=>a.toReference(e)),loops:this.loops.map(a=>a.toReference(e)),searches:this.searches.map(a=>a.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(r=>r.toFlatJSON(e)),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e)),...this.projects.flatMap(r=>r.toFlatJSON(e)),...this.variableDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.variableInstances.flatMap(r=>r.toFlatJSON(e)),...this.conditions.flatMap(r=>r.toFlatJSON(e)),...this.operations.flatMap(r=>r.toFlatJSON(e)),...this.functionCalls.flatMap(r=>r.toFlatJSON(e)),...this.loops.flatMap(r=>r.toFlatJSON(e)),...this.searches.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e)),...this.projects.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(r=>r.toFlatGenerationTarget(e)),...this.conditions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.operations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.loops.flatMap(r=>r.toFlatGenerationTarget(e)),...this.searches.flatMap(r=>r.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=A5(),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=O(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=O(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=O(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=O(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=O(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=O(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=O(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=O(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=O(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=O(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=O(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(r=>r.id===e.id);if(t>-1){const r=this.entities[t];return this.entities.splice(t,1),r}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(r=>r.id===e.id);if(t>-1){const r=this.functions[t];return this.functions.splice(t,1),r}return null}removeExternalProject(e){const t=this.projects.findIndex(r=>r.id===e.id);if(t>-1){const r=this.projects[t];return this.projects.splice(t,1),r}return null}removeGlobalEvent(e){const t=this.events.findIndex(r=>r.id===e.id);if(t>-1){const r=this.events[t];return this.events.splice(t,1),r}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(r=>r.id===e.id);if(t>-1){const r=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),r}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.functionCalls.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.conditions.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.operations.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.loops.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.searches.reduce((t,r)=>{const a=We(r);return[...t,...a]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[])]}getVariableDeclarations(){return u([...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[])])}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(r=>{if(!r.declaration){const a=r.initialData,d=a.declaration.entityId||a.declaration.id,o=t.find(l=>l.id===d);o&&r.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===W.PERSISTED_ENTITY)||null}};p(se,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),p(se,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(se,"type",n.Project),p(se,"USER_MANAGED_PARENT_TYPES",[]),p(se,"PARENT_TYPES",[...se.USER_MANAGED_PARENT_TYPES]),p(se,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(se,"INMUTABLE_BASE_PROPERTIES",["id","type","version"]),p(se,"BASE_PROPERTIES",[...se.MUTABLE_BASE_PROPERTIES,...se.INMUTABLE_BASE_PROPERTIES]),p(se,"MUTABLE_META_PROPERTIES",[...se.MUTABLE_BASE_PROPERTIES,"x","y"]),p(se,"INMUTABLE_META_PROPERTIES",[...se.INMUTABLE_BASE_PROPERTIES]),p(se,"META_PROPERTIES",[...se.MUTABLE_META_PROPERTIES,...se.INMUTABLE_META_PROPERTIES]),p(se,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(se,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),p(se,"UPSTREAM_PROPERTIES",[...se.MUTABLE_UPSTREAM_PROPERTIES,...se.INMUTABLE_UPSTREAM_PROPERTIES]),p(se,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),p(se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(se,"DOWNSTREAM_PROPERTIES",[...se.MUTABLE_DOWNSTREAM_PROPERTIES,...se.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(se,"PROPERTIES",[...se.META_PROPERTIES,...se.UPSTREAM_PROPERTIES,...se.DOWNSTREAM_PROPERTIES]);let w=se;var bO=(i=>(i.PersistChangeSet="persist-change-set",i.CreateSingle="create-single",i.CreateBulk="create-bulk",i.CreateSingleNested="create-single-nested",i.CreateBulkNested="create-bulk-nested",i.Update="update",i.Clone="clone",i.Delete="delete",i.Load="load",i.LoadNested="load-nested",i.LoadVersion="load-version",i))(bO||{});class AO extends Ze{constructor(e){super(br,e);p(this,"id",He.Parallel);p(this,"name",He.Parallel);p(this,"description","Execute a list of actions one after the other");p(this,"version","1");p(this,"autoexecutable",!0);p(this,"initialData",br);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"project");this.project=e,this.inputs=br.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=br.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=br.error?O(br.error,this.project):null}}class DO extends Ze{constructor(e){super(jt,e);p(this,"id",jt.id);p(this,"name",jt.name);p(this,"description",jt.description);p(this,"version",jt.version);p(this,"autoexecutable",!1);p(this,"initialData",jt);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"project");this.project=e,this.inputs=jt.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=jt.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=jt.error?O(jt.error,this.project):null}}class PO extends Ze{constructor(e){super(Qr,e);p(this,"id",He.Sequential);p(this,"name",He.Sequential);p(this,"description","Execute a list of actions one after the other");p(this,"version","1");p(this,"autoexecutable",!0);p(this,"initialData",Qr);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"project");this.project=e,this.inputs=Qr.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=Qr.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=Qr.error?O(Qr.error,this.project):null}}class hJ extends Ze{constructor(s){super(Oa,s)}}class mJ extends Ze{constructor(s){super(Ki,s)}}class vJ extends Ze{constructor(e){super(Xi,e);p(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e){let t=null;if(e.readsValue){const a=e.readsValue.getDataType();a&&a.entity&&a.entity.type===n.DefinitionEntity&&(t=a.entity)}const r=e.getDefaultValue();return!t&&r&&r.valueAsTypeSingle&&!Array.isArray(r.valueAsTypeSingle)&&r.valueAsTypeSingle.type===n.DefinitionEntity&&(t=r.valueAsTypeSingle),t}syncOperationInstance(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const r=[],a=[],d=[],o=[],l=this.getEntityToMatchInputMap(e);if(l){const{added:y,updated:v,removed:E,affected:P}=this.syncEntityToMatchInputMapDataType(l,t);r.push(...v),a.push(...y),d.push(...E),o.push(...P)}const c=this.getDataToValidateInputMap(e);if(c){const{added:y,updated:v,removed:E,affected:P}=this.syncDataToValidateInputMapDataType(c,t);r.push(...v),a.push(...y),d.push(...E),o.push(...P)}const f=this.getOutputDataOutputMap(e);if(f){const{added:y,updated:v,removed:E,affected:P}=this.syncOutputDataOutputMapDataType(f,t);r.push(...v),a.push(...y),d.push(...E),o.push(...P)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var c,f,y;const r=[],a=[],d=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==F.operation[Ke.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 v={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=O(v,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,b.Added),r.push(E),e.setDataType(E)}(f=e.dataType)==null||f.metaSync({inferred:!0,like:!1,asType:!0},t);const l=this.getEntityToMatch(e);return(y=e.dataType)==null||y.setEntity(l),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var y,v,E;const r=[],a=[],d=[],o=[];if(((y=e.declaration)==null?void 0:y.id)!==F.operation[Ke.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 l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l))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 P={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},V=O(P,e.project);V.setParent(e,t),V.initChildren(t),t==null||t.add(V,b.Added),r.push(V),e.setDataType(V)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(l);return(E=e.dataType)==null||E.setEntity(f),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var y,v,E;const r=[],a=[],d=[],o=[];if(((y=e.declaration)==null?void 0:y.id)!==F.operation[Ke.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 l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const P={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},V=O(P,e.project);V.setParent(e,t),V.initChildren(t),t==null||t.add(V,b.Added),r.push(V),e.setDataType(V)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(l);return(E=e.dataType)==null||E.setEntity(f),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var r,a;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id){const{added:d,updated:o,removed:l,affected:c}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}else if(((a=e.declaration)==null?void 0:a.id)===F.operation[Ke.Validate].inputs.dataToValidate.id){const{added:d,updated:o,removed:l,affected:c}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var r;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id){const{added:a,updated:d,removed:o,affected:l}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:u(d),added:u(a),removed:u(o),affected:u(l),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class TJ extends Ze{constructor(s){super(ll,s)}}class EJ extends Ze{constructor(s){super(cl,s)}}class IJ extends Ze{constructor(s){super(pl,s)}}class RJ extends Ze{constructor(s){super(xs,s)}}class bJ extends Ze{constructor(s){super(Gs,s)}}class AJ extends Ze{constructor(s){super(Pa,s)}}function DJ(i){const s=[new PO(i),new AO(i),new DO(i),new hJ(i),new mJ(i),new vJ(i),new RJ(i),new TJ(i),new IJ(i),new EJ(i),new bJ(i),new AJ(i),new Ze(dl,i),new Ze(ol,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}class OO extends Wr{constructor(e){super(Pt,e);p(this,"initialData");p(this,"id",W.PERSISTED_ENTITY);p(this,"version","1");p(this,"name",W.PERSISTED_ENTITY);p(this,"description",Pt.description);p(this,"type",n.BuiltInBaseEntity);p(this,"abstract",Pt.abstract);p(this,"static",Pt.static);p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"errors",[]);p(this,"project");this.initialData=Pt,this.project=e,this.id=Pt.id,this.version=Pt.version,this.name=Pt.name,this.static=Pt.static,this.abstract=Pt.abstract,this.properties=this.initialData.properties.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.methods=this.initialData.methods.map(t=>{const r=O(t,this.project);return r.parent=this,r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=O(t,this.project);return r.parent=this,r}),this.extends=this.initialData.extends.map(t=>O(t,this.project))}}function PJ(i){const s=[new OO(i),new Wr(_a,i),new Wr(Mr,i),new Wr(ao,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.builtInBaseEntities=s,s}function OJ(i){const s=[new pr(ie,i),new pr(zr,i),new pr(he,i),new pr(At,i),new pr(Hr,i),new pr(gr,i),new pr(Kr,i),new pr($n,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.primitives=s,s}function VJ(i){const s=[new Ze(oo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.globalEventActionDescriptors=s,s}function wJ(i){const s=[new Ze(ga,i),new Ze(yi,i),new Ze(wa,i),new Ze(jn,i),new Ze(Fn,i),new Ze(Hs,i)];s.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarations=s;const e=[new Ze(eo,i),new Ze(Ca,i),new Ze(Xs,i),new Ze(Pl,i),new Ze(Vl,i),new Ze(Ks,i)];return e.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarationsBodies=e,s}function CJ(i){const s=[new Gi(lo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.valueDescriptors=s,s}function gJ(i){const s=[new Ze(nn,i),new Ze(Jn,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}const _n={},Kd={};async function BJ(i,s={}){const e={...xA};return e.id=i.id,s.empty?{data:{id:i.id,type:n.Project,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]}}:{data:e}}function qp(i){const s=new w(i);return OJ(s),PJ(s),DJ(s),VJ(s),wJ(s),CJ(s),gJ(s),s.getAllBuiltIn().forEach(t=>{s.builtInInstances[t.id]||(s.builtInInstances[t.id]=t,delete s.instances[t.id])}),s}function _J(i){const s=new Map,e=i.getAllBuiltInIds();Object.keys(i.instances).forEach(a=>{if(e.includes(a)){s.set(a,a);return}s.set(a,w.UUID.uuid())});const t=qp(i.toShallowJSON({seenEntityMaps:s})),r=t.addChangeSet(new A(t,"",T().toISOString(),t));return new Cp(i).visit(a=>{const d=O(a.toShallowJSON({seenEntityMaps:s}),t);d.hydrateAncestors(),d.addSelfToProject(r)}).visit(a=>{const d=t.get(s.get(a.id));d&&d.afterAllChildrenInitialized(r)}),t.afterAllChildrenInitialized(r),r.close(),t}function VO(i){const s=qp(i),e=s.addChangeSet(new A(s,"",T().toISOString(),s));return e.type=yp.Automatic,new Cp(i).visit(t=>{const r=O(t,s);r.hydrateAncestors(),r.addSelfToProject(e)}).visit(t=>{const r=s.get(t.id);r&&r.afterAllChildrenInitialized(e)}),s.afterAllChildrenInitialized(e),e.close(),s}async function MJ(i,s={}){if(i.id&&_n[i.id])return _n[i.id];if(i.id&&Kd[i.id])return await Kd[i.id],_n[i.id];const e=BJ(i,s);i.id&&(Kd[i.id]=e);const t=await e;if(t.data){const r=VO(t.data);return _n[i.id]=r,i.id&&delete Kd[i.id],r}return null}function NJ(i){return _n[i.id]&&delete _n[i.id],null}const LJ="test_primitive_entities_export";h.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Pp,h.ALL_BUILT_IN_BASE_ENTITIES=VE,h.ALL_BUILT_IN_CONDITION_ENTITIES=FE,h.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=kE,h.ALL_BUILT_IN_LOOP_BODY_ENTITIES=iT,h.ALL_BUILT_IN_LOOP_ENTITIES=rT,h.ALL_BUILT_IN_OPERATION_ENTITIES=y0,h.ALL_BUILT_IN_PRIMITIVE_ENTITIES=af,h.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=WE,h.ALL_BUILT_IN_VALUE_DESCRIPTORS=JE,h.ActionDescriptorState=Ze,h.ActionInputMapState=sq,h.ActionOutputMapState=lq,h.AppendToListOperationInputIds=fh,h.AppendToListOperationOutputIds=yh,h.ArgumentDeclarationDependencyField=Q1,h.ArgumentDeclarationState=Ui,h.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Rp,h.BUILT_IN_BASE_ENTITY_IDS=F,h.BUILT_IN_ENTITY_TYPES=hr,h.BaseCanvasDraggableState=dJ,h.BaseEntityNames=W,h.BaseState=oJ,h.BaseValueDescriptorIds=Us,h.BreakStatementDependencyField=mp,h.BreakStatementState=wn,h.BuiltInBaseEntityState=Wr,h.CACHED_PROJECTS_BY_ID=_n,h.CALLABLE_ENTITIES_EXPLANATION=vq,h.CALLABLE_TYPES=wr,h.CALLER_ENTITIES_EXPLANATION=nP,h.CALLER_TYPES=Cr,h.CALLS_UPDATE_EXPLANATION=Fi,h.COMPARISON_CONDITIONS=GE,h.CONDITIONS=jE,h.CUSTOM_ENTITY_OPERATIONS=_m,h.CallableEntityClass=uJ,h.CallerEntityClass=Zp,h.ChangeSet=A,h.ChangeSetChangeCaptureType=yp,h.ChangeSetEntityChangeType=b,h.ChildEntityState=lJ,h.ComparisonOperatorTypes=ct,h.ConditionDependencyField=W1,h.ConditionState=Mi,h.ContinueStatementDependencyField=hp,h.ContinueStatementState=Ut,h.CreateNewInputIds=sm,h.CreateNewOutputIds=om,h.DRAGGABLE_CALLABLE_TYPES=tl,h.DRAGGABLE_CALLER_TYPES=zp,h.DRAGGABLE_ELEMENT_TYPES=$s,h.DRAGGABLE_EXECUTABLE_TYPES=_O,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Ss,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=el,h.DataTypeCompatibilityTypes=Er,h.DataTypeDependencyField=k1,h.DataTypeParentChildRelation=Et,h.DataTypeState=On,h.DefinitionEntityDependencyField=EO,h.DefinitionEntityState=Wi,h.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=aJ,h.ENTITIES_WITH_VALLUES_EXPLANATION=Nd,h.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=L,h.ENTITY_RECUSION_OPTIONS_DEFAULTS=k,h.ENTITY_TYPES=MO,h.ENTITY_WITH_DECLARATION_TYPES=gO,h.ENTITY_WITH_LOGIC_SCOPE_TYPES=mt,h.ENTITY_WITH_NAMES_TYPES=Hp,h.ENTITY_WITH_PARENT_TYPES=wO,h.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=Wp,h.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=CO,h.ENTITY_WITH_VALUE_TYPES=Jp,h.ENTRY_POINT_ENTITIES_EXPLANATION=Ps,h.ENTRY_POINT_TYPES=at,h.EVENT_TYPES=Sn,h.EXECUTABLE_TYPES=BO,h.EXECUTION_OPERATIONS=am,h.EntityAction=bO,h.EntityError=yn,h.EntityErrorSeverity=R,h.EntityGenerationError=D,h.EntityGenerationErrorCode=I,h.EntityInstanceErrorCode=Z,h.EntityOperations=Ke,h.EntityType=n,h.EntityWithLogicScopeClass=yJ,h.EntityWithValueClass=fJ,h.EntryPointEntityClass=cJ,h.ExecutionOperations=He,h.ExecutionTerminationType=q1,h.FunctionCallDependencyField=yP,h.FunctionCallState=ki,h.FunctionDeclarationDependencyField=x1,h.FunctionDeclarationState=gi,h.GLOBAL_EVENT_DECLARATIONS=xE,h.GetLastInListOperationInputIds=th,h.GetLastInListOperationOutputIds=rh,h.GlobalEventNames=Yr,h.GlobalEventState=Vn,h.HTTPOperations=Ct,h.HTTP_OPERATIONS=p0,h.InputMapDependencyField=K1,h.InputMapState=kr,h.InstalledProjectState=$i,h.InternalCallDependencyField=H1,h.InternalCallState=Cn,h.JoinListOperationInputIds=Ry,h.JoinListOperationOutputIds=by,h.LIST_OPERATIONS=Vh,h.ListOperations=ce,h.LiteralValueDependencyField=eP,h.LiteralValueState=gn,h.LoopDependencyField=J1,h.LoopState=_i,h.LoopTypes=H,h.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=xi,h.NUMBER_OPERATIONS=Lf,h.NumberOperations=Xe,h.OPERATION_DECLARATIONS=f0,h.OperationDependencyField=Z1,h.OperationState=Bi,h.OutputMapDependencyField=X1,h.OutputMapParentChildRelation=Ln,h.OutputMapState=Zr,h.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Ld,h.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=ji,h.PASS_THROUGH_CALLABLE_TYPES=nt,h.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=Yp,h.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Dp,h.ParallelExecutionOperation=AO,h.PassThroughCallableEntityClass=pJ,h.PersistedEntity=OO,h.PersistedEntityMethods=ar,h.PrimitiveEntityState=pr,h.PrimitiveTypes=M,h.ProjectState=w,h.PropertyDependencyField=j1,h.PropertyState=wi,h.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=RO,h.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=Tq,h.ReturnDeclarationDependencyField=F1,h.ReturnDeclarationState=tr,h.ReturnStatementDependencyField=gd,h.ReturnStatementState=Ci,h.STANDALONE_CONDITIONS=gE,h.STRING_OPERATIONS=Iy,h.ScopeCompatibilityType=Hd,h.SearchDependencyField=z1,h.SearchState=Si,h.SequentialExecutionOperation=PO,h.SequentialExecutionOperationInputIds=Jh,h.SequentialExecutionOperationOutputIds=Wh,h.SharedEntityErrorCode=S,h.SharedStateFunctionality=IO,h.SplitListOperationInputIds=$y,h.SplitListOperationOutputIds=Uy,h.StandaloneOperatorTypes=yr,h.StringOperations=Te,h.TERMINATION_TYPES=st,h.Traverser=Cp,h.USER_MANAGED_ENTITY_TYPES=Kp,h.UserManagedEntityStateTemplate=sJ,h.VALUE_READING_ENTITIES_EXPLANATION=Ap,h.VALUE_READING_TYPES=fi,h.VALUE_WRITING_ENTITIES_EXPLANATION=aP,h.VALUE_WRITING_TYPES=ht,h.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=bp,h.VARIABLE_TYPES=Qe,h.ValueAutogenerationType=yt,h.ValueDescriptorDependencyField=tP,h.ValueDescriptorParentChildRelation=_,h.ValueDescriptorState=Gi,h.ValueReadingEntityClass=pi,h.ValueWritingEntityClass=_s,h.VariableDeclarationDependencyField=Y1,h.VariableDeclarationState=Li,h.VariableInputMapState=aq,h.VariableInstanceDependencyField=vp,h.VariableInstanceState=Ni,h.VariableOutputMapState=dq,h.WaitOperation=DO,h.WaitOperationInputIds=Gh,h.WaitOperationOutputIds=jh,h.appendToListOperation=xs,h.appendToListOperationElementToAppendArgument=yl,h.appendToListOperationElementToAppendArgumentParentRef=bh,h.appendToListOperationElementToAppendArgumentRef=vh,h.appendToListOperationError=Oh,h.appendToListOperationErrorParentRef=Ph,h.appendToListOperationListArgument=fl,h.appendToListOperationListArgumentParentRef=Rh,h.appendToListOperationListArgumentRef=hh,h.appendToListOperationListDataType=mh,h.appendToListOperationResultListDataType=Ih,h.appendToListOperationResultListReturn=Dh,h.appendToListOperationResultListReturnParentRef=Ah,h.appendToListOperationResultListReturnRef=Eh,h.appendToListOperationSecondListDataType=Th,h.asGenerationActionExample=qr,h.booleanPrototype=zr,h.capitalizeFirstLetter=Wt,h.checkAreDataTypesCompatible=Ir,h.checkAreDefinitionEntitiesCompatibleAsDataType=V1,h.checkArePropertiesCompatibleAsDataType=O1,h.checkHasMetadataChanged=dt,h.checkIsBranchDependentButNotDirectlyOnBranch=Vs,h.checkIsBranchDependentOnBranch=Vq,h.checkIsCallableEntityReachable=Bs,h.checkIsCanvasEntity=Jq,h.checkIsDetachedBranch=fO,h.checkIsDetachedBranchShallow=xp,h.checkIsGlobalVariable=kq,h.checkIsGloballyDeclared=Fp,h.checkIsMethod=mO,h.checkIsNestedScope=zd,h.checkScopeCompatibility=gs,h.cloneProject=_J,h.countedLoopActionDescriptor=ga,h.countedLoopActionDescriptorDynamicReturnDeclaration=Yv,h.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=Wv,h.countedLoopActionDescriptorStringArgumentDeclaration=Jv,h.countedLoopActionDescriptorStringArgumentDeclarationDataType=Zv,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=xv,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=Fv,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=kv,h.countedLoopActionDescriptorStringArgumentDeclarationParentRef=qv,h.countedLoopBodyActionDescriptor=eo,h.countedLoopBodyActionDescriptorAnyDynamicArgument=Qv,h.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Xv,h.countedLoopBodyActionDescriptorAnyDynamicReturn=tT,h.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=eT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Cl,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Hv,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=zv,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Kv,h.createDefinitionEntityFromJSONObject=jd,h.createEntityError=pe,h.createNestedDataTypeForEntity=vP,h.createNewInstanceOperation=Ki,h.createNewInstanceOperationEntityToInstanciateArgument=hm,h.createNewInstanceOperationEntityToInstanciateArgumentRef=pm,h.createNewInstanceOperationEntityToInstanciateDataType=fm,h.createNewInstanceOperationError=Em,h.createNewInstanceOperationErrorParentRef=Tm,h.createNewInstanceOperationNewEntityDataArgument=cm,h.createNewInstanceOperationNewEntityDataArgumentDataType=um,h.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=lm,h.createNewInstanceOperationNewEntityDataArgumentParentRef=dm,h.createNewInstanceOperationOutputEntityDeclaration=vm,h.createNewInstanceOperationOutputEntityDeclarationParentRef=mm,h.createNewInstanceOperationRef=ym,h.createSemanticId=G1,h.createStateFromGenerationTargetType=nJ,h.createStateFromType=lt,h.createStateFromTypeAndSubscribe=O,h.cronJobBuiltInBaseEntity=ao,h.cronJobBuiltInBaseEntityExpressionProperty=PE,h.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=jO,h.cronJobBuiltInBaseEntityExpressionPropertyRef=AE,h.cronJobBuiltInBaseEntityRef=DE,h.cronJobTriggeredFunctionDeclarationBlueprint=kl,h.cronJobTriggeredFunctionDeclarationBlueprintParentRef=RE,h.dataTypeCompatibilityToErrorExplanation=fP,h.datePrototype=gr,h.dateValueAutogenerationSchema=rc,h.definitionEntityToZodSchema=lI,h.deletePersistedEntityMethod=xl,h.deletePersistedEntityMethodParentRef=sE,h.deleteRootProject=NJ,h.endpointBuiltInBaseEntity=_a,h.endpointBuiltInBaseEntityRef=oT,h.endpointBuiltInBaseEntityRefFour=xT,h.endpointBuiltInBaseEntityRefThree=mT,h.endpointBuiltInBaseEntityRefTwo=pT,h.endpointBuiltInCorsProperty=dT,h.endpointBuiltInCorsPropertyDataType=sT,h.endpointBuiltInCorsPropertyDataTypeRef=nT,h.endpointBuiltInCorsPropertyRef=aT,h.endpointBuiltInMethodProperty=Bl,h.endpointBuiltInMethodPropertyDataType=hT,h.endpointBuiltInMethodPropertyDataTypeRef=fT,h.endpointBuiltInMethodPropertyRef=yT,h.endpointBuiltInPathProperty=gl,h.endpointBuiltInPathPropertyDataType=cT,h.endpointBuiltInPathPropertyDataTypeRef=lT,h.endpointBuiltInPathPropertyRef=uT,h.endpointPathParamsArgumentDeclaration=Ml,h.endpointPathParamsArgumentDeclarationRef=OT,h.endpointPathParamsVariableDataType=VT,h.endpointPathParamsVariableDataTypeRef=PT,h.endpointReachedTriggerActionDescriptor=Gl,h.endpointReachedTriggerActionDescriptorRef=wT,h.endpointReachedTriggerActionDescriptorRefFour=BT,h.endpointReachedTriggerActionDescriptorRefThree=gT,h.endpointReachedTriggerActionDescriptorRefTwo=CT,h.endpointRequestBodyArgumentDeclaration=Ll,h.endpointRequestBodyArgumentDeclarationRef=IT,h.endpointRequestBodyVariableDataType=RT,h.endpointRequestHeadersArgumentDeclaration=_l,h.endpointRequestHeadersArgumentDeclarationRef=TT,h.endpointRequestHeadersVariableDataType=ET,h.endpointRequestHeadersVariableDataTypeRef=vT,h.endpointRequestQueryParamsArgumentDeclaration=Nl,h.endpointRequestQueryParamsArgumentDeclarationRef=AT,h.endpointRequestQueryParamsVariableDataType=DT,h.endpointRequestQueryParamsVariableDataTypeRef=bT,h.endpointResponseBodyDataType=jT,h.endpointResponseBodyReturnDeclaration=Ul,h.endpointResponseBodyReturnDeclarationRef=GT,h.endpointResponseCodeDataType=MT,h.endpointResponseCodeReturnDeclaration=Sl,h.endpointResponseCodeReturnDeclarationRef=_T,h.endpointResponseHeadersDataType=$T,h.endpointResponseHeadersDataTypeRef=LT,h.endpointResponseHeadersReturnDeclaration=$l,h.endpointResponseHeadersReturnDeclarationRef=ST,h.endpointReturnStatementRef=NT,h.endpointReturnStatementRefThree=FT,h.endpointReturnStatementRefTwo=UT,h.enrichFromKnownEntities=ws,h.enumOptionsProperty=nf,h.enumOptionsPropertyDataType=tf,h.enumOptionsPropertyDataTypeRef=Qp,h.enumOptionsPropertyRef=ef,h.enumPrototype=Hr,h.enumPrototypeRef=rf,h.executionBuiltInBaseEntity=so,h.executionBuiltInEntityAbortMethod=Zl,h.executionBuiltInEntityAbortMethodParentRef=OE,h.filterOutDuplicateEntities=u,h.filterOutDuplicateErrors=k9,h.findEntityFromKeys=gp,h.findReferenceToSelfInList=_P,h.findReferencesToSelfInProject=Sq,h.flattenActionDescriptor=MP,h.flattenArgumentDeclaration=NP,h.flattenBreakStatement=LP,h.flattenBuiltInBaseEntity=SP,h.flattenCalls=Jr,h.flattenCanvasAncestorsUntil=Fd,h.flattenCondition=$P,h.flattenContinueStatement=UP,h.flattenDataType=jP,h.flattenDefinitionEntity=GP,h.flattenDefinitionEntityExtensionAndImplementationTypes=Up,h.flattenDefinitionEntityExtensionTypes=Yd,h.flattenDefinitionEntityExtensions=Sp,h.flattenDefinitionEntityImplementations=$p,h.flattenDefinitionEntityImplementionTypes=Wd,h.flattenDerivedCanvasEntities=rr,h.flattenDetachedBranch=hO,h.flattenElementCalls=it,h.flattenElementCallsOnTheSameScope=Lq,h.flattenEntity=N,h.flattenFunctionCall=FP,h.flattenFunctionDeclaration=xP,h.flattenGlobalEvent=kP,h.flattenInputMap=ZP,h.flattenInstalledProject=qP,h.flattenInternalCall=JP,h.flattenLiteralValue=WP,h.flattenLoop=YP,h.flattenOperation=zP,h.flattenOutputMap=HP,h.flattenPrimitiveEntity=KP,h.flattenProject=XP,h.flattenProjectElements=BP,h.flattenProperty=QP,h.flattenRelatedCanvasElementsOnTheLeft=cO,h.flattenRelatedCanvasElementsOnTheRight=uO,h.flattenReturnDeclaration=eO,h.flattenReturnStatement=tO,h.flattenSearch=rO,h.flattenValueDescriptor=iO,h.flattenVariableDeclaration=nO,h.flattenVariableInstance=aO,h.flattenVariableReads=gP,h.flattenVariableWrites=CP,h.flattenVariables=We,h.fromChangeSetToRecordChangeSet=eJ,h.fromZodParseToEntityGenerationErrors=Tp,h.generate=Zw,h.generateActionExample=Eq,h.generateExecutionDataType=V7,h.generateIdFromStrategy=pt,h.generateMutablePropertiesExplanation=Bd,h.generateRandomBoolean=SI,h.generateRandomDate=fI,h.generateRandomDateAfter=uI,h.generateRandomDateBefore=cI,h.generateRandomDateBetweenRange=pI,h.generateRandomNumber=BI,h.generateRandomNumberAfter=wI,h.generateRandomNumberBefore=CI,h.generateRandomNumberBetweenRange=gI,h.generateRandomText=LI,h.generateRandomTextAfter=_I,h.generateRandomTextBefore=MI,h.generateRandomTextBetweenRange=NI,h.generateUniqueUUID=VI,h.getAllActionDescriptorsForConditions=Ud,h.getAllActionDescriptorsForGlobalEvents=Sd,h.getAllActionDescriptorsForLoops=$d,h.getAllActionDescriptorsForOperations=Aq,h.getAllBuiltInEntityIds=qd,h.getAllGloballyDeclaredFunctionDeclarationsExplanation=uP,h.getBaseBuiltInEntities=qi,h.getBaseSchemaBasedOnType=rP,h.getBuiltInEntityOwner=Ji,h.getCallableEntityReferenceSchema=Dt,h.getCallableEntityTypeSchema=yD,h.getCalledBy=cr,h.getCallerEntityReferenceSchema=W3,h.getCallerEntityTypeSchema=J3,h.getCalls=Mp,h.getCanvasEntitiesDerivedFromInternalCalls=lO,h.getCanvasEntitiesDerivedFromWrites=Ra,h.getCanvasEntityDerivedFromValueReadingEntity=Jd,h.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=dO,h.getCanvasEntityReferenceSchema=u5,h.getCanvasEntityTypeSchema=l5,h.getChildrenEntityWithValues=Cq,h.getColumnProperties=Kq,h.getCommonAncestor=_p,h.getCommonChildren=TP,h.getDatabaseEntities=zq,h.getDatabaseEntity=Xq,h.getDeclaration=Pn,h.getDeepestScope=TO,h.getDefinitionEntityExtends=ba,h.getDraggableCallableEntityReferenceSchema=mD,h.getDraggableCallableEntityTypeSchema=hD,h.getDraggableCallerEntityReferenceSchema=z3,h.getDraggableCallerEntityTypeSchema=Y3,h.getDraggableExecutableEntityReferenceSchema=Q3,h.getDraggableExecutableEntityTypeSchema=X3,h.getDraggablePassThroughCallableEntityReferenceSchema=md,h.getDraggablePassThroughCallableEntityTypeSchema=hd,h.getDraggablePlayableEntityReferenceSchema=n5,h.getDraggablePlayableEntityTypeSchema=i5,h.getEntityArgumentDeclarations=Lp,h.getEntityInputMaps=sO,h.getEntityOutputMaps=jq,h.getEntityReferenceSchema=d5,h.getEntityReturnDeclarations=oO,h.getEntityTypeSchema=o5,h.getEntityWithLogicScopeReferenceSchema=di,h.getEntityWithLogicScopeTypeSchema=e5,h.getEntityWithValueReferenceSchema=fD,h.getEntityWithValueTypeSchema=q3,h.getEntryPointEntityReferenceSchema=bt,h.getEntryPointEntityTypeSchema=Pi,h.getEventEntityReferenceSchema=fd,h.getEventEntityTypeSchema=pd,h.getExecutableEntityReferenceSchema=K3,h.getExecutableEntityTypeSchema=H3,h.getExtendedBuiltInEntity=Fq,h.getExtendedDefinitionEntity=Gp,h.getGenerationTargetSchemaBasedOnType=iP,h.getHeadIfPartOfDetachedBranch=yO,h.getHighestScope=vO,h.getImplementedBuiltInEntity=xq,h.getIsInteractive=jp,h.getLastInListOperation=pl,h.getLastInListOperationError=ph,h.getLastInListOperationErrorParentRef=ch,h.getLastInListOperationInputListArgument=dh,h.getLastInListOperationInputListArgumentParentRef=oh,h.getLastInListOperationInputListArgumentRef=ih,h.getLastInListOperationInputListDataType=nh,h.getLastInListOperationOutputElementDataType=sh,h.getLastInListOperationOutputElementReturn=uh,h.getLastInListOperationOutputElementReturnParentRef=lh,h.getLastInListOperationOutputElementReturnRef=ah,h.getLinkedEntitiesFromArgumentDeclaration=Nq,h.getLowestPersistedEntityImplementation=pO,h.getParentCallableEntity=EP,h.getParentCallerEntity=RP,h.getParentCanvasEntities=Yt,h.getParentCanvasEntity=Vt,h.getParentCanvasEntityFromTransfer=xd,h.getParentEntryPoint=wq,h.getParentPassthroughCallableEntity=IP,h.getPassThroughCallableEntityReferenceSchema=et,h.getPassThroughCallableEntityTypeSchema=yd,h.getPeristedEntities=Yq,h.getPlayableEntityReferenceSchema=r5,h.getPlayableEntityTypeSchema=t5,h.getProject=MJ,h.getPrototypeByType=Cs,h.getReferenceEntityId=g,h.getReferencedEntitiesStateOrErrors=Md,h.getReferencedEntityStateOrErrors=Ep,h.getReferencedIds=Zd,h.getRelatedCanvasElementsOnTheLeft=Bn,h.getRelatedCanvasElementsOnTheLeftFromTransfer=$q,h.getRelatedCanvasElementsOnTheRight=Zi,h.getRootEntryPointScopeOwner=kp,h.getScopeOwner=zt,h.getStateClassFromType=Qq,h.getTerminationReferenceSchema=s5,h.getTerminationTypeSchema=a5,h.getUsedArgFromDeclaration=Uq,h.getUsedReturnFromDeclaration=Gq,h.getValueReadingEntityReferenceSchema=pD,h.getValueReadingEntityTypeSchema=oi,h.getValueWritingEntityReferenceSchema=Z3,h.getValueWritingEntityTypeSchema=hs,h.getVariableFromInputMapping=AP,h.getVariableFromReturnVariablePointer=OP,h.getVariableReferenceSchema=Di,h.getVariableTypeSchema=En,h.getVariablesFromArgumentDeclarations=kd,h.getVariablesFromInputMaps=DP,h.getVariablesFromOutputMapping=VP,h.getVariablesFromOutputMaps=wP,h.getVariablesFromReturnDeclarations=PP,h.getVariablesInSameOrHigherScope=op,h.getWrites=Np,h.groupCallsBasedOnParallelizableExecution=Bq,h.handleAfterEntityImplementationSideEffects=mP,h.handleBeforeEntityImplementationSideEffects=hP,h.httpRequestBodyArgument=Js,h.httpRequestBodyArgumentRef=qm,h.httpRequestBodyDataType=Jm,h.httpRequestHeadersArgument=qs,h.httpRequestHeadersArgumentRef=km,h.httpRequestHeadersDataType=Zm,h.httpRequestMethodArgument=ks,h.httpRequestMethodArgumentRef=Fm,h.httpRequestMethodDataType=xm,h.httpRequestMethodDataTypeRef=Gm,h.httpRequestOperation=Oa,h.httpRequestOperationErrorValueDescriptor=Il,h.httpRequestOperationErrorValueDescriptorDatatype=c0,h.httpRequestOperationErrorValueDescriptorRef=u0,h.httpRequestOperationRef=s0,h.httpRequestOperationRefEight=d0,h.httpRequestOperationRefFive=n0,h.httpRequestOperationRefFour=i0,h.httpRequestOperationRefNine=l0,h.httpRequestOperationRefSeven=o0,h.httpRequestOperationRefSix=a0,h.httpRequestOperationRefThree=r0,h.httpRequestOperationRefTwo=t0,h.httpRequestQueryParamsArgument=El,h.httpRequestQueryParamsArgumentRef=$m,h.httpRequestQueryParamsDataType=Um,h.httpRequestVariableURLArgument=Zs,h.httpRequestVariableURLArgumentRef=Lm,h.httpRequestVariableURLDataType=Sm,h.httpRequestVariableURLDataTypeRef=Mm,h.httpResponseBodyReturnDataType=e0,h.httpResponseBodyReturnDataTypeRef=Xm,h.httpResponseBodyReturnReturn=zs,h.httpResponseBodyReturnReturnRef=Qm,h.httpResponseCodeDataType=Ym,h.httpResponseCodeReturn=Ws,h.httpResponseCodeReturnRef=Wm,h.httpResponseHeadersDataType=Km,h.httpResponseHeadersDataTypeRef=zm,h.httpResponseHeadersReturn=Ys,h.httpResponseHeadersReturnRef=Hm,h.implement=Gd,h.inferArgumentDeclarationDataType=w1,h.inferDataType=xr,h.inferInputMapDataType=np,h.inferOutputMapDataType=sp,h.inferPropertyDataType=B1,h.inferReturnDeclarationDataType=ap,h.inferValueDescriptorDataType=_1,h.inferVariableDeclarationDataType=g1,h.inferVariableInstanceDataType=C1,h.initBaseProjectEntity=qp,h.initProject=VO,h.isPromise=wp,h.iterateOverListActionDescriptorListArgumentDeclaration=q0,h.iterateOverListActionDescriptorListArgumentDeclarationDataType=k0,h.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=x0,h.iterateOverListActionDescriptorListArgumentDeclarationParentRef=Z0,h.iterateOverListLoopActionDescriptor=yi,h.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=W0,h.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=J0,h.iterateOverListLoopBodyActionDescriptor=Ca,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=rv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=tv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=nv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=iv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Qs,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=z0,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Y0,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=H0,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=ev,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=X0,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=K0,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Q0,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=lv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=ov,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=sv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=dv,h.iterateOverObjectKeysLoopActionDescriptor=jn,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=cv,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=uv,h.iterateOverObjectKeysLoopBodyActionDescriptor=Pl,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=Iv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Ev,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=bv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Rv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Dl,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=fv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=pv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=yv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Tv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=mv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=hv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=vv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=Vv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Pv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Dv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Ov,h.iterateOverObjectValuesLoopActionDescriptor=Fn,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Cv,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=wv,h.iterateOverObjectValuesLoopBodyActionDescriptor=Vl,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Uv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$v,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=jv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Gv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ol,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Bv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=gv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=_v,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Sv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Nv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Mv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Lv,h.iterateOverStringActionDescriptorDynamicReturnDeclaration=g0,h.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=C0,h.iterateOverStringActionDescriptorStringArgumentDeclaration=w0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=O0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=P0,h.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=V0,h.iterateOverStringLoopActionDescriptor=wa,h.iterateOverStringLoopBodyActionDescriptor=Xs,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=U0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=j0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=G0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=bl,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=_0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=B0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=M0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Al,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=L0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=N0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=S0,h.joinListOperation=ll,h.joinListOperationError=Sy,h.joinListOperationErrorParentRef=Ly,h.joinListOperationFirstListArgument=gy,h.joinListOperationFirstListArgumentParentRef=Cy,h.joinListOperationFirstListArgumentRef=Ay,h.joinListOperationFirstListDataType=Dy,h.joinListOperationResultListDataType=wy,h.joinListOperationResultListReturn=Ny,h.joinListOperationResultListReturnParentRef=My,h.joinListOperationResultListReturnRef=Vy,h.joinListOperationSecondListArgument=_y,h.joinListOperationSecondListArgumentParentRef=By,h.joinListOperationSecondListArgumentRef=Py,h.joinListOperationSecondListDataType=Oy,h.joinListWithLastSeparator=re,h.joinStringsOperation=Pa,h.joinStringsOperationDynamicStringArgument=ry,h.joinStringsOperationDynamicStringArgumentParentRef=ty,h.joinStringsOperationDynamicStringArgumentRef=Qf,h.joinStringsOperationDynamicStringDataType=ey,h.joinStringsOperationError=Xf,h.joinStringsOperationErrorParentRef=Kf,h.joinStringsOperationFirstStringArgument=js,h.joinStringsOperationFirstStringArgumentParentRef=xf,h.joinStringsOperationFirstStringArgumentRef=Sf,h.joinStringsOperationFirstStringDataType=$f,h.joinStringsOperationResultStringDataType=Ff,h.joinStringsOperationResultStringReturn=Da,h.joinStringsOperationResultStringReturnParentRef=Hf,h.joinStringsOperationResultStringReturnRef=jf,h.joinStringsOperationSecondStringArgument=Fs,h.joinStringsOperationSecondStringArgumentParentRef=zf,h.joinStringsOperationSecondStringArgumentRef=Uf,h.joinStringsOperationSecondStringDataType=Gf,h.joinStringsOperationSeparatorStringArgument=Yf,h.joinStringsOperationSeparatorStringArgumentParentRef=Wf,h.joinStringsOperationSeparatorStringArgumentRef=kf,h.joinStringsOperationSeparatorStringDataType=Jf,h.joinStringsOperationSeparatorStringDataTypeDefaultValue=qf,h.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=Zf,h.keyValuePrototype=$n,h.lowercaseFirstLetter=Dd,h.manualFlowActionDescriptorDeclarationArgumentDeclaration=Rl,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=T0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=v0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=E0,h.manualFlowLoopActionDescriptor=Hs,h.manualFlowLoopActionDescriptorDynamicReturnDeclaration=m0,h.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=h0,h.manualFlowLoopBodyActionDescriptor=Ks,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=R0,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=I0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=A0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=b0,h.mapActionDescriptorToTypeItRepresents=Wq,h.mergeEntityErrorsList=Z9,h.mergeListOfEntities=Zq,h.methodDefaultValue=jm,h.mockClientProject=xA,h.moreThanOrEqualCondition=Jn,h.moreThanOrEqualConditionLeftHandArgument=NE,h.moreThanOrEqualConditionLeftHandArgumentDataType=_E,h.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=BE,h.moreThanOrEqualConditionLeftHandArgumentParentRef=ME,h.moreThanOrEqualConditionRightHandArgument=UE,h.moreThanOrEqualConditionRightHandArgumentDataType=SE,h.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=LE,h.moreThanOrEqualConditionRightHandArgumentParentRef=$E,h.notEmptyCondition=nn,h.notEmptyConditionArgument=CE,h.notEmptyConditionRef=wE,h.nullPrototype=Xp,h.numberAdditionOperation=Gs,h.numberAdditionOperationDynamicSummandArgument=Tf,h.numberAdditionOperationDynamicSummandArgumentType=vf,h.numberAdditionOperationDynamicSummandArgumentTypeParentRef=mf,h.numberAdditionOperationError=hf,h.numberAdditionOperationErrorParentRef=yf,h.numberAdditionOperationFirstNumberArgument=rl,h.numberAdditionOperationFirstNumberArgumentRef=sf,h.numberAdditionOperationFirstNumberDataType=of,h.numberAdditionOperationRef=pf,h.numberAdditionOperationRefThree=nl,h.numberAdditionOperationRefTwo=ff,h.numberAdditionOperationResultNumberDataType=cf,h.numberAdditionOperationResultNumberReturn=al,h.numberAdditionOperationResultNumberReturnRef=uf,h.numberAdditionOperationSecondNumberArgument=il,h.numberAdditionOperationSecondNumberArgumentRef=df,h.numberAdditionOperationSecondNumberDataType=lf,h.numberPrototype=he,h.numberSubtractionOperation=ol,h.numberSubtractionOperationDynamicSubtrahendArgument=Nf,h.numberSubtractionOperationDynamicSubtrahendArgumentType=Mf,h.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=_f,h.numberSubtractionOperationError=Bf,h.numberSubtractionOperationErrorParentRef=gf,h.numberSubtractionOperationFirstNumberArgument=Pf,h.numberSubtractionOperationFirstNumberArgumentRef=Ef,h.numberSubtractionOperationFirstNumberDataType=If,h.numberSubtractionOperationRef=sl,h.numberSubtractionOperationRefThree=wf,h.numberSubtractionOperationRefTwo=Of,h.numberSubtractionOperationResultNumberDataType=Df,h.numberSubtractionOperationResultNumberReturn=Cf,h.numberSubtractionOperationResultNumberReturnRef=Af,h.numberSubtractionOperationSecondNumberArgument=Vf,h.numberSubtractionOperationSecondNumberArgumentRef=Rf,h.numberSubtractionOperationSecondNumberDataType=bf,h.numberValueAutogenerationSchema=tc,h.parallelExecutionOperation=br,h.parallelExecutionOperationError=Uh,h.parallelExecutionOperationErrorParentRef=$h,h.parallelExecutionOperationListOfExecutionResultsDataType=Nh,h.parallelExecutionOperationListOfExecutionResultsReturn=ml,h.parallelExecutionOperationListOfExecutionResultsReturnRef=Mh,h.parallelExecutionOperationListOfFunctionsArgument=hl,h.parallelExecutionOperationListOfFunctionsArgumentDatatype=_h,h.parallelExecutionOperationListOfFunctionsArgumentRef=Bh,h.parallelExecutionOperationListOfFunctionsBlueprint=gh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Ch,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=wh,h.parallelExecutionOperationRef=Lh,h.parallelExecutionOperationRefThree=Sh,h.persistedBuiltInBaseEntity=Pt,h.persistedBuiltInBaseEntityDatabaseProperty=kn,h.persistedBuiltInBaseEntityDatabasePropertyDataType=lE,h.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=UO,h.persistedBuiltInBaseEntityDatabasePropertyParentRef=uE,h.persistedBuiltInBaseEntityDatabasePropertyRef=dE,h.persistedBuiltInBaseEntityPrimaryKeyProperty=Zn,h.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=TE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=pE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=cE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=EE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=vE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=yE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=fE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=mE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=hE,h.processOutputGlobalValueDescriptorDataType=qE,h.processOutputGlobalValueDescriptorReturn=lo,h.processOutputGlobalValueDescriptorReturnRef=ZE,h.projectPublicationCompletedGlobalEvent=oo,h.propertyToZodSchema=dI,h.relationalDatabaseBuiltInBaseEntity=Mr,h.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Fl,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=nE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=iE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=aE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=rE,h.relationalDatabaseBuiltInBaseEntityDefaultProperty=jl,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=tE,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=QT,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=eE,h.relationalDatabaseBuiltInBaseEntityIdentifierProperty=to,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=qT,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=kT,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=ZT,h.relationalDatabaseBuiltInBaseEntityMinSizeProperty=no,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=XT,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=HT,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=KT,h.relationalDatabaseBuiltInBaseEntityPasswordProperty=io,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=zT,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=$O,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=YT,h.relationalDatabaseBuiltInBaseEntityRef=xn,h.relationalDatabaseBuiltInBaseEntityUsernameProperty=ro,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=WT,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=SO,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=JT,h.resolveActionDescriptorName=U1,h.resolveBaseEntityName=N1,h.resolveBuiltInBaseEntityDataTypeLabel=L1,h.resolveClonedEntityProject=ft,h.resolveConditionOperatorLabel=wd,h.resolveDataType=Pd,h.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Bp,h.resolveDataTypeLabel=Vd,h.resolveDefinitionEntityDataTypeLabel=_7,h.resolveEntityDataTypeLabel=B7,h.resolveEntityName=U,h.resolveFirstCallsSecond=_q,h.resolveFirstWritesSecond=Mq,h.resolvePrimaryKeyProperty=Hq,h.resolvePrimitiveEntityName=$1,h.resolveSearchName=S1,h.resolveVariableScope=w7,h.sequentialExecutionOperation=Qr,h.sequentialExecutionOperationError=nm,h.sequentialExecutionOperationErrorParentRef=im,h.sequentialExecutionOperationListOfExecutionResultsDataType=em,h.sequentialExecutionOperationListOfExecutionResultsReturn=Tl,h.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=rm,h.sequentialExecutionOperationListOfExecutionResultsReturnRef=Qh,h.sequentialExecutionOperationListOfFunctionsArgument=vl,h.sequentialExecutionOperationListOfFunctionsArgumentDatatype=Xh,h.sequentialExecutionOperationListOfFunctionsArgumentParentRef=tm,h.sequentialExecutionOperationListOfFunctionsArgumentRef=Kh,h.sequentialExecutionOperationListOfFunctionsBlueprint=Hh,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=zh,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=Yh,h.softDeletePersistedEntityMethod=GO,h.softDeletePersistedEntityMethodParentRef=IE,h.sortCallsBasedOnExecutionDependencies=bP,h.sortChildrenEntitiesBasedOnExecutionDependencies=gq,h.splitListOperation=cl,h.splitListOperationError=eh,h.splitListOperationErrorParentRef=Qy,h.splitListOperationFirstOutputListDataType=ky,h.splitListOperationFirstOutputListReturn=zy,h.splitListOperationFirstOutputListReturnParentRef=Yy,h.splitListOperationFirstOutputListReturnRef=ul,h.splitListOperationInputListArgument=qy,h.splitListOperationInputListArgumentParentRef=Zy,h.splitListOperationInputListArgumentRef=Gy,h.splitListOperationInputListDataType=jy,h.splitListOperationSecondOutputListDataType=Hy,h.splitListOperationSecondOutputListReturn=Xy,h.splitListOperationSecondOutputListReturnParentRef=Ky,h.splitListOperationSplitIndexArgument=Wy,h.splitListOperationSplitIndexArgumentParentRef=Jy,h.splitListOperationSplitIndexArgumentRef=Fy,h.splitListOperationSplitIndexDataType=xy,h.splitStringOperation=dl,h.splitStringOperationError=Ey,h.splitStringOperationErrorParentRef=Ty,h.splitStringOperationFirstPartResultStringDataType=dy,h.splitStringOperationFirstPartResultStringReturn=vy,h.splitStringOperationFirstPartResultStringReturnParentRef=my,h.splitStringOperationFirstPartResultStringReturnRef=oy,h.splitStringOperationIndexArgument=yy,h.splitStringOperationIndexArgumentParentRef=fy,h.splitStringOperationIndexArgumentRef=ay,h.splitStringOperationIndexDataType=sy,h.splitStringOperationSecondPartResultStringDataType=uy,h.splitStringOperationSecondPartResultStringReturn=NO,h.splitStringOperationSecondPartResultStringReturnParentRef=hy,h.splitStringOperationSecondPartResultStringReturnRef=ly,h.splitStringOperationStringArgument=py,h.splitStringOperationStringArgumentParentRef=cy,h.splitStringOperationStringArgumentRef=iy,h.splitStringOperationStringDataType=ny,h.stringPrototype=ie,h.stringValueAutogenerationSchema=ec,h.suggestNewIdForEntity=fp,h.test_primitive_entities_export=LJ,h.toCamelCase=C7,h.toEntityState=ir,h.toKebabCase=M1,h.toLowerCaseKebabCase=Od,h.toPascalCase=g7,h.untypedDataPrototype=At,h.updateErrorsList=Ye,h.updateValueReader=qq,h.urlDefaultValue=Nm,h.uuidPrototype=Kr,h.validateArgumentDeclarationName=cp,h.validateCalledByErrorIdInAction=Rq,h.validateCalledByIdInAction=Iq,h.validateCallers=lP,h.validateConditionEntityDeclaration=Dq,h.validateDataOperation=Xi,h.validateDataOperationDataToValidateArgument=Am,h.validateDataOperationDataToValidateArgumentParentRef=bm,h.validateDataOperationDataToValidateArgumentRef=Im,h.validateDataOperationDataToValidateDataType=Rm,h.validateDataOperationEntityToMatchTypeArgument=Vm,h.validateDataOperationEntityToMatchTypeArgumentParentRef=Om,h.validateDataOperationEntityToMatchTypeArgumentRef=Dm,h.validateDataOperationEntityToMatchTypeDataType=Pm,h.validateDataOperationError=Bm,h.validateDataOperationErrorParentRef=gm,h.validateDataOperationOutputEntityDeclaration=Cm,h.validateDataOperationOutputEntityDeclarationParentRef=wm,h.validateDefinitionEntityName=Cd,h.validateEntryCaller=dP,h.validateErrorCaller=oP,h.validateFunctionCallDeclaration=cP,h.validateFunctionDeclarationName=dp,h.validateGeneratedEntityParentIsNotBuiltInEntity=mq,h.validateGeneration=yq,h.validateGenerationTarget=ot,h.validateGenerationUpdate=hq,h.validateLoopEntityDeclaration=Pq,h.validateName=M7,h.validateOperationEntityDeclaration=pP,h.validatePropertyName=up,h.validateReachability=ci,h.validateReadsValueInActionPayload=bq,h.validateReferenceObject=_d,h.validateReferenceToOne=Ip,h.validateReferences=It,h.validateReturnDeclarationName=pp,h.validateSuccessCaller=sP,h.validateValueReaderGenerationUpdate=Os,h.validateValueWritter=Op,h.validateVariableDeclarationName=lp,h.validateVariableInternalCallUse=Vp,h.valueAutogenerationCurrentDateAndTimeSchema=qA,h.valueAutogenerationGenericSchema=Ko,h.valueAutogenerationOptions=ic,h.valueAutogenerationOptionsSchema=ZA,h.valueAutogenerationRandomBooleanSchema=Qu,h.valueAutogenerationRandomDateBetweenSchema=eD,h.valueAutogenerationRandomDateFromSchema=XA,h.valueAutogenerationRandomDateSchema=ed,h.valueAutogenerationRandomDateUntilSchema=QA,h.valueAutogenerationRandomNumberBetweenSchema=YA,h.valueAutogenerationRandomNumberFromSchema=JA,h.valueAutogenerationRandomNumberSchema=Xo,h.valueAutogenerationRandomNumberUntilSchema=WA,h.valueAutogenerationRandomSchema=ds,h.valueAutogenerationRandomTextBetweenSchema=KA,h.valueAutogenerationRandomTextFromSchema=zA,h.valueAutogenerationRandomTextSchema=Qo,h.valueAutogenerationRandomTextUntilSchema=HA,h.valueAutogenerationRangeValueTypesSchema=os,h.valueAutogenerationUniqueSchema=Xu,h.waitOperation=jt,h.waitOperationMillisecondsNumberArgument=Hi,h.waitOperationMillisecondsNumberArgumentRef=Fh,h.waitOperationMillisecondsNumberDataType=xh,h.waitOperationOperationError=qh,h.waitOperationOperationErrorParentRef=Zh,h.waitOperationRef=kh,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
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:a,modifiedData:r}}get allBasePropertiesFromExtendedAndImplementedEntities(){return u([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[])])}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[]),...this.implements.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])].filter(e=>!!e.abstract))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new D({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:R.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{hr.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{hr.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=w.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return(r=this.knownVersions)==null||r.set(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=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(c,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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.extends.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addExtension(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),this.initialData.implements.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addImplementation(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c,affected:f}=this.syncImplementationProperties(e);t.push(...o),r.push(...l),a.push(...c),d.push(...f);const{updated:y,added:v,removed:E,affected:P}=this.addExtendedProperties(e);return t.push(...y),r.push(...v),a.push(...E),d.push(...P),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.methods=this.initialData.methods.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.extends=this.initialData.extends.map(t=>O(t,this.project)),this.implements=this.initialData.implements.map(t=>O(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}syncImplementationProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.implementedPropertiesFromOriginalParents,c=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return l.filter(y=>!c.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===y.id})).forEach(y=>{if(this.properties.find(V=>{var C;return((C=V.implements)==null?void 0:C.id)===y.id}))return;const E=this.properties.find(V=>V.name===y.name&&!!V.abstract&&!V.implements);if(E){E.implements=y,E.abstract=!1;return}const P=y.clone(this,w.UUID.uuid());P.initChildren(e),r.push(P),e==null||e.add(P,b.Added),P.setImplements(y,e),P.metaSync({abstract:!1},e),this.addProperty(P)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addExtendedProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.extendedPropertiesFromOriginalParents,c=l.filter(y=>l.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===y.id})?!1:!y.abstract),f=new Set(o.map(y=>y.name));return c.forEach(y=>{if(f.has(y.name))return;f.add(y.name);const v=y.clone(this,w.UUID.uuid());v.initChildren(e),r.push(v),e==null||e.add(v,b.Added),this.addProperty(v)}),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSuggestions(){return this.implements.forEach(e=>{g5(this,e).forEach(a=>{const d=a.toJSON();d.id=`_suggestion--parent--${this.id}--${a.id}`;const o=O(d,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),B5(this,e).forEach(a=>{const d=`_suggestion--parent--${this.id}--${a.id}`,o=a.implementAsFunctionDeclaration(d),l=O(o,this.project);if(l.suggestion=!0,l.setParent(this,null),l.initChildren(null),l.inputs.forEach(c=>{c.suggestion=!0}),l.returnStatements.length){const c=l.returnStatements[0];c.suggestion=!0,c.outputs.forEach(f=>{f.suggestion=!0})}this.addSuggestedMethod(l)})}),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.x=e.x||this.x,this.y=e.y||this.y,this.static=e.static||this.static,this.abstract=e.abstract||this.abstract,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ne.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ne.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:f,added:y}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...f),d.push(...y)}),this.properties.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.methods.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.abstractMethods.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.suggestedProperties.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),this.suggestedMethods.forEach(l=>{const{updated:c,removed:f}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...f)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const l=this.parent.setEntity(null);r.push(l)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];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:l}=o.restore({},e);r.push(...l)}),this.methods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.abstractMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedProperties.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(r=>r.toFlat(e)),...this.implements.flatMap(r=>r.toFlat(e)),...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(r=>r.toFlatIds(e)),...this.implements.flatMap(r=>r.toFlatIds(e)),...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.parent.toFlatIds(e)])}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=k){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:"1",createdAt:T().toISOString(),author:"1",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(c=>c.toJSONClone({...e,newId:null})),methods:this.methods.map(c=>c.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(c=>c.toJSONClone({...e,newId:null})),implements:this.implements.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),extends:this.extends.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),methods:this.methods.map(a=>a.toReference(e)),abstractMethods:this.abstractMethods.map(a=>a.toReference(e)),implements:this.implements.map(a=>a.toReference(e)),extends:this.extends.map(a=>a.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(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e)),...this.implements.flatMap(r=>r.toFlatJSON(e)),...this.extends.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.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=C5(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=null,t=null,r=!0){var P,V,C;let a=ft(e,this);const d=this.toJSON(),o=t||w.UUID.uuid();d.properties=[],d.methods=[],d.abstractMethods=[];const l=o.split("-id"),c=l[l.length-1||0]||o;d.id=o;const f=lt(d,a);e&&f.setParent(e,null),r&&f.subscribe(),f.initChildren(null);const y=(P=this.properties)==null?void 0:P.map(G=>G.clone(f,w.UUID.uuid(),r));f.properties=y;const v=(V=this.methods)==null?void 0:V.map((G,j)=>G.clone(f,c+"-method-"+j+"-id",r));f.methods=v;const E=(C=this.abstractMethods)==null?void 0:C.map((G,j)=>G.clone(f,c+"-abstract-method-"+j+"-id",r));return f.abstractMethods=E,f}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"implement-definition-entity")),r){const a=Gd(this,e,t,r);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),a}getAllInteractiveMethods(){const e=this.implements.filter(r=>r.type===n.DefinitionEntity||r.type===n.BuiltInBaseEntity&&r.interactive);return u([...this.methods,...this.extends.flatMap(r=>r.getAllInteractiveMethods()),...e.flatMap(r=>r.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const r=[],a=[],d=[],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 l=[];e.forEach(y=>{l.find(E=>U(E,this.project)===U(y,this.project))||l.push(y)});const c=this.properties.filter(y=>!y.getDataType());l.forEach(y=>{const v=c.find(G=>U(G,this.project)===U(y,this.project));if(!v)return;const P=Pn(y.parent).getMasterInputWithValueWritterFromAllInstances(y),V=xr(P),C=V==null?void 0:V.clone(v,w.UUID.uuid(),!0);C&&v.setDataType(C),y.setDeclaration(v)});const f=[];return l.forEach(y=>{if(!y.declaration){f.push(y);return}}),f.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(f.forEach(y=>{const v=this.properties.find(B=>U(B,this.project)===U(y,this.project));if(v){if(y.setDeclaration(v),!v.getDataType()){const $=Pn(y.parent).getMasterInputWithValueWritterFromAllInstances(y),z=xr($),X=z==null?void 0:z.clone(v,w.UUID.uuid(),!0);X&&v.setDataType(X)}return}const E={id:w.UUID.uuid(),type:n.Property,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:U(y,this.project),description:y.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:y.index,implements:null,dataType:null,parent:this.toReference()},P=O(E,this.project);P.setParent(this,t),P.initChildren(t),t==null||t.add(P,b.Added),t==null||t.add(this,b.Affected);const C=Pn(y.parent).getMasterInputWithValueWritterFromAllInstances(y),G=xr(C),j=G==null?void 0:G.clone(P,w.UUID.uuid(),!0);return j&&(t==null||t.add(j,b.Added),P.setDataType(j)),this.addProperty(P),y.setDeclaration(P),P}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:u(r),updated:u(a),removed:u(d),affected:u(o),self:this})}};p(Ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(Ne,"type",n.DefinitionEntity),p(Ne,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),p(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),p(Ne,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),p(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),p(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"x","y"]),p(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),p(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),p(Ne,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),p(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),p(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),p(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),p(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Wi=Ne;function rJ(i){const s=o6(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Ms=class Ms extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"version");p(this,"name");p(this,"description",null);p(this,"type",n.BuiltInBaseEntity);p(this,"abstract",!1);p(this,"static");p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"interactive",!1);p(this,"errors",[]);p(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(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.extends=this.initialData.extends.map(r=>O(r,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...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=L,...t){return await Ms.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.extends.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.extends.flatMap(r=>r.toFlatIds(e))])}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=k){return{id:this.id+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=k){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(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.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=rJ(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,"",T().toISOString(),null,!0,"implement-built-in-base-entity")),r){const a=Gd(this,e,t,r);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),a}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Ms&&e.push(...r.getAllInteractiveMethods())})),u(e)}};p(Ms,"repository",{APILoad:async(e,...t)=>null});let Wr=Ms;function iJ(i){const s=X9(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Xd=class Xd extends rt{constructor(e,t){super(e);p(this,"initialData");p(this,"id");p(this,"name");p(this,"description",null);p(this,"type",n.PrimitiveEntity);p(this,"static");p(this,"abstract");p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"errors",[]);p(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(r=>{const a=O(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=O(r,this.project);return a.parent=this,a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=O(r,this.project);return a.parent=this,a})}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...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=L,...t){return await Xd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e))])}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=k){return{id:this.id+"--"+w.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=k){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(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.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=iJ(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(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Wr&&e.push(...r.getAllInteractiveMethods())}),u(e)}};p(Xd,"repository",{APILoad:async(e,...t)=>null});let pr=Xd;function lt(i,s){if(!i)throw new Error("Entity is null");const e=s.get(i.id);switch(i.type){case n.LiteralValue:return e||new gn(i,s);case n.DefinitionEntity:return e||new Wi(i,s);case n.PrimitiveEntity:return e||new pr(i,s);case n.FunctionDeclaration:return e||new gi(i,s);case n.GlobalEvent:return e||new Vn(i,s);case n.DataType:return e||new On(i,s);case n.Property:return e||new wi(i,s);case n.FunctionCall:return e||new ki(i,s);case n.Condition:return e||new Mi(i,s);case n.Operation:return e||new Bi(i,s);case n.VariableDeclaration:return e||new Li(i,s);case n.VariableInstance:return e||new Ni(i,s);case n.OutputMap:return e||new Zr(i,s);case n.ReturnDeclaration:return e||new tr(i,s);case n.ArgumentDeclaration:return e||new Ui(i,s);case n.InputMap:return e||new kr(i,s);case n.Project:return e||new w(i);case n.InstalledProject:return e||new $i(i,s);case n.ActionDescriptor:return e||new Ze(i,s);case n.ReturnStatement:return e||new Ci(i,s);case n.Loop:return e||new _i(i,s);case n.Search:return e||new Si(i,s);case n.ValueDescriptor:return e||new Gi(i,s);case n.BuiltInBaseEntity:return e||new Wr(i,s);case n.InternalCall:return e||new Cn(i,s);case n.ContinueStatement:return e||new Ut(i,s);case n.BreakStatement:return e||new wn(i,s);case n.GenericReference:return s.get(i.entityId);default:throw new Error("Invalid entity type: "+i.type)}}function O(i,s){if(!i)throw new Error("Entity is null");const e=lt(i,s);return e.subscribe(),e}function nJ(i,s){if(!i)throw new Error("Entity is null");switch(i.type){case n.LiteralValue:return gn.fromGenerationTarget(i,s);case n.DefinitionEntity:return Wi.fromGenerationTarget(i,s);case n.FunctionDeclaration:return gi.fromGenerationTarget(i,s);case n.GlobalEvent:return Vn.fromGenerationTarget(i,s);case n.DataType:return On.fromGenerationTarget(i,s);case n.Property:return wi.fromGenerationTarget(i,s);case n.FunctionCall:return ki.fromGenerationTarget(i,s);case n.Condition:return Mi.fromGenerationTarget(i,s);case n.Operation:return Bi.fromGenerationTarget(i,s);case n.VariableDeclaration:return Li.fromGenerationTarget(i,s);case n.VariableInstance:return Ni.fromGenerationTarget(i,s);case n.OutputMap:return Zr.fromGenerationTarget(i,s);case n.ReturnDeclaration:return tr.fromGenerationTarget(i,s);case n.ArgumentDeclaration:return Ui.fromGenerationTarget(i,s);case n.InputMap:return kr.fromGenerationTarget(i,s);case n.InstalledProject:return $i.fromGenerationTarget(i,s);case n.ReturnStatement:return Ci.fromGenerationTarget(i,s);case n.Loop:return _i.fromGenerationTarget(i,s);case n.Search:return Si.fromGenerationTarget(i,s);case n.ActionDescriptor:return Ze.fromGenerationTarget(i,s);case n.ValueDescriptor:return Gi.fromGenerationTarget(i,s);case n.InternalCall:return Cn.fromGenerationTarget(i,s);case n.ContinueStatement:return Ut.fromGenerationTarget(i,s);case n.BreakStatement:return wn.fromGenerationTarget(i,s);default:throw new Error("Invalid entity type: "+i.type)}}const k={seenEntityMaps:new Map,seenEntities:new Set};class IO{constructor(){p(this,"initialData")}}const L={cascade:!1},RO={APILoad:async(i,...s)=>null},aJ={APICreate:async(i,...s)=>i,APIUpdate:async(i,...s)=>i,APIDelete:async(i,...s)=>{},APIClone:async(i,...s)=>{},APILoadVersion:async(i,s,...e)=>null,...RO};class sJ{}class oJ extends IO{}class dJ{}class lJ{}class uJ{}class Zp{}class cJ extends Zp{}class pJ extends Zp{}class fJ{}class pi{static initReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=O(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=ir(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),s.readsValue.initChildren(null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}static hydrateReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=O(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=ir(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}}class _s{static initWritesValues(s,e){const t=s.initialData.writesValues.reduce((a,d)=>{if(d.type===n.GenericReference||s.writesValues.some(l=>l.id===d.id))return a;const o=O(d,s.project);return o.setValueWriter(s),Qe.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...a,o]},[]),r=[...s.writesValues];return s.writesValues=u([...r,...t]),s.writesValues}}class yJ{}const se=class se extends rt{constructor(e){super(e);p(this,"initialData");p(this,"id");p(this,"type",n.Project);p(this,"name",null);p(this,"description",null);p(this,"x");p(this,"y");p(this,"entities",[]);p(this,"projects",[]);p(this,"functions",[]);p(this,"events",[]);p(this,"variableDeclarations",[]);p(this,"variableInstances",[]);p(this,"conditions",[]);p(this,"operations",[]);p(this,"functionCalls",[]);p(this,"loops",[]);p(this,"searches",[]);p(this,"primitives",[]);p(this,"builtInBaseEntities",[]);p(this,"operationDeclarations",[]);p(this,"globalEventActionDescriptors",[]);p(this,"loopDeclarations",[]);p(this,"loopDeclarationsBodies",[]);p(this,"conditionDeclarations",[]);p(this,"valueDescriptors",[]);p(this,"dataTypes",[]);p(this,"project");p(this,"instances",{});p(this,"builtInInstances",{});p(this,"deletedInstances",{});p(this,"errors",[]);p(this,"references",[]);p(this,"history",[]);p(this,"detachedDependents",{});p(this,"knownVersions",null);p(this,"activeVersion",!1);p(this,"initialized",!1);p(this,"startedInitialization",!1);p(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{(!se.UUID||se.UUID.isBackup)&&(se.UUID=No==null?void 0:No()),se.UUID||(se.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),se.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:r=>r}}}static injectUUIDModule(e){se.UUID=e}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}onCloseChangeSet(e){this.onCloseChangeSetCallback=e}closeChangeSet(e){this.onCloseChangeSetCallback&&this.onCloseChangeSetCallback(e)}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(a=>a.id===(e==null?void 0:e.id));if(t)return t;const r=this.history.findIndex(a=>T(a.timestamp).isBefore(T(e==null?void 0:e.timestamp)));return r===-1?this.history.push(e):this.history.splice(r,0,e),e}discardChangeSet(e){const t=this.history.findIndex(r=>r.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}redo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async r=>{await t.init(this),r(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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),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=se.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new se(this);return(r=this.knownVersions)==null||r.set(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=[],r=[],a=[],d=[];return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[f,y]of this.knownVersions||new Map){if(c.set(f,y),y.activeVersion=!1,y.knownVersions)for(const[v,E]of y.knownVersions)c.set(v,E);y.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new se(c)}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:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=null){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e){const t=[],r=[],a=[],d=[];return this.subscribeToDependencies(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),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,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.projects=this.initialData.projects.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableInstances=this.initialData.variableInstances.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.conditions=this.initialData.conditions.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.operations=this.initialData.operations.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functions=this.initialData.functions.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functionCalls=this.initialData.functionCalls.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.loops=this.initialData.loops.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.searches=this.initialData.searches.map(t=>{const r=O(t,this);return r.setParent(this,null),r.initChildren(e),r}),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.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,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await se.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await se.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await se.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",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(r=>r.toFlat(e)),...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e)),...this.projects.flatMap(r=>r.toFlat(e)),...this.variableDeclarations.flatMap(r=>r.toFlat(e)),...this.variableInstances.flatMap(r=>r.toFlat(e)),...this.conditions.flatMap(r=>r.toFlat(e)),...this.operations.flatMap(r=>r.toFlat(e)),...this.functionCalls.flatMap(r=>r.toFlat(e)),...this.loops.flatMap(r=>r.toFlat(e)),...this.searches.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),Array.from(e))}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,r=new Set,a=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(d=>{if(a.includes(d)){t.set(d,d);return}t.set(d,se.UUID.uuid())}),r.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(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),projects:this.projects.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableDeclarations:this.variableDeclarations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableInstances:this.variableInstances.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),conditions:this.conditions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),operations:this.operations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functions:this.functions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),events:this.events.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functionCalls:this.functionCalls.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),loops:this.loops.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),searches:this.searches.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null}))}}toReference(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+se.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=k){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.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(a=>a.toReference(e)),functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),projects:this.projects.map(a=>a.toReference(e)),variableDeclarations:this.variableDeclarations.map(a=>a.toReference(e)),variableInstances:this.variableInstances.map(a=>a.toReference(e)),conditions:this.conditions.map(a=>a.toReference(e)),operations:this.operations.map(a=>a.toReference(e)),functionCalls:this.functionCalls.map(a=>a.toReference(e)),loops:this.loops.map(a=>a.toReference(e)),searches:this.searches.map(a=>a.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(r=>r.toFlatJSON(e)),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e)),...this.projects.flatMap(r=>r.toFlatJSON(e)),...this.variableDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.variableInstances.flatMap(r=>r.toFlatJSON(e)),...this.conditions.flatMap(r=>r.toFlatJSON(e)),...this.operations.flatMap(r=>r.toFlatJSON(e)),...this.functionCalls.flatMap(r=>r.toFlatJSON(e)),...this.loops.flatMap(r=>r.toFlatJSON(e)),...this.searches.flatMap(r=>r.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(r=>r.toFlatGenerationTarget(e)),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e)),...this.projects.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(r=>r.toFlatGenerationTarget(e)),...this.conditions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.operations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.loops.flatMap(r=>r.toFlatGenerationTarget(e)),...this.searches.flatMap(r=>r.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=A5(),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=O(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=O(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=O(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=O(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=O(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=O(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=O(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=O(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=O(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=O(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=O(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(r=>r.id===e.id);if(t>-1){const r=this.entities[t];return this.entities.splice(t,1),r}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(r=>r.id===e.id);if(t>-1){const r=this.functions[t];return this.functions.splice(t,1),r}return null}removeExternalProject(e){const t=this.projects.findIndex(r=>r.id===e.id);if(t>-1){const r=this.projects[t];return this.projects.splice(t,1),r}return null}removeGlobalEvent(e){const t=this.events.findIndex(r=>r.id===e.id);if(t>-1){const r=this.events[t];return this.events.splice(t,1),r}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(r=>r.id===e.id);if(t>-1){const r=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),r}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.functionCalls.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.conditions.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.operations.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.loops.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.searches.reduce((t,r)=>{const a=We(r);return[...t,...a]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[])]}getVariableDeclarations(){return u([...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[])])}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(r=>{if(!r.declaration){const a=r.initialData,d=a.declaration.entityId||a.declaration.id,o=t.find(l=>l.id===d);o&&r.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===W.PERSISTED_ENTITY)||null}};p(se,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),p(se,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),p(se,"type",n.Project),p(se,"USER_MANAGED_PARENT_TYPES",[]),p(se,"PARENT_TYPES",[...se.USER_MANAGED_PARENT_TYPES]),p(se,"MUTABLE_BASE_PROPERTIES",["name","description"]),p(se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),p(se,"BASE_PROPERTIES",[...se.MUTABLE_BASE_PROPERTIES,...se.INMUTABLE_BASE_PROPERTIES]),p(se,"MUTABLE_META_PROPERTIES",[...se.MUTABLE_BASE_PROPERTIES,"x","y"]),p(se,"INMUTABLE_META_PROPERTIES",[...se.INMUTABLE_BASE_PROPERTIES]),p(se,"META_PROPERTIES",[...se.MUTABLE_META_PROPERTIES,...se.INMUTABLE_META_PROPERTIES]),p(se,"MUTABLE_UPSTREAM_PROPERTIES",[]),p(se,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),p(se,"UPSTREAM_PROPERTIES",[...se.MUTABLE_UPSTREAM_PROPERTIES,...se.INMUTABLE_UPSTREAM_PROPERTIES]),p(se,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),p(se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),p(se,"DOWNSTREAM_PROPERTIES",[...se.MUTABLE_DOWNSTREAM_PROPERTIES,...se.INMUTABLE_DOWNSTREAM_PROPERTIES]),p(se,"PROPERTIES",[...se.META_PROPERTIES,...se.UPSTREAM_PROPERTIES,...se.DOWNSTREAM_PROPERTIES]);let w=se;var bO=(i=>(i.PersistChangeSet="persist-change-set",i.CreateSingle="create-single",i.CreateBulk="create-bulk",i.CreateSingleNested="create-single-nested",i.CreateBulkNested="create-bulk-nested",i.Update="update",i.Clone="clone",i.Delete="delete",i.Load="load",i.LoadNested="load-nested",i.LoadVersion="load-version",i))(bO||{});class AO extends Ze{constructor(e){super(br,e);p(this,"id",He.Parallel);p(this,"name",He.Parallel);p(this,"description","Execute a list of actions one after the other");p(this,"version","1");p(this,"autoexecutable",!0);p(this,"initialData",br);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"project");this.project=e,this.inputs=br.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=br.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=br.error?O(br.error,this.project):null}}class DO extends Ze{constructor(e){super(jt,e);p(this,"id",jt.id);p(this,"name",jt.name);p(this,"description",jt.description);p(this,"version",jt.version);p(this,"autoexecutable",!1);p(this,"initialData",jt);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"project");this.project=e,this.inputs=jt.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=jt.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=jt.error?O(jt.error,this.project):null}}class PO extends Ze{constructor(e){super(Qr,e);p(this,"id",He.Sequential);p(this,"name",He.Sequential);p(this,"description","Execute a list of actions one after the other");p(this,"version","1");p(this,"autoexecutable",!0);p(this,"initialData",Qr);p(this,"type",n.ActionDescriptor);p(this,"inputs",[]);p(this,"outputs",[]);p(this,"error",null);p(this,"project");this.project=e,this.inputs=Qr.inputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=Qr.outputs.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=Qr.error?O(Qr.error,this.project):null}}class hJ extends Ze{constructor(s){super(Oa,s)}}class mJ extends Ze{constructor(s){super(Ki,s)}}class vJ extends Ze{constructor(e){super(Xi,e);p(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e){let t=null;if(e.readsValue){const a=e.readsValue.getDataType();a&&a.entity&&a.entity.type===n.DefinitionEntity&&(t=a.entity)}const r=e.getDefaultValue();return!t&&r&&r.valueAsTypeSingle&&!Array.isArray(r.valueAsTypeSingle)&&r.valueAsTypeSingle.type===n.DefinitionEntity&&(t=r.valueAsTypeSingle),t}syncOperationInstance(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const r=[],a=[],d=[],o=[],l=this.getEntityToMatchInputMap(e);if(l){const{added:y,updated:v,removed:E,affected:P}=this.syncEntityToMatchInputMapDataType(l,t);r.push(...v),a.push(...y),d.push(...E),o.push(...P)}const c=this.getDataToValidateInputMap(e);if(c){const{added:y,updated:v,removed:E,affected:P}=this.syncDataToValidateInputMapDataType(c,t);r.push(...v),a.push(...y),d.push(...E),o.push(...P)}const f=this.getOutputDataOutputMap(e);if(f){const{added:y,updated:v,removed:E,affected:P}=this.syncOutputDataOutputMapDataType(f,t);r.push(...v),a.push(...y),d.push(...E),o.push(...P)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var c,f,y;const r=[],a=[],d=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==F.operation[Ke.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 v={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=O(v,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,b.Added),r.push(E),e.setDataType(E)}(f=e.dataType)==null||f.metaSync({inferred:!0,like:!1,asType:!0},t);const l=this.getEntityToMatch(e);return(y=e.dataType)==null||y.setEntity(l),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var y,v,E;const r=[],a=[],d=[],o=[];if(((y=e.declaration)==null?void 0:y.id)!==F.operation[Ke.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 l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l))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 P={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},V=O(P,e.project);V.setParent(e,t),V.initChildren(t),t==null||t.add(V,b.Added),r.push(V),e.setDataType(V)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(l);return(E=e.dataType)==null||E.setEntity(f),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var y,v,E;const r=[],a=[],d=[],o=[];if(((y=e.declaration)==null?void 0:y.id)!==F.operation[Ke.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 l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const P={id:w.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},V=O(P,e.project);V.setParent(e,t),V.initChildren(t),t==null||t.add(V,b.Added),r.push(V),e.setDataType(V)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(l);return(E=e.dataType)==null||E.setEntity(f),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var r,a;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id){const{added:d,updated:o,removed:l,affected:c}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}else if(((a=e.declaration)==null?void 0:a.id)===F.operation[Ke.Validate].inputs.dataToValidate.id){const{added:d,updated:o,removed:l,affected:c}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var r;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id){const{added:a,updated:d,removed:o,affected:l}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:u(d),added:u(a),removed:u(o),affected:u(l),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class TJ extends Ze{constructor(s){super(ll,s)}}class EJ extends Ze{constructor(s){super(cl,s)}}class IJ extends Ze{constructor(s){super(pl,s)}}class RJ extends Ze{constructor(s){super(xs,s)}}class bJ extends Ze{constructor(s){super(Gs,s)}}class AJ extends Ze{constructor(s){super(Pa,s)}}function DJ(i){const s=[new PO(i),new AO(i),new DO(i),new hJ(i),new mJ(i),new vJ(i),new RJ(i),new TJ(i),new IJ(i),new EJ(i),new bJ(i),new AJ(i),new Ze(dl,i),new Ze(ol,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}class OO extends Wr{constructor(e){super(Pt,e);p(this,"initialData");p(this,"id",W.PERSISTED_ENTITY);p(this,"version","1");p(this,"name",W.PERSISTED_ENTITY);p(this,"description",Pt.description);p(this,"type",n.BuiltInBaseEntity);p(this,"abstract",Pt.abstract);p(this,"static",Pt.static);p(this,"properties",[]);p(this,"methods",[]);p(this,"abstractMethods",[]);p(this,"extends",[]);p(this,"errors",[]);p(this,"project");this.initialData=Pt,this.project=e,this.id=Pt.id,this.version=Pt.version,this.name=Pt.name,this.static=Pt.static,this.abstract=Pt.abstract,this.properties=this.initialData.properties.map(t=>{const r=O(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.methods=this.initialData.methods.map(t=>{const r=O(t,this.project);return r.parent=this,r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=O(t,this.project);return r.parent=this,r}),this.extends=this.initialData.extends.map(t=>O(t,this.project))}}function PJ(i){const s=[new OO(i),new Wr(_a,i),new Wr(Mr,i),new Wr(ao,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.builtInBaseEntities=s,s}function OJ(i){const s=[new pr(ie,i),new pr(zr,i),new pr(he,i),new pr(At,i),new pr(Hr,i),new pr(gr,i),new pr(Kr,i),new pr($n,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.primitives=s,s}function VJ(i){const s=[new Ze(oo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.globalEventActionDescriptors=s,s}function wJ(i){const s=[new Ze(ga,i),new Ze(yi,i),new Ze(wa,i),new Ze(jn,i),new Ze(Fn,i),new Ze(Hs,i)];s.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarations=s;const e=[new Ze(eo,i),new Ze(Ca,i),new Ze(Xs,i),new Ze(Pl,i),new Ze(Vl,i),new Ze(Ks,i)];return e.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarationsBodies=e,s}function CJ(i){const s=[new Gi(lo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.valueDescriptors=s,s}function gJ(i){const s=[new Ze(nn,i),new Ze(Jn,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}const _n={},Kd={};async function BJ(i,s={}){const e={...xA};return e.id=i.id,s.empty?{data:{id:i.id,type:n.Project,version:"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]}}:{data:e}}function qp(i){const s=new w(i);return OJ(s),PJ(s),DJ(s),VJ(s),wJ(s),CJ(s),gJ(s),s.getAllBuiltIn().forEach(t=>{s.builtInInstances[t.id]||(s.builtInInstances[t.id]=t,delete s.instances[t.id])}),s}function _J(i){const s=new Map,e=i.getAllBuiltInIds();Object.keys(i.instances).forEach(a=>{if(e.includes(a)){s.set(a,a);return}s.set(a,w.UUID.uuid())});const t=qp(i.toShallowJSON({seenEntityMaps:s})),r=t.addChangeSet(new A(t,"",T().toISOString(),t));return new Cp(i).visit(a=>{const d=O(a.toShallowJSON({seenEntityMaps:s}),t);d.hydrateAncestors(),d.addSelfToProject(r)}).visit(a=>{const d=t.get(s.get(a.id));d&&d.afterAllChildrenInitialized(r)}),t.afterAllChildrenInitialized(r),r.close(),t}function VO(i){const s=qp(i),e=s.addChangeSet(new A(s,"",T().toISOString(),s));return e.type=yp.Automatic,new Cp(i).visit(t=>{const r=O(t,s);r.hydrateAncestors(),r.addSelfToProject(e)}).visit(t=>{const r=s.get(t.id);r&&r.afterAllChildrenInitialized(e)}),s.afterAllChildrenInitialized(e),e.close(),s}async function MJ(i,s={}){if(i.id&&_n[i.id])return _n[i.id];if(i.id&&Kd[i.id])return await Kd[i.id],_n[i.id];const e=BJ(i,s);i.id&&(Kd[i.id]=e);const t=await e;if(t.data){const r=VO(t.data);return _n[i.id]=r,i.id&&delete Kd[i.id],r}return null}function NJ(i){return _n[i.id]&&delete _n[i.id],null}const LJ="test_primitive_entities_export";h.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Pp,h.ALL_BUILT_IN_BASE_ENTITIES=VE,h.ALL_BUILT_IN_CONDITION_ENTITIES=FE,h.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=kE,h.ALL_BUILT_IN_LOOP_BODY_ENTITIES=iT,h.ALL_BUILT_IN_LOOP_ENTITIES=rT,h.ALL_BUILT_IN_OPERATION_ENTITIES=y0,h.ALL_BUILT_IN_PRIMITIVE_ENTITIES=af,h.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=WE,h.ALL_BUILT_IN_VALUE_DESCRIPTORS=JE,h.ActionDescriptorState=Ze,h.ActionInputMapState=sq,h.ActionOutputMapState=lq,h.AppendToListOperationInputIds=fh,h.AppendToListOperationOutputIds=yh,h.ArgumentDeclarationDependencyField=Q1,h.ArgumentDeclarationState=Ui,h.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Rp,h.BUILT_IN_BASE_ENTITY_IDS=F,h.BUILT_IN_ENTITY_TYPES=hr,h.BaseCanvasDraggableState=dJ,h.BaseEntityNames=W,h.BaseState=oJ,h.BaseValueDescriptorIds=Us,h.BreakStatementDependencyField=mp,h.BreakStatementState=wn,h.BuiltInBaseEntityState=Wr,h.CACHED_PROJECTS_BY_ID=_n,h.CALLABLE_ENTITIES_EXPLANATION=vq,h.CALLABLE_TYPES=wr,h.CALLER_ENTITIES_EXPLANATION=nP,h.CALLER_TYPES=Cr,h.CALLS_UPDATE_EXPLANATION=Fi,h.COMPARISON_CONDITIONS=GE,h.CONDITIONS=jE,h.CUSTOM_ENTITY_OPERATIONS=_m,h.CallableEntityClass=uJ,h.CallerEntityClass=Zp,h.ChangeSet=A,h.ChangeSetChangeCaptureType=yp,h.ChangeSetEntityChangeType=b,h.ChildEntityState=lJ,h.ComparisonOperatorTypes=ct,h.ConditionDependencyField=W1,h.ConditionState=Mi,h.ContinueStatementDependencyField=hp,h.ContinueStatementState=Ut,h.CreateNewInputIds=sm,h.CreateNewOutputIds=om,h.DRAGGABLE_CALLABLE_TYPES=tl,h.DRAGGABLE_CALLER_TYPES=zp,h.DRAGGABLE_ELEMENT_TYPES=$s,h.DRAGGABLE_EXECUTABLE_TYPES=_O,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Ss,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=el,h.DataTypeCompatibilityTypes=Er,h.DataTypeDependencyField=k1,h.DataTypeParentChildRelation=Et,h.DataTypeState=On,h.DefinitionEntityDependencyField=EO,h.DefinitionEntityState=Wi,h.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=aJ,h.ENTITIES_WITH_VALLUES_EXPLANATION=Nd,h.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=L,h.ENTITY_RECUSION_OPTIONS_DEFAULTS=k,h.ENTITY_TYPES=MO,h.ENTITY_WITH_DECLARATION_TYPES=gO,h.ENTITY_WITH_LOGIC_SCOPE_TYPES=mt,h.ENTITY_WITH_NAMES_TYPES=Hp,h.ENTITY_WITH_PARENT_TYPES=wO,h.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=Wp,h.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=CO,h.ENTITY_WITH_VALUE_TYPES=Jp,h.ENTRY_POINT_ENTITIES_EXPLANATION=Ps,h.ENTRY_POINT_TYPES=at,h.EVENT_TYPES=Sn,h.EXECUTABLE_TYPES=BO,h.EXECUTION_OPERATIONS=am,h.EntityAction=bO,h.EntityError=yn,h.EntityErrorSeverity=R,h.EntityGenerationError=D,h.EntityGenerationErrorCode=I,h.EntityInstanceErrorCode=Z,h.EntityOperations=Ke,h.EntityType=n,h.EntityWithLogicScopeClass=yJ,h.EntityWithValueClass=fJ,h.EntryPointEntityClass=cJ,h.ExecutionOperations=He,h.ExecutionTerminationType=q1,h.FunctionCallDependencyField=yP,h.FunctionCallState=ki,h.FunctionDeclarationDependencyField=x1,h.FunctionDeclarationState=gi,h.GLOBAL_EVENT_DECLARATIONS=xE,h.GetLastInListOperationInputIds=th,h.GetLastInListOperationOutputIds=rh,h.GlobalEventNames=Yr,h.GlobalEventState=Vn,h.HTTPOperations=Ct,h.HTTP_OPERATIONS=p0,h.InputMapDependencyField=K1,h.InputMapState=kr,h.InstalledProjectState=$i,h.InternalCallDependencyField=H1,h.InternalCallState=Cn,h.JoinListOperationInputIds=Ry,h.JoinListOperationOutputIds=by,h.LIST_OPERATIONS=Vh,h.ListOperations=ce,h.LiteralValueDependencyField=eP,h.LiteralValueState=gn,h.LoopDependencyField=J1,h.LoopState=_i,h.LoopTypes=H,h.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=xi,h.NUMBER_OPERATIONS=Lf,h.NumberOperations=Xe,h.OPERATION_DECLARATIONS=f0,h.OperationDependencyField=Z1,h.OperationState=Bi,h.OutputMapDependencyField=X1,h.OutputMapParentChildRelation=Ln,h.OutputMapState=Zr,h.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Ld,h.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=ji,h.PASS_THROUGH_CALLABLE_TYPES=nt,h.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=Yp,h.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Dp,h.ParallelExecutionOperation=AO,h.PassThroughCallableEntityClass=pJ,h.PersistedEntity=OO,h.PersistedEntityMethods=ar,h.PrimitiveEntityState=pr,h.PrimitiveTypes=M,h.ProjectState=w,h.PropertyDependencyField=j1,h.PropertyState=wi,h.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=RO,h.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=Tq,h.ReturnDeclarationDependencyField=F1,h.ReturnDeclarationState=tr,h.ReturnStatementDependencyField=gd,h.ReturnStatementState=Ci,h.STANDALONE_CONDITIONS=gE,h.STRING_OPERATIONS=Iy,h.ScopeCompatibilityType=Hd,h.SearchDependencyField=z1,h.SearchState=Si,h.SequentialExecutionOperation=PO,h.SequentialExecutionOperationInputIds=Jh,h.SequentialExecutionOperationOutputIds=Wh,h.SharedEntityErrorCode=S,h.SharedStateFunctionality=IO,h.SplitListOperationInputIds=$y,h.SplitListOperationOutputIds=Uy,h.StandaloneOperatorTypes=yr,h.StringOperations=Te,h.TERMINATION_TYPES=st,h.Traverser=Cp,h.USER_MANAGED_ENTITY_TYPES=Kp,h.UserManagedEntityStateTemplate=sJ,h.VALUE_READING_ENTITIES_EXPLANATION=Ap,h.VALUE_READING_TYPES=fi,h.VALUE_WRITING_ENTITIES_EXPLANATION=aP,h.VALUE_WRITING_TYPES=ht,h.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=bp,h.VARIABLE_TYPES=Qe,h.ValueAutogenerationType=yt,h.ValueDescriptorDependencyField=tP,h.ValueDescriptorParentChildRelation=_,h.ValueDescriptorState=Gi,h.ValueReadingEntityClass=pi,h.ValueWritingEntityClass=_s,h.VariableDeclarationDependencyField=Y1,h.VariableDeclarationState=Li,h.VariableInputMapState=aq,h.VariableInstanceDependencyField=vp,h.VariableInstanceState=Ni,h.VariableOutputMapState=dq,h.WaitOperation=DO,h.WaitOperationInputIds=Gh,h.WaitOperationOutputIds=jh,h.appendToListOperation=xs,h.appendToListOperationElementToAppendArgument=yl,h.appendToListOperationElementToAppendArgumentParentRef=bh,h.appendToListOperationElementToAppendArgumentRef=vh,h.appendToListOperationError=Oh,h.appendToListOperationErrorParentRef=Ph,h.appendToListOperationListArgument=fl,h.appendToListOperationListArgumentParentRef=Rh,h.appendToListOperationListArgumentRef=hh,h.appendToListOperationListDataType=mh,h.appendToListOperationResultListDataType=Ih,h.appendToListOperationResultListReturn=Dh,h.appendToListOperationResultListReturnParentRef=Ah,h.appendToListOperationResultListReturnRef=Eh,h.appendToListOperationSecondListDataType=Th,h.asGenerationActionExample=qr,h.booleanPrototype=zr,h.capitalizeFirstLetter=Wt,h.checkAreDataTypesCompatible=Ir,h.checkAreDefinitionEntitiesCompatibleAsDataType=V1,h.checkArePropertiesCompatibleAsDataType=O1,h.checkHasMetadataChanged=dt,h.checkIsBranchDependentButNotDirectlyOnBranch=Vs,h.checkIsBranchDependentOnBranch=Vq,h.checkIsCallableEntityReachable=Bs,h.checkIsCanvasEntity=Jq,h.checkIsDetachedBranch=fO,h.checkIsDetachedBranchShallow=xp,h.checkIsGlobalVariable=kq,h.checkIsGloballyDeclared=Fp,h.checkIsMethod=mO,h.checkIsNestedScope=zd,h.checkScopeCompatibility=gs,h.cloneProject=_J,h.countedLoopActionDescriptor=ga,h.countedLoopActionDescriptorDynamicReturnDeclaration=Yv,h.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=Wv,h.countedLoopActionDescriptorStringArgumentDeclaration=Jv,h.countedLoopActionDescriptorStringArgumentDeclarationDataType=Zv,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=xv,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=Fv,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=kv,h.countedLoopActionDescriptorStringArgumentDeclarationParentRef=qv,h.countedLoopBodyActionDescriptor=eo,h.countedLoopBodyActionDescriptorAnyDynamicArgument=Qv,h.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Xv,h.countedLoopBodyActionDescriptorAnyDynamicReturn=tT,h.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=eT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Cl,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Hv,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=zv,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Kv,h.createDefinitionEntityFromJSONObject=jd,h.createEntityError=pe,h.createNestedDataTypeForEntity=vP,h.createNewInstanceOperation=Ki,h.createNewInstanceOperationEntityToInstanciateArgument=hm,h.createNewInstanceOperationEntityToInstanciateArgumentRef=pm,h.createNewInstanceOperationEntityToInstanciateDataType=fm,h.createNewInstanceOperationError=Em,h.createNewInstanceOperationErrorParentRef=Tm,h.createNewInstanceOperationNewEntityDataArgument=cm,h.createNewInstanceOperationNewEntityDataArgumentDataType=um,h.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=lm,h.createNewInstanceOperationNewEntityDataArgumentParentRef=dm,h.createNewInstanceOperationOutputEntityDeclaration=vm,h.createNewInstanceOperationOutputEntityDeclarationParentRef=mm,h.createNewInstanceOperationRef=ym,h.createSemanticId=G1,h.createStateFromGenerationTargetType=nJ,h.createStateFromType=lt,h.createStateFromTypeAndSubscribe=O,h.cronJobBuiltInBaseEntity=ao,h.cronJobBuiltInBaseEntityExpressionProperty=PE,h.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=jO,h.cronJobBuiltInBaseEntityExpressionPropertyRef=AE,h.cronJobBuiltInBaseEntityRef=DE,h.cronJobTriggeredFunctionDeclarationBlueprint=kl,h.cronJobTriggeredFunctionDeclarationBlueprintParentRef=RE,h.dataTypeCompatibilityToErrorExplanation=fP,h.datePrototype=gr,h.dateValueAutogenerationSchema=rc,h.definitionEntityToZodSchema=lI,h.deletePersistedEntityMethod=xl,h.deletePersistedEntityMethodParentRef=sE,h.deleteRootProject=NJ,h.endpointBuiltInBaseEntity=_a,h.endpointBuiltInBaseEntityRef=oT,h.endpointBuiltInBaseEntityRefFour=xT,h.endpointBuiltInBaseEntityRefThree=mT,h.endpointBuiltInBaseEntityRefTwo=pT,h.endpointBuiltInCorsProperty=dT,h.endpointBuiltInCorsPropertyDataType=sT,h.endpointBuiltInCorsPropertyDataTypeRef=nT,h.endpointBuiltInCorsPropertyRef=aT,h.endpointBuiltInMethodProperty=Bl,h.endpointBuiltInMethodPropertyDataType=hT,h.endpointBuiltInMethodPropertyDataTypeRef=fT,h.endpointBuiltInMethodPropertyRef=yT,h.endpointBuiltInPathProperty=gl,h.endpointBuiltInPathPropertyDataType=cT,h.endpointBuiltInPathPropertyDataTypeRef=lT,h.endpointBuiltInPathPropertyRef=uT,h.endpointPathParamsArgumentDeclaration=Ml,h.endpointPathParamsArgumentDeclarationRef=OT,h.endpointPathParamsVariableDataType=VT,h.endpointPathParamsVariableDataTypeRef=PT,h.endpointReachedTriggerActionDescriptor=Gl,h.endpointReachedTriggerActionDescriptorRef=wT,h.endpointReachedTriggerActionDescriptorRefFour=BT,h.endpointReachedTriggerActionDescriptorRefThree=gT,h.endpointReachedTriggerActionDescriptorRefTwo=CT,h.endpointRequestBodyArgumentDeclaration=Ll,h.endpointRequestBodyArgumentDeclarationRef=IT,h.endpointRequestBodyVariableDataType=RT,h.endpointRequestHeadersArgumentDeclaration=_l,h.endpointRequestHeadersArgumentDeclarationRef=TT,h.endpointRequestHeadersVariableDataType=ET,h.endpointRequestHeadersVariableDataTypeRef=vT,h.endpointRequestQueryParamsArgumentDeclaration=Nl,h.endpointRequestQueryParamsArgumentDeclarationRef=AT,h.endpointRequestQueryParamsVariableDataType=DT,h.endpointRequestQueryParamsVariableDataTypeRef=bT,h.endpointResponseBodyDataType=jT,h.endpointResponseBodyReturnDeclaration=Ul,h.endpointResponseBodyReturnDeclarationRef=GT,h.endpointResponseCodeDataType=MT,h.endpointResponseCodeReturnDeclaration=Sl,h.endpointResponseCodeReturnDeclarationRef=_T,h.endpointResponseHeadersDataType=$T,h.endpointResponseHeadersDataTypeRef=LT,h.endpointResponseHeadersReturnDeclaration=$l,h.endpointResponseHeadersReturnDeclarationRef=ST,h.endpointReturnStatementRef=NT,h.endpointReturnStatementRefThree=FT,h.endpointReturnStatementRefTwo=UT,h.enrichFromKnownEntities=ws,h.enumOptionsProperty=nf,h.enumOptionsPropertyDataType=tf,h.enumOptionsPropertyDataTypeRef=Qp,h.enumOptionsPropertyRef=ef,h.enumPrototype=Hr,h.enumPrototypeRef=rf,h.executionBuiltInBaseEntity=so,h.executionBuiltInEntityAbortMethod=Zl,h.executionBuiltInEntityAbortMethodParentRef=OE,h.filterOutDuplicateEntities=u,h.filterOutDuplicateErrors=k9,h.findEntityFromKeys=gp,h.findReferenceToSelfInList=_P,h.findReferencesToSelfInProject=Sq,h.flattenActionDescriptor=MP,h.flattenArgumentDeclaration=NP,h.flattenBreakStatement=LP,h.flattenBuiltInBaseEntity=SP,h.flattenCalls=Jr,h.flattenCanvasAncestorsUntil=Fd,h.flattenCondition=$P,h.flattenContinueStatement=UP,h.flattenDataType=jP,h.flattenDefinitionEntity=GP,h.flattenDefinitionEntityExtensionAndImplementationTypes=Up,h.flattenDefinitionEntityExtensionTypes=Yd,h.flattenDefinitionEntityExtensions=Sp,h.flattenDefinitionEntityImplementations=$p,h.flattenDefinitionEntityImplementionTypes=Wd,h.flattenDerivedCanvasEntities=rr,h.flattenDetachedBranch=hO,h.flattenElementCalls=it,h.flattenElementCallsOnTheSameScope=Lq,h.flattenEntity=N,h.flattenFunctionCall=FP,h.flattenFunctionDeclaration=xP,h.flattenGlobalEvent=kP,h.flattenInputMap=ZP,h.flattenInstalledProject=qP,h.flattenInternalCall=JP,h.flattenLiteralValue=WP,h.flattenLoop=YP,h.flattenOperation=zP,h.flattenOutputMap=HP,h.flattenPrimitiveEntity=KP,h.flattenProject=XP,h.flattenProjectElements=BP,h.flattenProperty=QP,h.flattenRelatedCanvasElementsOnTheLeft=cO,h.flattenRelatedCanvasElementsOnTheRight=uO,h.flattenReturnDeclaration=eO,h.flattenReturnStatement=tO,h.flattenSearch=rO,h.flattenValueDescriptor=iO,h.flattenVariableDeclaration=nO,h.flattenVariableInstance=aO,h.flattenVariableReads=gP,h.flattenVariableWrites=CP,h.flattenVariables=We,h.fromChangeSetToRecordChangeSet=eJ,h.fromZodParseToEntityGenerationErrors=Tp,h.generate=Zw,h.generateActionExample=Eq,h.generateExecutionDataType=V7,h.generateIdFromStrategy=pt,h.generateMutablePropertiesExplanation=Bd,h.generateRandomBoolean=SI,h.generateRandomDate=fI,h.generateRandomDateAfter=uI,h.generateRandomDateBefore=cI,h.generateRandomDateBetweenRange=pI,h.generateRandomNumber=BI,h.generateRandomNumberAfter=wI,h.generateRandomNumberBefore=CI,h.generateRandomNumberBetweenRange=gI,h.generateRandomText=LI,h.generateRandomTextAfter=_I,h.generateRandomTextBefore=MI,h.generateRandomTextBetweenRange=NI,h.generateUniqueUUID=VI,h.getAllActionDescriptorsForConditions=Ud,h.getAllActionDescriptorsForGlobalEvents=Sd,h.getAllActionDescriptorsForLoops=$d,h.getAllActionDescriptorsForOperations=Aq,h.getAllBuiltInEntityIds=qd,h.getAllGloballyDeclaredFunctionDeclarationsExplanation=uP,h.getBaseBuiltInEntities=qi,h.getBaseSchemaBasedOnType=rP,h.getBuiltInEntityOwner=Ji,h.getCallableEntityReferenceSchema=Dt,h.getCallableEntityTypeSchema=yD,h.getCalledBy=cr,h.getCallerEntityReferenceSchema=W3,h.getCallerEntityTypeSchema=J3,h.getCalls=Mp,h.getCanvasEntitiesDerivedFromInternalCalls=lO,h.getCanvasEntitiesDerivedFromWrites=Ra,h.getCanvasEntityDerivedFromValueReadingEntity=Jd,h.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=dO,h.getCanvasEntityReferenceSchema=u5,h.getCanvasEntityTypeSchema=l5,h.getChildrenEntityWithValues=Cq,h.getColumnProperties=Kq,h.getCommonAncestor=_p,h.getCommonChildren=TP,h.getDatabaseEntities=zq,h.getDatabaseEntity=Xq,h.getDeclaration=Pn,h.getDeepestScope=TO,h.getDefinitionEntityExtends=ba,h.getDraggableCallableEntityReferenceSchema=mD,h.getDraggableCallableEntityTypeSchema=hD,h.getDraggableCallerEntityReferenceSchema=z3,h.getDraggableCallerEntityTypeSchema=Y3,h.getDraggableExecutableEntityReferenceSchema=Q3,h.getDraggableExecutableEntityTypeSchema=X3,h.getDraggablePassThroughCallableEntityReferenceSchema=md,h.getDraggablePassThroughCallableEntityTypeSchema=hd,h.getDraggablePlayableEntityReferenceSchema=n5,h.getDraggablePlayableEntityTypeSchema=i5,h.getEntityArgumentDeclarations=Lp,h.getEntityInputMaps=sO,h.getEntityOutputMaps=jq,h.getEntityReferenceSchema=d5,h.getEntityReturnDeclarations=oO,h.getEntityTypeSchema=o5,h.getEntityWithLogicScopeReferenceSchema=di,h.getEntityWithLogicScopeTypeSchema=e5,h.getEntityWithValueReferenceSchema=fD,h.getEntityWithValueTypeSchema=q3,h.getEntryPointEntityReferenceSchema=bt,h.getEntryPointEntityTypeSchema=Pi,h.getEventEntityReferenceSchema=fd,h.getEventEntityTypeSchema=pd,h.getExecutableEntityReferenceSchema=K3,h.getExecutableEntityTypeSchema=H3,h.getExtendedBuiltInEntity=Fq,h.getExtendedDefinitionEntity=Gp,h.getGenerationTargetSchemaBasedOnType=iP,h.getHeadIfPartOfDetachedBranch=yO,h.getHighestScope=vO,h.getImplementedBuiltInEntity=xq,h.getIsInteractive=jp,h.getLastInListOperation=pl,h.getLastInListOperationError=ph,h.getLastInListOperationErrorParentRef=ch,h.getLastInListOperationInputListArgument=dh,h.getLastInListOperationInputListArgumentParentRef=oh,h.getLastInListOperationInputListArgumentRef=ih,h.getLastInListOperationInputListDataType=nh,h.getLastInListOperationOutputElementDataType=sh,h.getLastInListOperationOutputElementReturn=uh,h.getLastInListOperationOutputElementReturnParentRef=lh,h.getLastInListOperationOutputElementReturnRef=ah,h.getLinkedEntitiesFromArgumentDeclaration=Nq,h.getLowestPersistedEntityImplementation=pO,h.getParentCallableEntity=EP,h.getParentCallerEntity=RP,h.getParentCanvasEntities=Yt,h.getParentCanvasEntity=Vt,h.getParentCanvasEntityFromTransfer=xd,h.getParentEntryPoint=wq,h.getParentPassthroughCallableEntity=IP,h.getPassThroughCallableEntityReferenceSchema=et,h.getPassThroughCallableEntityTypeSchema=yd,h.getPeristedEntities=Yq,h.getPlayableEntityReferenceSchema=r5,h.getPlayableEntityTypeSchema=t5,h.getProject=MJ,h.getPrototypeByType=Cs,h.getReferenceEntityId=g,h.getReferencedEntitiesStateOrErrors=Md,h.getReferencedEntityStateOrErrors=Ep,h.getReferencedIds=Zd,h.getRelatedCanvasElementsOnTheLeft=Bn,h.getRelatedCanvasElementsOnTheLeftFromTransfer=$q,h.getRelatedCanvasElementsOnTheRight=Zi,h.getRootEntryPointScopeOwner=kp,h.getScopeOwner=zt,h.getStateClassFromType=Qq,h.getTerminationReferenceSchema=s5,h.getTerminationTypeSchema=a5,h.getUsedArgFromDeclaration=Uq,h.getUsedReturnFromDeclaration=Gq,h.getValueReadingEntityReferenceSchema=pD,h.getValueReadingEntityTypeSchema=oi,h.getValueWritingEntityReferenceSchema=Z3,h.getValueWritingEntityTypeSchema=hs,h.getVariableFromInputMapping=AP,h.getVariableFromReturnVariablePointer=OP,h.getVariableReferenceSchema=Di,h.getVariableTypeSchema=En,h.getVariablesFromArgumentDeclarations=kd,h.getVariablesFromInputMaps=DP,h.getVariablesFromOutputMapping=VP,h.getVariablesFromOutputMaps=wP,h.getVariablesFromReturnDeclarations=PP,h.getVariablesInSameOrHigherScope=op,h.getWrites=Np,h.groupCallsBasedOnParallelizableExecution=Bq,h.handleAfterEntityImplementationSideEffects=mP,h.handleBeforeEntityImplementationSideEffects=hP,h.httpRequestBodyArgument=Js,h.httpRequestBodyArgumentRef=qm,h.httpRequestBodyDataType=Jm,h.httpRequestHeadersArgument=qs,h.httpRequestHeadersArgumentRef=km,h.httpRequestHeadersDataType=Zm,h.httpRequestMethodArgument=ks,h.httpRequestMethodArgumentRef=Fm,h.httpRequestMethodDataType=xm,h.httpRequestMethodDataTypeRef=Gm,h.httpRequestOperation=Oa,h.httpRequestOperationErrorValueDescriptor=Il,h.httpRequestOperationErrorValueDescriptorDatatype=c0,h.httpRequestOperationErrorValueDescriptorRef=u0,h.httpRequestOperationRef=s0,h.httpRequestOperationRefEight=d0,h.httpRequestOperationRefFive=n0,h.httpRequestOperationRefFour=i0,h.httpRequestOperationRefNine=l0,h.httpRequestOperationRefSeven=o0,h.httpRequestOperationRefSix=a0,h.httpRequestOperationRefThree=r0,h.httpRequestOperationRefTwo=t0,h.httpRequestQueryParamsArgument=El,h.httpRequestQueryParamsArgumentRef=$m,h.httpRequestQueryParamsDataType=Um,h.httpRequestVariableURLArgument=Zs,h.httpRequestVariableURLArgumentRef=Lm,h.httpRequestVariableURLDataType=Sm,h.httpRequestVariableURLDataTypeRef=Mm,h.httpResponseBodyReturnDataType=e0,h.httpResponseBodyReturnDataTypeRef=Xm,h.httpResponseBodyReturnReturn=zs,h.httpResponseBodyReturnReturnRef=Qm,h.httpResponseCodeDataType=Ym,h.httpResponseCodeReturn=Ws,h.httpResponseCodeReturnRef=Wm,h.httpResponseHeadersDataType=Km,h.httpResponseHeadersDataTypeRef=zm,h.httpResponseHeadersReturn=Ys,h.httpResponseHeadersReturnRef=Hm,h.implement=Gd,h.inferArgumentDeclarationDataType=w1,h.inferDataType=xr,h.inferInputMapDataType=np,h.inferOutputMapDataType=sp,h.inferPropertyDataType=B1,h.inferReturnDeclarationDataType=ap,h.inferValueDescriptorDataType=_1,h.inferVariableDeclarationDataType=g1,h.inferVariableInstanceDataType=C1,h.initBaseProjectEntity=qp,h.initProject=VO,h.isPromise=wp,h.iterateOverListActionDescriptorListArgumentDeclaration=q0,h.iterateOverListActionDescriptorListArgumentDeclarationDataType=k0,h.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=x0,h.iterateOverListActionDescriptorListArgumentDeclarationParentRef=Z0,h.iterateOverListLoopActionDescriptor=yi,h.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=W0,h.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=J0,h.iterateOverListLoopBodyActionDescriptor=Ca,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=rv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=tv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=nv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=iv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Qs,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=z0,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Y0,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=H0,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=ev,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=X0,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=K0,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Q0,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=lv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=ov,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=sv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=dv,h.iterateOverObjectKeysLoopActionDescriptor=jn,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=cv,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=uv,h.iterateOverObjectKeysLoopBodyActionDescriptor=Pl,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=Iv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Ev,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=bv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Rv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Dl,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=fv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=pv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=yv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Tv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=mv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=hv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=vv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=Vv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Pv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Dv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Ov,h.iterateOverObjectValuesLoopActionDescriptor=Fn,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Cv,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=wv,h.iterateOverObjectValuesLoopBodyActionDescriptor=Vl,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Uv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$v,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=jv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Gv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ol,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Bv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=gv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=_v,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Sv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Nv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Mv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Lv,h.iterateOverStringActionDescriptorDynamicReturnDeclaration=g0,h.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=C0,h.iterateOverStringActionDescriptorStringArgumentDeclaration=w0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=O0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=P0,h.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=V0,h.iterateOverStringLoopActionDescriptor=wa,h.iterateOverStringLoopBodyActionDescriptor=Xs,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=U0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=j0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=G0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=bl,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=_0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=B0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=M0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Al,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=L0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=N0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=S0,h.joinListOperation=ll,h.joinListOperationError=Sy,h.joinListOperationErrorParentRef=Ly,h.joinListOperationFirstListArgument=gy,h.joinListOperationFirstListArgumentParentRef=Cy,h.joinListOperationFirstListArgumentRef=Ay,h.joinListOperationFirstListDataType=Dy,h.joinListOperationResultListDataType=wy,h.joinListOperationResultListReturn=Ny,h.joinListOperationResultListReturnParentRef=My,h.joinListOperationResultListReturnRef=Vy,h.joinListOperationSecondListArgument=_y,h.joinListOperationSecondListArgumentParentRef=By,h.joinListOperationSecondListArgumentRef=Py,h.joinListOperationSecondListDataType=Oy,h.joinListWithLastSeparator=re,h.joinStringsOperation=Pa,h.joinStringsOperationDynamicStringArgument=ry,h.joinStringsOperationDynamicStringArgumentParentRef=ty,h.joinStringsOperationDynamicStringArgumentRef=Qf,h.joinStringsOperationDynamicStringDataType=ey,h.joinStringsOperationError=Xf,h.joinStringsOperationErrorParentRef=Kf,h.joinStringsOperationFirstStringArgument=js,h.joinStringsOperationFirstStringArgumentParentRef=xf,h.joinStringsOperationFirstStringArgumentRef=Sf,h.joinStringsOperationFirstStringDataType=$f,h.joinStringsOperationResultStringDataType=Ff,h.joinStringsOperationResultStringReturn=Da,h.joinStringsOperationResultStringReturnParentRef=Hf,h.joinStringsOperationResultStringReturnRef=jf,h.joinStringsOperationSecondStringArgument=Fs,h.joinStringsOperationSecondStringArgumentParentRef=zf,h.joinStringsOperationSecondStringArgumentRef=Uf,h.joinStringsOperationSecondStringDataType=Gf,h.joinStringsOperationSeparatorStringArgument=Yf,h.joinStringsOperationSeparatorStringArgumentParentRef=Wf,h.joinStringsOperationSeparatorStringArgumentRef=kf,h.joinStringsOperationSeparatorStringDataType=Jf,h.joinStringsOperationSeparatorStringDataTypeDefaultValue=qf,h.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=Zf,h.keyValuePrototype=$n,h.lowercaseFirstLetter=Dd,h.manualFlowActionDescriptorDeclarationArgumentDeclaration=Rl,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=T0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=v0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=E0,h.manualFlowLoopActionDescriptor=Hs,h.manualFlowLoopActionDescriptorDynamicReturnDeclaration=m0,h.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=h0,h.manualFlowLoopBodyActionDescriptor=Ks,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=R0,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=I0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=A0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=b0,h.mapActionDescriptorToTypeItRepresents=Wq,h.mergeEntityErrorsList=Z9,h.mergeListOfEntities=Zq,h.methodDefaultValue=jm,h.mockClientProject=xA,h.moreThanOrEqualCondition=Jn,h.moreThanOrEqualConditionLeftHandArgument=NE,h.moreThanOrEqualConditionLeftHandArgumentDataType=_E,h.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=BE,h.moreThanOrEqualConditionLeftHandArgumentParentRef=ME,h.moreThanOrEqualConditionRightHandArgument=UE,h.moreThanOrEqualConditionRightHandArgumentDataType=SE,h.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=LE,h.moreThanOrEqualConditionRightHandArgumentParentRef=$E,h.notEmptyCondition=nn,h.notEmptyConditionArgument=CE,h.notEmptyConditionRef=wE,h.nullPrototype=Xp,h.numberAdditionOperation=Gs,h.numberAdditionOperationDynamicSummandArgument=Tf,h.numberAdditionOperationDynamicSummandArgumentType=vf,h.numberAdditionOperationDynamicSummandArgumentTypeParentRef=mf,h.numberAdditionOperationError=hf,h.numberAdditionOperationErrorParentRef=yf,h.numberAdditionOperationFirstNumberArgument=rl,h.numberAdditionOperationFirstNumberArgumentRef=sf,h.numberAdditionOperationFirstNumberDataType=of,h.numberAdditionOperationRef=pf,h.numberAdditionOperationRefThree=nl,h.numberAdditionOperationRefTwo=ff,h.numberAdditionOperationResultNumberDataType=cf,h.numberAdditionOperationResultNumberReturn=al,h.numberAdditionOperationResultNumberReturnRef=uf,h.numberAdditionOperationSecondNumberArgument=il,h.numberAdditionOperationSecondNumberArgumentRef=df,h.numberAdditionOperationSecondNumberDataType=lf,h.numberPrototype=he,h.numberSubtractionOperation=ol,h.numberSubtractionOperationDynamicSubtrahendArgument=Nf,h.numberSubtractionOperationDynamicSubtrahendArgumentType=Mf,h.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=_f,h.numberSubtractionOperationError=Bf,h.numberSubtractionOperationErrorParentRef=gf,h.numberSubtractionOperationFirstNumberArgument=Pf,h.numberSubtractionOperationFirstNumberArgumentRef=Ef,h.numberSubtractionOperationFirstNumberDataType=If,h.numberSubtractionOperationRef=sl,h.numberSubtractionOperationRefThree=wf,h.numberSubtractionOperationRefTwo=Of,h.numberSubtractionOperationResultNumberDataType=Df,h.numberSubtractionOperationResultNumberReturn=Cf,h.numberSubtractionOperationResultNumberReturnRef=Af,h.numberSubtractionOperationSecondNumberArgument=Vf,h.numberSubtractionOperationSecondNumberArgumentRef=Rf,h.numberSubtractionOperationSecondNumberDataType=bf,h.numberValueAutogenerationSchema=tc,h.parallelExecutionOperation=br,h.parallelExecutionOperationError=Uh,h.parallelExecutionOperationErrorParentRef=$h,h.parallelExecutionOperationListOfExecutionResultsDataType=Nh,h.parallelExecutionOperationListOfExecutionResultsReturn=ml,h.parallelExecutionOperationListOfExecutionResultsReturnRef=Mh,h.parallelExecutionOperationListOfFunctionsArgument=hl,h.parallelExecutionOperationListOfFunctionsArgumentDatatype=_h,h.parallelExecutionOperationListOfFunctionsArgumentRef=Bh,h.parallelExecutionOperationListOfFunctionsBlueprint=gh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Ch,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=wh,h.parallelExecutionOperationRef=Lh,h.parallelExecutionOperationRefThree=Sh,h.persistedBuiltInBaseEntity=Pt,h.persistedBuiltInBaseEntityDatabaseProperty=kn,h.persistedBuiltInBaseEntityDatabasePropertyDataType=lE,h.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=UO,h.persistedBuiltInBaseEntityDatabasePropertyParentRef=uE,h.persistedBuiltInBaseEntityDatabasePropertyRef=dE,h.persistedBuiltInBaseEntityPrimaryKeyProperty=Zn,h.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=TE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=pE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=cE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=EE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=vE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=yE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=fE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=mE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=hE,h.processOutputGlobalValueDescriptorDataType=qE,h.processOutputGlobalValueDescriptorReturn=lo,h.processOutputGlobalValueDescriptorReturnRef=ZE,h.projectPublicationCompletedGlobalEvent=oo,h.propertyToZodSchema=dI,h.relationalDatabaseBuiltInBaseEntity=Mr,h.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Fl,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=nE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=iE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=aE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=rE,h.relationalDatabaseBuiltInBaseEntityDefaultProperty=jl,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=tE,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=QT,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=eE,h.relationalDatabaseBuiltInBaseEntityIdentifierProperty=to,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=qT,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=kT,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=ZT,h.relationalDatabaseBuiltInBaseEntityMinSizeProperty=no,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=XT,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=HT,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=KT,h.relationalDatabaseBuiltInBaseEntityPasswordProperty=io,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=zT,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=$O,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=YT,h.relationalDatabaseBuiltInBaseEntityRef=xn,h.relationalDatabaseBuiltInBaseEntityUsernameProperty=ro,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=WT,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=SO,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=JT,h.resolveActionDescriptorName=U1,h.resolveBaseEntityName=N1,h.resolveBuiltInBaseEntityDataTypeLabel=L1,h.resolveClonedEntityProject=ft,h.resolveConditionOperatorLabel=wd,h.resolveDataType=Pd,h.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Bp,h.resolveDataTypeLabel=Vd,h.resolveDefinitionEntityDataTypeLabel=_7,h.resolveEntityDataTypeLabel=B7,h.resolveEntityName=U,h.resolveFirstCallsSecond=_q,h.resolveFirstWritesSecond=Mq,h.resolvePrimaryKeyProperty=Hq,h.resolvePrimitiveEntityName=$1,h.resolveSearchName=S1,h.resolveVariableScope=w7,h.sequentialExecutionOperation=Qr,h.sequentialExecutionOperationError=nm,h.sequentialExecutionOperationErrorParentRef=im,h.sequentialExecutionOperationListOfExecutionResultsDataType=em,h.sequentialExecutionOperationListOfExecutionResultsReturn=Tl,h.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=rm,h.sequentialExecutionOperationListOfExecutionResultsReturnRef=Qh,h.sequentialExecutionOperationListOfFunctionsArgument=vl,h.sequentialExecutionOperationListOfFunctionsArgumentDatatype=Xh,h.sequentialExecutionOperationListOfFunctionsArgumentParentRef=tm,h.sequentialExecutionOperationListOfFunctionsArgumentRef=Kh,h.sequentialExecutionOperationListOfFunctionsBlueprint=Hh,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=zh,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=Yh,h.softDeletePersistedEntityMethod=GO,h.softDeletePersistedEntityMethodParentRef=IE,h.sortCallsBasedOnExecutionDependencies=bP,h.sortChildrenEntitiesBasedOnExecutionDependencies=gq,h.splitListOperation=cl,h.splitListOperationError=eh,h.splitListOperationErrorParentRef=Qy,h.splitListOperationFirstOutputListDataType=ky,h.splitListOperationFirstOutputListReturn=zy,h.splitListOperationFirstOutputListReturnParentRef=Yy,h.splitListOperationFirstOutputListReturnRef=ul,h.splitListOperationInputListArgument=qy,h.splitListOperationInputListArgumentParentRef=Zy,h.splitListOperationInputListArgumentRef=Gy,h.splitListOperationInputListDataType=jy,h.splitListOperationSecondOutputListDataType=Hy,h.splitListOperationSecondOutputListReturn=Xy,h.splitListOperationSecondOutputListReturnParentRef=Ky,h.splitListOperationSplitIndexArgument=Wy,h.splitListOperationSplitIndexArgumentParentRef=Jy,h.splitListOperationSplitIndexArgumentRef=Fy,h.splitListOperationSplitIndexDataType=xy,h.splitStringOperation=dl,h.splitStringOperationError=Ey,h.splitStringOperationErrorParentRef=Ty,h.splitStringOperationFirstPartResultStringDataType=dy,h.splitStringOperationFirstPartResultStringReturn=vy,h.splitStringOperationFirstPartResultStringReturnParentRef=my,h.splitStringOperationFirstPartResultStringReturnRef=oy,h.splitStringOperationIndexArgument=yy,h.splitStringOperationIndexArgumentParentRef=fy,h.splitStringOperationIndexArgumentRef=ay,h.splitStringOperationIndexDataType=sy,h.splitStringOperationSecondPartResultStringDataType=uy,h.splitStringOperationSecondPartResultStringReturn=NO,h.splitStringOperationSecondPartResultStringReturnParentRef=hy,h.splitStringOperationSecondPartResultStringReturnRef=ly,h.splitStringOperationStringArgument=py,h.splitStringOperationStringArgumentParentRef=cy,h.splitStringOperationStringArgumentRef=iy,h.splitStringOperationStringDataType=ny,h.stringPrototype=ie,h.stringValueAutogenerationSchema=ec,h.suggestNewIdForEntity=fp,h.test_primitive_entities_export=LJ,h.toCamelCase=C7,h.toEntityState=ir,h.toKebabCase=M1,h.toLowerCaseKebabCase=Od,h.toPascalCase=g7,h.untypedDataPrototype=At,h.updateErrorsList=Ye,h.updateValueReader=qq,h.urlDefaultValue=Nm,h.uuidPrototype=Kr,h.validateArgumentDeclarationName=cp,h.validateCalledByErrorIdInAction=Rq,h.validateCalledByIdInAction=Iq,h.validateCallers=lP,h.validateConditionEntityDeclaration=Dq,h.validateDataOperation=Xi,h.validateDataOperationDataToValidateArgument=Am,h.validateDataOperationDataToValidateArgumentParentRef=bm,h.validateDataOperationDataToValidateArgumentRef=Im,h.validateDataOperationDataToValidateDataType=Rm,h.validateDataOperationEntityToMatchTypeArgument=Vm,h.validateDataOperationEntityToMatchTypeArgumentParentRef=Om,h.validateDataOperationEntityToMatchTypeArgumentRef=Dm,h.validateDataOperationEntityToMatchTypeDataType=Pm,h.validateDataOperationError=Bm,h.validateDataOperationErrorParentRef=gm,h.validateDataOperationOutputEntityDeclaration=Cm,h.validateDataOperationOutputEntityDeclarationParentRef=wm,h.validateDefinitionEntityName=Cd,h.validateEntryCaller=dP,h.validateErrorCaller=oP,h.validateFunctionCallDeclaration=cP,h.validateFunctionDeclarationName=dp,h.validateGeneratedEntityParentIsNotBuiltInEntity=mq,h.validateGeneration=yq,h.validateGenerationTarget=ot,h.validateGenerationUpdate=hq,h.validateLoopEntityDeclaration=Pq,h.validateName=M7,h.validateOperationEntityDeclaration=pP,h.validatePropertyName=up,h.validateReachability=ci,h.validateReadsValueInActionPayload=bq,h.validateReferenceObject=_d,h.validateReferenceToOne=Ip,h.validateReferences=It,h.validateReturnDeclarationName=pp,h.validateSuccessCaller=sP,h.validateValueReaderGenerationUpdate=Os,h.validateValueWritter=Op,h.validateVariableDeclarationName=lp,h.validateVariableInternalCallUse=Vp,h.valueAutogenerationCurrentDateAndTimeSchema=qA,h.valueAutogenerationGenericSchema=Ko,h.valueAutogenerationOptions=ic,h.valueAutogenerationOptionsSchema=ZA,h.valueAutogenerationRandomBooleanSchema=Qu,h.valueAutogenerationRandomDateBetweenSchema=eD,h.valueAutogenerationRandomDateFromSchema=XA,h.valueAutogenerationRandomDateSchema=ed,h.valueAutogenerationRandomDateUntilSchema=QA,h.valueAutogenerationRandomNumberBetweenSchema=YA,h.valueAutogenerationRandomNumberFromSchema=JA,h.valueAutogenerationRandomNumberSchema=Xo,h.valueAutogenerationRandomNumberUntilSchema=WA,h.valueAutogenerationRandomSchema=ds,h.valueAutogenerationRandomTextBetweenSchema=KA,h.valueAutogenerationRandomTextFromSchema=zA,h.valueAutogenerationRandomTextSchema=Qo,h.valueAutogenerationRandomTextUntilSchema=HA,h.valueAutogenerationRangeValueTypesSchema=os,h.valueAutogenerationUniqueSchema=Xu,h.waitOperation=jt,h.waitOperationMillisecondsNumberArgument=Hi,h.waitOperationMillisecondsNumberArgumentRef=Fh,h.waitOperationMillisecondsNumberDataType=xh,h.waitOperationOperationError=qh,h.waitOperationOperationErrorParentRef=Zh,h.waitOperationRef=kh,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});