@elyx-code/project-logic-tree 0.0.6239 → 0.0.6241

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.
@@ -54,10 +54,10 @@ ${g}`,issue:null}))}}}}return s.push(...l.errors,...o,...pt(i)),{errors:s,modifi
54
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:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}propagateChanges(){const e=[this],t=[],i=[],s=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const l=this.parent.parent,{updated:o,added:d,removed:u}=l.syncChildren();e.push(...o),t.push(...d),i.push(...u)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return Rr.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.required=e.required!==void 0?e.required:this.required,this.isError=e.isError!==void 0?e.isError:this.isError,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.getCounterparts();d.length&&d.forEach(u=>{if(!(t!=null&&t.hasRemoved(u.id))){const{updated:y,removed:c,added:E,affected:I}=u.remove({ignoreUpstream:e},t);i.push(...y),s.push(...c),l.push(...E),o.push(...I)}})}return!e&&this.parent&&this.parent.removeOutputDeclaration(this,t),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);i.push(...o.updated)}return this.parent&&this.parent.addOutputDeclaration(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...((l=this.dataType)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatIds(e))||[],...((l=this.dataType)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;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:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y,c,E;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,readsValue:((E=this.readsValue)==null?void 0:E.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatJSON(e))||[],...((l=this.dataType)==null?void 0:l.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 i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.dataType)==null?void 0:l.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=s1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(E=this.dataType)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(I=this.defaultValue)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type"))){var i;const t=Tc(this,e);if(t&&t.parent===this)this.dataType&&this.dataType.merge(t,e);else if(t&&t.parent!==this)if(this.dataType)this.dataType.merge(t,e);else{const s=t.clone(e,this);e==null||e.add(s,b.Added),this.setDataType(s)}return(i=this.dataType)==null||i.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(l=>l.outputs).filter(l=>x(l,this.project)===x(this,this.project)&&l.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const i=this.parent.parent.returnStatements.flatMap(s=>s.outputs);this.implements?e=i.filter(l=>{var o;return this.implements.id===((o=l.implements)==null?void 0:o.id)}):e=i.filter(l=>x(l,this.project)===x(this,this.project)&&l.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var s,l,o;const t=this.getCounterparts(),i=t.find(d=>{var u;return(u=d.dataType)==null?void 0:u.isResolved});if(i)this.setDataType(i.dataType),e==null||e.add(this,b.Updated);else for(let d=0;d<t.length;d++){const u=t[d];if((!u.dataType||!u.dataType.isResolved||(s=u.dataType)!=null&&s.inferred)&&u.readsValue&&u.inferDataType(e),(l=u.dataType)!=null&&l.isResolved){this.setDataType(u.dataType),e==null||e.add(this,b.Updated);break}}return(o=this.dataType)==null||o.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return(!this.dataType||!this.dataType.isResolved||(t=this.dataType)!=null&&t.inferred)&&this.readsValue?this.inferDataType(e):this.inferDataTypeFromCounterparts(e),this.dataType}};f(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(be,"type",n.ReturnDeclaration),f(be,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),f(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES]),f(be,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),f(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),f(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),f(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),f(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),f(be,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),f(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let ei=be;function o1(r){var s;const a=I5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const VJ=Object.freeze(Object.defineProperty({__proto__:null,validate:o1},Symbol.toStringTag,{value:"Module"}));function l1(r){var s;const a=m5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const BJ=Object.freeze(Object.defineProperty({__proto__:null,validate:l1},Symbol.toStringTag,{value:"Module"}));var Vc=(r=>(r.Parent="parent",r))(Vc||{});const Fe=class Fe extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.ContinueStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),o=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),d=e.calledByError.map(c=>{const E=_(c);return t.get(E)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Fe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Fe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),throws:((u=this.throws)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:((y=this.parent)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.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)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.calledBy.flatMap(s=>s.toFlatJSON(e)),...((i=this.throws)==null?void 0:i.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(i=>i.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=l1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.outputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=E,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Fe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Fe,"type",n.ContinueStatement),f(Fe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),f(Fe,"MUTABLE_BASE_PROPERTIES",[]),f(Fe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Fe,"BASE_PROPERTIES",[...Fe.MUTABLE_BASE_PROPERTIES,...Fe.INMUTABLE_BASE_PROPERTIES]),f(Fe,"MUTABLE_META_PROPERTIES",["x","y"]),f(Fe,"INMUTABLE_META_PROPERTIES",[...Fe.INMUTABLE_BASE_PROPERTIES]),f(Fe,"META_PROPERTIES",[...Fe.MUTABLE_META_PROPERTIES,...Fe.INMUTABLE_META_PROPERTIES]),f(Fe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Fe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Fe,"UPSTREAM_PROPERTIES",[...Fe.MUTABLE_UPSTREAM_PROPERTIES,...Fe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Fe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Fe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Fe,"DOWNSTREAM_PROPERTIES",[...Fe.MUTABLE_DOWNSTREAM_PROPERTIES,...Fe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Fe,"PROPERTIES",[...Fe.META_PROPERTIES,...Fe.UPSTREAM_PROPERTIES,...Fe.DOWNSTREAM_PROPERTIES]);let Ut=Fe;var Gl=(r=>(r.Parent="parent",r))(Gl||{});const st=class st extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.ReturnStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),o=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),d=e.calledByError.map(c=>{const E=_(c);return t.get(E)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:ut}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Fe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Fe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),throws:((u=this.throws)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:((y=this.parent)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.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)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.calledBy.flatMap(s=>s.toFlatJSON(e)),...((i=this.throws)==null?void 0:i.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(i=>i.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=l1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.outputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=E,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Fe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Fe,"type",n.ContinueStatement),f(Fe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),f(Fe,"MUTABLE_BASE_PROPERTIES",[]),f(Fe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Fe,"BASE_PROPERTIES",[...Fe.MUTABLE_BASE_PROPERTIES,...Fe.INMUTABLE_BASE_PROPERTIES]),f(Fe,"MUTABLE_META_PROPERTIES",["x","y"]),f(Fe,"INMUTABLE_META_PROPERTIES",[...Fe.INMUTABLE_BASE_PROPERTIES]),f(Fe,"META_PROPERTIES",[...Fe.MUTABLE_META_PROPERTIES,...Fe.INMUTABLE_META_PROPERTIES]),f(Fe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Fe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Fe,"UPSTREAM_PROPERTIES",[...Fe.MUTABLE_UPSTREAM_PROPERTIES,...Fe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Fe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Fe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Fe,"DOWNSTREAM_PROPERTIES",[...Fe.MUTABLE_DOWNSTREAM_PROPERTIES,...Fe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Fe,"PROPERTIES",[...Fe.META_PROPERTIES,...Fe.UPSTREAM_PROPERTIES,...Fe.DOWNSTREAM_PROPERTIES]);let Ut=Fe;var Gl=(r=>(r.Parent="parent",r))(Gl||{});const st=class st extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.ReturnStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),o=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),d=e.calledByError.map(c=>{const E=_(c);return t.get(E)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:ut}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new st(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new st(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:y}=this.syncReturnDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),l.push(...y),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await st.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await st.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await st.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await st.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await st.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await st.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.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(i=>i.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=o1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.outputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=E,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncReturnDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-return-declarations"))){const t=[],i=[],s=[],l=[],o=It(this,this.project);return o.implements?(o.implements.outputs.filter(y=>!this.outputs.find(c=>{var E;return((E=c.implements)==null?void 0:E.id)===y.id})).forEach(y=>{const c=y.implementAsReturnDeclaration(e,this);i.push(c)}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}):(e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this})}};f(st,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(st,"type",n.ReturnStatement),f(st,"USER_MANAGED_PARENT_TYPES",[...ut]),f(st,"PARENT_TYPES",[...st.USER_MANAGED_PARENT_TYPES]),f(st,"MUTABLE_BASE_PROPERTIES",[]),f(st,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(st,"BASE_PROPERTIES",[...Ut.MUTABLE_BASE_PROPERTIES,...Ut.INMUTABLE_BASE_PROPERTIES]),f(st,"MUTABLE_META_PROPERTIES",["x","y"]),f(st,"INMUTABLE_META_PROPERTIES",[...Ut.INMUTABLE_BASE_PROPERTIES]),f(st,"META_PROPERTIES",[...Ut.MUTABLE_META_PROPERTIES,...Ut.INMUTABLE_META_PROPERTIES]),f(st,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(st,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(st,"UPSTREAM_PROPERTIES",[...Ut.MUTABLE_UPSTREAM_PROPERTIES,...Ut.INMUTABLE_UPSTREAM_PROPERTIES]),f(st,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(st,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(st,"DOWNSTREAM_PROPERTIES",[...Ut.MUTABLE_DOWNSTREAM_PROPERTIES,...Ut.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(st,"PROPERTIES",[...ei.META_PROPERTIES,...ei.UPSTREAM_PROPERTIES,...ei.DOWNSTREAM_PROPERTIES]);let Fr=st;function d1(r){const a=m7(),e=r.toJSON();a.safeParse(e).success;const i=_J(r),s=MJ(r),l=ui(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return Ke(r.errors,o)}function _J(r){const a=[];if(!r.calls.length){const e=de({id:`${r.id}--${F.ScopeWithoutLogic}`,message:`Action "${x(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:D.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function MJ(r){const a=[];return r.implements,Ke(r.errors,a)}const NJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.Implements="implements",r))(u1||{});const Re=class Re extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"private");f(this,"index",null);f(this,"type",n.FunctionDeclaration);f(this,"implements",null);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s=null;if(e.implements){const d=_(e.implements);s=t.get(d)}const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=bc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const E=d,O=qt(E).filter(P=>!P.interactive);if(O.length){let P=O.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(O.map(V=>x(V,V.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(O[0],O[0].project)}").`;P+=`
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new st(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new st(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:y}=this.syncReturnDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),l.push(...y),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await st.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await st.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await st.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await st.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await st.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await st.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.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(i=>i.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=o1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.outputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=E,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncReturnDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-return-declarations"))){const t=[],i=[],s=[],l=[],o=It(this,this.project);return o.implements?(o.implements.outputs.filter(y=>!this.outputs.find(c=>{var E;return((E=c.implements)==null?void 0:E.id)===y.id})).forEach(y=>{const c=y.implementAsReturnDeclaration(e,this);i.push(c)}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}):(e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this})}};f(st,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(st,"type",n.ReturnStatement),f(st,"USER_MANAGED_PARENT_TYPES",[...ut]),f(st,"PARENT_TYPES",[...st.USER_MANAGED_PARENT_TYPES]),f(st,"MUTABLE_BASE_PROPERTIES",[]),f(st,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(st,"BASE_PROPERTIES",[...Ut.MUTABLE_BASE_PROPERTIES,...Ut.INMUTABLE_BASE_PROPERTIES]),f(st,"MUTABLE_META_PROPERTIES",["x","y"]),f(st,"INMUTABLE_META_PROPERTIES",[...Ut.INMUTABLE_BASE_PROPERTIES]),f(st,"META_PROPERTIES",[...Ut.MUTABLE_META_PROPERTIES,...Ut.INMUTABLE_META_PROPERTIES]),f(st,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(st,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(st,"UPSTREAM_PROPERTIES",[...Ut.MUTABLE_UPSTREAM_PROPERTIES,...Ut.INMUTABLE_UPSTREAM_PROPERTIES]),f(st,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(st,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(st,"DOWNSTREAM_PROPERTIES",[...Ut.MUTABLE_DOWNSTREAM_PROPERTIES,...Ut.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(st,"PROPERTIES",[...ei.META_PROPERTIES,...ei.UPSTREAM_PROPERTIES,...ei.DOWNSTREAM_PROPERTIES]);let Fr=st;function d1(r){const a=m7(),e=r.toJSON();a.safeParse(e).success;const i=_J(r),s=MJ(r),l=ui(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return Ke(r.errors,o)}function _J(r){const a=[];if(!r.calls.length){const e=de({id:`${r.id}--${F.ScopeWithoutLogic}`,message:`Action "${x(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:D.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function MJ(r){const a=[];return r.implements,Ke(r.errors,a)}const NJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.Implements="implements",r))(u1||{});const Re=class Re extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"private");f(this,"index",null);f(this,"type",n.FunctionDeclaration);f(this,"implements",null);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s=null;if(e.implements){const d=_(e.implements);s=t.get(d)}const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=bc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const E=d,O=qt(E).filter(P=>!P.interactive);if(O.length){let P=O.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(O.map(V=>x(V,V.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${E.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(O[0],O[0].project)}").`;P+=`
61
61
  ${rn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:P,issue:null}))}else{const P=E.methods.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===i.implements});P&&s.push(new w({id:`${i.id}--${$.MethodOverwritesOtherSiblingWithSameImplementation}`,code:$.MethodOverwritesOtherSiblingWithSameImplementation,severity:D.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is trying to implement the '${n.ActionDescriptor}' with id "${i.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${P.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.
@@ -79,14 +79,14 @@ All built-in 'action-descriptor' entity ids are:
79
79
  `;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:D.Error,message:`Entity of type "${n.Operation}" with id "${i.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'.${d}`,issue:null}))}return{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:E}=this.syncMissingFixedOutputs(e),{updated:I,added:O,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...y,...I),i.push(...d,...c,...I),s.push(...u,...E,...I),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&i.setParent(this.parent,null);return i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=c1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.outputs.filter(c=>c.parentRelationType===N.FixedReturns&&!this.outputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.outputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.outputs.forEach(O=>{O.index>=c.index&&O.index++});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:c.toJSON(),defaultValue:null,writesValues:[],index:c.index,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e)}),this.outputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Oe,"type",n.Operation),f(Oe,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),f(Oe,"MUTABLE_BASE_PROPERTIES",[]),f(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),f(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let Zr=Oe;function y1(r){const a=xZ(),e=r.toJSON();a.safeParse(e).success;const i=ui(r);r.inputs.forEach(l=>l.validate()),i.forEach(l=>l.validate());const s=[];return Ke(r.errors,s)}const gJ=Object.freeze(Object.defineProperty({__proto__:null,validate:y1},Symbol.toStringTag,{value:"Module"})),Pe=class Pe extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"type",n.GlobalEvent);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"implements");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s;e.implements&&(s=t.getBuiltIn(e.implements));const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{},t);if(i=l.modifiedData,s.push(...l.errors,...pt(i)),!e.implements)s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:E}=this.syncMissingFixedOutputs(e),{updated:I,added:O,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...y,...I),i.push(...d,...c,...I),s.push(...u,...E,...I),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&i.setParent(this.parent,null);return i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=c1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.outputs.filter(c=>c.parentRelationType===N.FixedReturns&&!this.outputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id}));this.outputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.outputs.forEach(O=>{O.index>=c.index&&O.index++});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:c.toJSON(),defaultValue:null,writesValues:[],index:c.index,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e)}),this.outputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Oe,"type",n.Operation),f(Oe,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),f(Oe,"MUTABLE_BASE_PROPERTIES",[]),f(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),f(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let Zr=Oe;function y1(r){const a=xZ(),e=r.toJSON();a.safeParse(e).success;const i=ui(r);r.inputs.forEach(l=>l.validate()),i.forEach(l=>l.validate());const s=[];return Ke(r.errors,s)}const gJ=Object.freeze(Object.defineProperty({__proto__:null,validate:y1},Symbol.toStringTag,{value:"Module"})),Pe=class Pe extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"type",n.GlobalEvent);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"implements");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s;e.implements&&(s=t.getBuiltIn(e.implements));const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{},t);if(i=l.modifiedData,s.push(...l.errors,...pt(i)),!e.implements)s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.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
  ${Jl(t)}`,issue:null}));else if(!t.get(e.implements))s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.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
  ${Jl(t)}`,issue:null}));else if(!t.globalEventActionDescriptors.find(u=>u.id===e.implements))s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.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
  ${Jl(t)}`,issue:null}));else{const u=t.events.find(y=>y.implements.id===e.implements);u&&s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.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 '${u.id}' in the project. Each global event must implement a unique action descriptor.
86
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:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Gl.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 w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Zt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Zt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${Zt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${Zt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,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,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);if(i.addEntryCaller(this,null),i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e));return i}),this.implements=C(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Pe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),ui(this).forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...y),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),ui(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ui(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,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=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,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(u=>u.toJSONClone({...e,newId:null})),calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,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(s=>s.toReference(e)),calls:this.calls.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.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=y1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ui(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[];const y=u.split("-id"),c=y[y.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const E=nt(d,o);t?E.setParent(t,null):E.setParent(this.parent,null),s&&E.subscribe(),E.initChildren(e),e==null||e.add(E,b.Added);const I=(P=this.inputs)==null?void 0:P.map((V,M)=>V.clone(e,E,c+"-argument-declaration-"+M+"-id",s));return E.inputs=I,l?(ui(this).map((V,M)=>V.clone(e,E,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),E):(e==null||e.attemptAutoclose("clone-entity",this.id),E)}getVariableInstances(){return He(this).filter(i=>i.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}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Pe,"type",n.GlobalEvent),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES]),f(Pe,"MUTABLE_BASE_PROPERTIES",["description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let qr=Pe;function h1(r){var s;const a=C5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const GJ=Object.freeze(Object.defineProperty({__proto__:null,validate:h1},Symbol.toStringTag,{value:"Module"}));var _c=(r=>(r.Parent="parent",r))(_c||{});const xe=class xe extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.BreakStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),o=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),d=e.calledByError.map(c=>{const E=_(c);return t.get(E)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.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})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.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(i=>i.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=h1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.outputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=E,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(xe,"type",n.BreakStatement),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Jr=xe;function Mc(r){var l,o;const a=c5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(l=r.error)==null||l.validate(),(o=r.body)==null||o.validate();const s=[...Ar(r)];return Ke(r.errors,s)}function FJ(r){return Mc(r)}const xJ=Object.freeze(Object.defineProperty({__proto__:null,validate:Mc,validateListLoop:FJ},Symbol.toStringTag,{value:"Module"}));function m1(r){const a=ED(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return Ke(r.errors,i)}const kJ=Object.freeze(Object.defineProperty({__proto__:null,validate:m1},Symbol.toStringTag,{value:"Module"}));var v1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(v1||{});const we=class we extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"implementation",null);f(this,"parent",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=_(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},l=C(s,t);return i&&l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=l.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const d=o,y=qt(d).filter(c=>!c.interactive);if(y.length){let c=y.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(y.map(E=>x(E,E.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(y[0],y[0].project)}").`;c+=`
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.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})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,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:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.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(i=>i.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=h1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.outputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=E,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(xe,"type",n.BreakStatement),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Jr=xe;function Mc(r){var l,o;const a=c5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(l=r.error)==null||l.validate(),(o=r.body)==null||o.validate();const s=[...Ar(r)];return Ke(r.errors,s)}function FJ(r){return Mc(r)}const xJ=Object.freeze(Object.defineProperty({__proto__:null,validate:Mc,validateListLoop:FJ},Symbol.toStringTag,{value:"Module"}));function m1(r){const a=ED(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return Ke(r.errors,i)}const kJ=Object.freeze(Object.defineProperty({__proto__:null,validate:m1},Symbol.toStringTag,{value:"Module"}));var v1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(v1||{});const we=class we extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"implementation",null);f(this,"parent",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=_(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},l=C(s,t);return i&&l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=l.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const d=o,y=qt(d).filter(c=>!c.interactive);if(y.length){let c=y.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(y.map(E=>x(E,E.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(y[0],y[0].project)}").`;c+=`
90
90
  ${rn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:c,issue:null}))}}else if(o&&o.type===n.DataType){const d=o;d.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.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
  ${Qi({describe_entity:d.entity.id})}
@@ -96,19 +96,19 @@ ${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}
96
96
  ${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.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
  ${Sl(t)}`,issue:null})),{errors:s,modifiedData:i}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${x(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 '${x(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===Vc.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===_c.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 w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===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,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=C(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];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:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.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 i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Mc(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.body&&(c.body=this.body.clone(e,c,y+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?He(this.body).filter(i=>i.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(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||x(d,this.project)===x(l,this.project)&&wi(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const y=u.outputs,c=o.filter(E=>!y.find(I=>x(E,this.project)===x(I,this.project)&&wi(E.dataType,I.dataType)));c.length&&(t.push(u),e==null||e.add(u,b.Updated)),c.forEach(E=>{const I=E.clone(e,u);e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const y=this.getUniqueReturnDeclarations(),c=this.body.inputs;y.sort((P,V)=>P.index-V.index),y.forEach(P=>{const V=P.getDataType(e);let g=c.find(pe=>x(pe,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&wi(pe.dataType,P.dataType));if(!g){const pe=oe.fromReturnDeclarationToBodyArgumentDeclarationName(P),Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:pe,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},Q=C(Ee,this.project);Q.setParent(this.body,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),i.push(Q),g=Q}const B=this.body.inputs.find(pe=>pe.index===g.index&&pe!==g),G=this.body.inputs.filter(pe=>pe!==g);let q=g.index;B&&(q=Math.max(...G.map(pe=>pe.index))+1),g.index!==q&&(g.metaSync({index:q},e),t.push(g));const W=g.getDataType(e);let X=W;if(V)if(!W||!wi(W,V)){if(!X){const Ee=V.clone(e,g);e==null||e.add(Ee,b.Added),Ee.addSelfToProject(e),X=Ee,i.push(Ee),t.push(g)}const pe=X.merge(V,e);pe.self===X?V.remove({ignoreUpstream:!1},e):pe.self===V&&(X.remove({ignoreUpstream:!1},e),X=V),X.metaSync({isList:!0},e)}else X.isList||(X.metaSync({isList:!0},e),t.push(X));if(!V&&!X){const pe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},Ee=C(pe,this.project);Ee.metaSync({isList:!0},e),Ee.setParent(g,e),Ee.initChildren(e),e==null||e.add(Ee,b.Added),Ee.addSelfToProject(e),i.push(Ee)}});const{updated:E,added:I,removed:O}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...E),i.push(...I),s.push(...O),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;return o.forEach((y,c)=>{y.index!==c&&(y.metaSync({index:c},e),t.push(y))}),o.forEach(y=>{const c=y.getDataType(e);let I=d.find(V=>x(V,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(y)&&wi(V.dataType,y.dataType));if(!I){const V=oe.fromReturnDeclarationToLoopOutputDeclarationName(y),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:V,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(y,this.project)}'`,defaultValue:null,dataType:null,index:y.index,required:y.required,parentRelationType:N.FixedReturns,parent:this.toReference()},g=C(M,this.project);g.setParent(this,e),g.initChildren(e),e==null||e.add(g,b.Added),g.addSelfToProject(e),i.push(g),I=g}I.index!==y.index&&(I.metaSync({index:y.index},e),t.push(I));let P=I.getDataType(e);if(c)if(!P||!wi(P,c)){if(!P){const M=c.clone(e,I);e==null||e.add(M,b.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(I)}const V=P.merge(c,e);V.self===P?c.remove({ignoreUpstream:!1},e):V.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const V={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:I.toReference()},M=C(V,this.project);M.metaSync({isList:!0},e),M.setParent(I,e),M.initChildren(e),e==null||e.add(M,b.Added),M.addSelfToProject(e),i.push(M)}}),d.filter(y=>!o.find(E=>x(y,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(E))).forEach(y=>{const{updated:c,removed:E}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(y=>{var I;let E=d.find(O=>{var P,V;return((P=O.declaration)==null?void 0:P.id)===y.id&&wi((V=O.declaration)==null?void 0:V.dataType,y.dataType)});if(E)((I=E.declaration)==null?void 0:I.id)!==y.id&&(E.setDeclaration(y),t.push(E));else{const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:y.index,declaration:y.toJSON(),writesValues:[],parent:this.toReference()},P=C(O,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,b.Added),P.addSelfToProject(e),i.push(P),E=P}E.index!==y.index&&(E.metaSync({index:y.index},e),t.push(E))}),d.filter(y=>!o.find(E=>{var I;return((I=y.declaration)==null?void 0:I.id)===E.id})).forEach(y=>{const{updated:c,removed:E}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(E=>{var I;return E.name===oe.CURRENT_ITERATION_NUMBER_ARG_NAME||E.id===((I=this.currentIterationNumberArgumentDeclaration)==null?void 0:I.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},I=C(E,this.project);I.setParent(this.body,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I),d=I}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},I=C(E,this.project);I.setParent(d,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I),c=I}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==L.Number||c.entity.id!==k["primitive-entity"].number.id){const E=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(E),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(y=>y===this.currentIterationNumberArgumentDeclaration||y===this.currentValueArgumentDeclaration?!1:!d.find(E=>x(y,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(E))).forEach(y=>{const{updated:c,removed:E}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var y,c,E,I,O;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.List].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.List].inputs.list.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(!G){const W={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},X=C(W,this.project);X.setParent(g,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),i.push(X),G=X}const q=V.getDataType(e);G.merge(q,e),G.metaSync({isList:!1},e)}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case ee.Counted:{this.currentValueArgumentDeclaration=null;break}case ee.ObjectKeys:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((y=G.entity)==null?void 0:y.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},W=C(q,this.project);W.setParent(g,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),G=W}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ObjectValues:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].inputs.object.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=V.getDataType(e),W=((E=q==null?void 0:q.entity)==null?void 0:E.properties)||[];(I=G.orChildrenGroup)==null||I.forEach(X=>{const{updated:pe,removed:Ee}=X.remove({ignoreUpstream:!1},e);t.push(...pe),s.push(...Ee)}),W.forEach(X=>{if(!X.getDataType(e)){const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:G.toReference()},Q=C(Ee,this.project);Q.setParent(G,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),i.push(Q)}})}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},W=C(q,this.project);W.setParent(g,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),G=W;const X=V.getDataType(e);(((c=X==null?void 0:X.entity)==null?void 0:c.properties)||[]).forEach(Ee=>{if(!Ee.getDataType(e)){const le={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:W.toReference()},ri=C(le,this.project);ri.setParent(W,e),ri.initChildren(e),e==null||e.add(ri,b.Added),ri.addSelfToProject(e),i.push(ri)}})}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.String:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.String].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((O=G.entity)==null?void 0:O.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},W=C(q,this.project);W.setParent(g,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),i.push(W),G=W}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:E}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...y),i.push(...c),s.push(...E),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case ee.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=C(y,this.project);c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:E}=this.syncInputMaps(e);t.push(...y),i.push(...c),s.push(...E);const{updated:I,added:O,removed:P}=this.syncTerminationStatements(e);t.push(...I),i.push(...O),s.push(...P);const{updated:V,added:M,removed:g}=this.syncBodyArgumentsDeclarations(e);t.push(...V),i.push(...M),s.push(...g);const{updated:B,added:G,removed:q}=this.syncBodyInputIndexes(e);t.push(...B),i.push(...G),s.push(...q);const{updated:W,added:X,removed:pe}=this.syncOutputsDeclarations(e);t.push(...W),i.push(...X),s.push(...pe);const{updated:Ee,added:Q,removed:le}=this.syncOutputMaps(e);return t.push(...Ee),i.push(...Q),s.push(...le),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};f(oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(oe,"type",n.Loop),f(oe,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(oe,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(oe,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(oe,"CURRENT_VALUE_ARG_NAME","Current value"),f(oe,"MUTABLE_BASE_PROPERTIES",[]),f(oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(oe,"BASE_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"MUTABLE_META_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(oe,"INMUTABLE_META_PROPERTIES",[...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"META_PROPERTIES",[...oe.MUTABLE_META_PROPERTIES,...oe.INMUTABLE_META_PROPERTIES]),f(oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(oe,"UPSTREAM_PROPERTIES",[...oe.MUTABLE_UPSTREAM_PROPERTIES,...oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(oe,"DOWNSTREAM_PROPERTIES",[...oe.MUTABLE_DOWNSTREAM_PROPERTIES,...oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(oe,"PROPERTIES",[...oe.META_PROPERTIES,...oe.UPSTREAM_PROPERTIES,...oe.DOWNSTREAM_PROPERTIES]);let Sr=oe;function E1(r){const a=x5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...Ar(r)];return Ke(r.errors,s)}const ZJ=Object.freeze(Object.defineProperty({__proto__:null,validate:E1},Symbol.toStringTag,{value:"Module"}));var I1=(r=>(r.Parent="parent",r))(I1||{});const ke=class ke extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Condition);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"declaration");f(this,"inputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d;if(e.declaration){const c=_(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===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,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=C(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];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:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.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 i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Mc(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.body&&(c.body=this.body.clone(e,c,y+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?He(this.body).filter(i=>i.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(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||x(d,this.project)===x(l,this.project)&&wi(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const y=u.outputs,c=o.filter(E=>!y.find(I=>x(E,this.project)===x(I,this.project)&&wi(E.dataType,I.dataType)));c.length&&(t.push(u),e==null||e.add(u,b.Updated)),c.forEach(E=>{const I=E.clone(e,u);e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const y=this.getUniqueReturnDeclarations(),c=this.body.inputs;y.sort((P,V)=>P.index-V.index),y.forEach(P=>{const V=P.getDataType(e);let g=c.find(pe=>x(pe,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&wi(pe.dataType,P.dataType));if(!g){const pe=oe.fromReturnDeclarationToBodyArgumentDeclarationName(P),Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:pe,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},Q=C(Ee,this.project);Q.setParent(this.body,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),i.push(Q),g=Q}const B=this.body.inputs.find(pe=>pe.index===g.index&&pe!==g),G=this.body.inputs.filter(pe=>pe!==g);let q=g.index;B&&(q=Math.max(...G.map(pe=>pe.index))+1),g.index!==q&&(g.metaSync({index:q},e),t.push(g));const W=g.getDataType(e);let X=W;if(V)if(!W||!wi(W,V)){if(!X){const Ee=V.clone(e,g);e==null||e.add(Ee,b.Added),Ee.addSelfToProject(e),X=Ee,i.push(Ee),t.push(g)}const pe=X.merge(V,e);pe.self===X?V.remove({ignoreUpstream:!1},e):pe.self===V&&(X.remove({ignoreUpstream:!1},e),X=V),X.metaSync({isList:!0},e)}else X.isList||(X.metaSync({isList:!0},e),t.push(X));if(!V&&!X){const pe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},Ee=C(pe,this.project);Ee.metaSync({isList:!0},e),Ee.setParent(g,e),Ee.initChildren(e),e==null||e.add(Ee,b.Added),Ee.addSelfToProject(e),i.push(Ee)}});const{updated:E,added:I,removed:O}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...E),i.push(...I),s.push(...O),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;return o.forEach((y,c)=>{y.index!==c&&(y.metaSync({index:c},e),t.push(y))}),o.forEach(y=>{const c=y.getDataType(e);let I=d.find(V=>x(V,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(y)&&wi(V.dataType,y.dataType));if(!I){const V=oe.fromReturnDeclarationToLoopOutputDeclarationName(y),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:V,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(y,this.project)}'`,defaultValue:null,dataType:null,index:y.index,required:y.required,parentRelationType:N.FixedReturns,parent:this.toReference()},g=C(M,this.project);g.setParent(this,e),g.initChildren(e),e==null||e.add(g,b.Added),g.addSelfToProject(e),i.push(g),I=g}I.index!==y.index&&(I.metaSync({index:y.index},e),t.push(I));let P=I.getDataType(e);if(c)if(!P||!wi(P,c)){if(!P){const M=c.clone(e,I);e==null||e.add(M,b.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(I)}const V=P.merge(c,e);V.self===P?c.remove({ignoreUpstream:!1},e):V.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const V={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:I.toReference()},M=C(V,this.project);M.metaSync({isList:!0},e),M.setParent(I,e),M.initChildren(e),e==null||e.add(M,b.Added),M.addSelfToProject(e),i.push(M)}}),d.filter(y=>!o.find(E=>x(y,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(E))).forEach(y=>{const{updated:c,removed:E}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(y=>{var I;let E=d.find(O=>{var P,V;return((P=O.declaration)==null?void 0:P.id)===y.id&&wi((V=O.declaration)==null?void 0:V.dataType,y.dataType)});if(E)((I=E.declaration)==null?void 0:I.id)!==y.id&&(E.setDeclaration(y),t.push(E));else{const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:y.index,declaration:y.toJSON(),writesValues:[],parent:this.toReference()},P=C(O,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,b.Added),P.addSelfToProject(e),i.push(P),E=P}E.index!==y.index&&(E.metaSync({index:y.index},e),t.push(E))}),d.filter(y=>!o.find(E=>{var I;return((I=y.declaration)==null?void 0:I.id)===E.id})).forEach(y=>{const{updated:c,removed:E}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(E=>{var I;return E.name===oe.CURRENT_ITERATION_NUMBER_ARG_NAME||E.id===((I=this.currentIterationNumberArgumentDeclaration)==null?void 0:I.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},I=C(E,this.project);I.setParent(this.body,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I),d=I}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},I=C(E,this.project);I.setParent(d,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I),c=I}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==L.Number||c.entity.id!==k["primitive-entity"].number.id){const E=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(E),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(y=>y===this.currentIterationNumberArgumentDeclaration||y===this.currentValueArgumentDeclaration?!1:!d.find(E=>x(y,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(E))).forEach(y=>{const{updated:c,removed:E}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...E)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var y,c,E,I,O;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.List].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.List].inputs.list.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(!G){const W={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},X=C(W,this.project);X.setParent(g,e),X.initChildren(e),e==null||e.add(X,b.Added),X.addSelfToProject(e),i.push(X),G=X}const q=V.getDataType(e);G.merge(q,e),G.metaSync({isList:!1},e)}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case ee.Counted:{this.currentValueArgumentDeclaration=null;break}case ee.ObjectKeys:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((y=G.entity)==null?void 0:y.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},W=C(q,this.project);W.setParent(g,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),G=W}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.ObjectValues:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].body.inputs.currentValue.id}),V=this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.ObjectValues].inputs.object.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop][ee.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=V.getDataType(e),W=((E=q==null?void 0:q.entity)==null?void 0:E.properties)||[];(I=G.orChildrenGroup)==null||I.forEach(X=>{const{updated:pe,removed:Ee}=X.remove({ignoreUpstream:!1},e);t.push(...pe),s.push(...Ee)}),W.forEach(X=>{if(!X.getDataType(e)){const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:G.toReference()},Q=C(Ee,this.project);Q.setParent(G,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),i.push(Q)}})}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},W=C(q,this.project);W.setParent(g,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),G=W;const X=V.getDataType(e);(((c=X==null?void 0:X.entity)==null?void 0:c.properties)||[]).forEach(Ee=>{if(!Ee.getDataType(e)){const le={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Pt.OrDataTypeGroup,parent:W.toReference()},ri=C(le,this.project);ri.setParent(W,e),ri.initChildren(e),e==null||e.add(ri,b.Added),ri.addSelfToProject(e),i.push(ri)}})}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case ee.String:{const P=this.body.inputs.find(g=>{var B;return((B=g.implements)==null?void 0:B.id)===k[n.Loop][ee.String].body.inputs.currentValue.id});if(!this.inputs.find(g=>{var B;return((B=g.declaration)==null?void 0:B.id)===k[n.Loop][ee.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const g=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let G=P.getDataType(e);if(G){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((O=G.entity)==null?void 0:O.id)!==q.id&&(G.setEntity(q),t.push(G))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:g.toReference()},W=C(q,this.project);W.setParent(g,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),i.push(W),G=W}}else{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(g,this.project);B.setParent(this.body,e),B.initChildren(e),e==null||e.add(B,b.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:E}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...y),i.push(...c),s.push(...E),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case ee.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}case ee.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),i.push(y)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=C(y,this.project);c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:E}=this.syncInputMaps(e);t.push(...y),i.push(...c),s.push(...E);const{updated:I,added:O,removed:P}=this.syncTerminationStatements(e);t.push(...I),i.push(...O),s.push(...P);const{updated:V,added:M,removed:g}=this.syncBodyArgumentsDeclarations(e);t.push(...V),i.push(...M),s.push(...g);const{updated:B,added:G,removed:q}=this.syncBodyInputIndexes(e);t.push(...B),i.push(...G),s.push(...q);const{updated:W,added:X,removed:pe}=this.syncOutputsDeclarations(e);t.push(...W),i.push(...X),s.push(...pe);const{updated:Ee,added:Q,removed:le}=this.syncOutputMaps(e);return t.push(...Ee),i.push(...Q),s.push(...le),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};f(oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(oe,"type",n.Loop),f(oe,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(oe,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(oe,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(oe,"CURRENT_VALUE_ARG_NAME","Current value"),f(oe,"MUTABLE_BASE_PROPERTIES",[]),f(oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(oe,"BASE_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"MUTABLE_META_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(oe,"INMUTABLE_META_PROPERTIES",[...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"META_PROPERTIES",[...oe.MUTABLE_META_PROPERTIES,...oe.INMUTABLE_META_PROPERTIES]),f(oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(oe,"UPSTREAM_PROPERTIES",[...oe.MUTABLE_UPSTREAM_PROPERTIES,...oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(oe,"DOWNSTREAM_PROPERTIES",[...oe.MUTABLE_DOWNSTREAM_PROPERTIES,...oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(oe,"PROPERTIES",[...oe.META_PROPERTIES,...oe.UPSTREAM_PROPERTIES,...oe.DOWNSTREAM_PROPERTIES]);let Sr=oe;function E1(r){const a=x5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...Ar(r)];return Ke(r.errors,s)}const ZJ=Object.freeze(Object.defineProperty({__proto__:null,validate:E1},Symbol.toStringTag,{value:"Module"}));var I1=(r=>(r.Parent="parent",r))(I1||{});const ke=class ke extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Condition);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"declaration");f(this,"inputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d;if(e.declaration){const c=_(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.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
  ${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.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
  ${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.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
  ${Wl(t)}`,issue:null})),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Zt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Zt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===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,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await ke.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),this.parent.type===n.Project&&this.project.addCondition(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){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=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.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=E1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.inputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-input-map-"+P+"-id",s));return c.inputs=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ke,"type",n.Condition),f(ke,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),f(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),f(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"MUTABLE_META_PROPERTIES",["x","y"]),f(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),f(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),f(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),f(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let Wr=ke;function A1(r){var o;const a=PZ(),e=r.toJSON();a.safeParse(e).success,(o=r.dataType)==null||o.validate(),r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),r.internalCalls.forEach(d=>d.validate());const s=[...Ar(r)];if(r.id==="random-company-employee-test-variable-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const qJ=Object.freeze(Object.defineProperty({__proto__:null,validate:A1},Symbol.toStringTag,{value:"Module"}));function b1(r){const a=_Z(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),r.internalCalls.forEach(o=>o.validate());const s=[...Ar(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const JJ=Object.freeze(Object.defineProperty({__proto__:null,validate:b1},Symbol.toStringTag,{value:"Module"}));var Nc=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(Nc||{});const Ce=class Ce extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.VariableInstance);f(this,"defaultValue",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const I=_(e.parent);i=t.get(I)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const O=_(I);return t.get(O)}),d=e.calledBySuccess.map(I=>{const O=_(I);return t.get(O)}),u=e.calledByError.map(I=>{const O=_(I);return t.get(O)});let y=null;if(e.readsValue){const I=_(e.readsValue);y=t.get(I)}const c={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:y,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},E=C(c,t);return E.setParent(i,null),E.initChildren(null),E}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Zt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${Zt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===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,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await ke.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),this.parent.type===n.Project&&this.project.addCondition(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){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=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.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=E1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(I=this.inputs)==null?void 0:I.map((O,P)=>O.clone(e,c,y+"-input-map-"+P+"-id",s));return c.inputs=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ke,"type",n.Condition),f(ke,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),f(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),f(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"MUTABLE_META_PROPERTIES",["x","y"]),f(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),f(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),f(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),f(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let Wr=ke;function A1(r){var o;const a=PZ(),e=r.toJSON();a.safeParse(e).success,(o=r.dataType)==null||o.validate(),r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),r.internalCalls.forEach(d=>d.validate());const s=[...Ar(r)];if(r.id==="random-company-employee-test-variable-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const qJ=Object.freeze(Object.defineProperty({__proto__:null,validate:A1},Symbol.toStringTag,{value:"Module"}));function b1(r){const a=_Z(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),r.internalCalls.forEach(o=>o.validate());const s=[...Ar(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=Zc(r);return s.push(...l),Ke(r.errors,s)}const JJ=Object.freeze(Object.defineProperty({__proto__:null,validate:b1},Symbol.toStringTag,{value:"Module"}));var Nc=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(Nc||{});const Ce=class Ce extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.VariableInstance);f(this,"defaultValue",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const I=_(e.parent);i=t.get(I)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const O=_(I);return t.get(O)}),d=e.calledBySuccess.map(I=>{const O=_(I);return t.get(O)}),u=e.calledByError.map(I=>{const O=_(I);return t.get(O)});let y=null;if(e.readsValue){const I=_(e.readsValue);y=t.get(I)}const c={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:y,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},E=C(c,t);return E.setParent(i,null),E.initChildren(null),E}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{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=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:G,updated:q,removed:W,affected:X}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...G),t.push(...q),s.push(...W),l.push(...X)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),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,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}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(i=>!(e.find(o=>o.id===i.id)||e.find(o=>o.declaration===i.declaration)))}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(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=C(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,e),i}),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.internalCalls=this.initialData.internalCalls.reduce((t,i)=>{if(i.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(i);if(!s)return t;const l=s;return l.setParent(this,null),[...t,l]}else{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(e),[...t,s]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ce.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e))])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(s=>s.toFlatIds(e)),...this.successCalls.flatMap(s=>s.toFlatIds(e)),...this.errorCalls.flatMap(s=>s.toFlatIds(e)),...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.outputs.flatMap(s=>s.toFlatIds(e)),...this.internalCalls.flatMap(s=>s.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((i=this.readsValue)==null?void 0:i.toReference())||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),internalCalls:this.internalCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((y=this.readsValue)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),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})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.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)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.declaration)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e)),...this.calledBy.flatMap(l=>l.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 i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.declaration)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.readsValue)==null?void 0:l.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=b1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(s=>s.getErrors()),...this.internalCalls.flatMap(s=>s.getErrors()),...this.outputs.flatMap(s=>s.getErrors()),...((i=this.readsValue)==null?void 0:i.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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(O=this.defaultValue)==null?void 0:O.clone(e,u,m.UUID.uuid(),s);u.defaultValue=y||null;const c=(P=this.inputs)==null?void 0:P.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const E=(V=this.outputs)==null?void 0:V.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=E;const I=(M=this.internalCalls)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=I,e==null||e.attemptAutoclose("clone-entity",this.id),u}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,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];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(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.declaration.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];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(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];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(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return((t=this.declaration)==null?void 0:t.getDataType(e))||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)}};f(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ce,"type",n.VariableInstance),f(Ce,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES]),f(Ce,"MUTABLE_BASE_PROPERTIES",[]),f(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),f(Ce,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let zr=Ce;var R1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(R1||{});const Ve=class Ve extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"required",!1);f(this,"constant",!1);f(this,"x");f(this,"y");f(this,"type",n.VariableDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:"",description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d=null;if(e.readsValue){const c=_(e.readsValue);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:s,calledBySuccess:l,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);i=l.modifiedData;const o=Rc(i,t);return s.push(...l.errors,...o,...pt(i)),{errors:s,modifiedData:i}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Nc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{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=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:G,updated:q,removed:W,affected:X}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...G),t.push(...q),s.push(...W),l.push(...X)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),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,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}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(i=>!(e.find(o=>o.id===i.id)||e.find(o=>o.declaration===i.declaration)))}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(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=C(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,e),i}),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.internalCalls=this.initialData.internalCalls.reduce((t,i)=>{if(i.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(i);if(!s)return t;const l=s;return l.setParent(this,null),[...t,l]}else{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(e),[...t,s]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ce.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e))])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(s=>s.toFlatIds(e)),...this.successCalls.flatMap(s=>s.toFlatIds(e)),...this.errorCalls.flatMap(s=>s.toFlatIds(e)),...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.outputs.flatMap(s=>s.toFlatIds(e)),...this.internalCalls.flatMap(s=>s.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((i=this.readsValue)==null?void 0:i.toReference())||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),internalCalls:this.internalCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((y=this.readsValue)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),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})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.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)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.declaration)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e)),...this.calledBy.flatMap(l=>l.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 i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.declaration)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.readsValue)==null?void 0:l.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=b1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(s=>s.getErrors()),...this.internalCalls.flatMap(s=>s.getErrors()),...this.outputs.flatMap(s=>s.getErrors()),...((i=this.readsValue)==null?void 0:i.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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(O=this.defaultValue)==null?void 0:O.clone(e,u,m.UUID.uuid(),s);u.defaultValue=y||null;const c=(P=this.inputs)==null?void 0:P.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const E=(V=this.outputs)==null?void 0:V.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=E;const I=(M=this.internalCalls)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=I,e==null||e.attemptAutoclose("clone-entity",this.id),u}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,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];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(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.declaration.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];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(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];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(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return((t=this.declaration)==null?void 0:t.getDataType(e))||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)}};f(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ce,"type",n.VariableInstance),f(Ce,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES]),f(Ce,"MUTABLE_BASE_PROPERTIES",[]),f(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),f(Ce,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let zr=Ce;var R1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(R1||{});const Ve=class Ve extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"required",!1);f(this,"constant",!1);f(this,"x");f(this,"y");f(this,"type",n.VariableDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:"",description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const E=_(c);return t.get(E)}),l=e.calledBySuccess.map(c=>{const E=_(c);return t.get(E)}),o=e.calledByError.map(c=>{const E=_(c);return t.get(E)});let d=null;if(e.readsValue){const c=_(e.readsValue);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:s,calledBySuccess:l,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);i=l.modifiedData;const o=Rc(i,t);return s.push(...l.errors,...o,...pt(i)),{errors:s,modifiedData:i}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Nc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.dataType||this.dataType.inferred){const{added:B,updated:G,removed:q,affected:W}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...G),s.push(...q),l.push(...W)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),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,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}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,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>x(s,this.project)===x(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,g,B,G;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=C({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,b.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const W=(g=this.dataType)==null?void 0:g.merge(q,e);this.dataType&&(W==null?void 0:W.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((B=W==null?void 0:W.self)==null?void 0:B.id)&&q.remove({ignoreUpstream:!1},e),W!=null&&W.self&&(W.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(W.self,b.Added),this.setDataType(W.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(X=>x(X,this.project)===x(q,this.project))||d.push(q)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if((G=this.dataType)==null||G.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:y,removed:c,affected:E}=this.generateUnusedInputs(e);t.push(...y),i.push(...u),s.push(...c),l.push(...E);const{updated:I,added:O,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...O),i.push(...I),s.push(...P),l.push(...V),this.variableInstances.forEach(q=>{const{updated:W,added:X,removed:pe,affected:Ee}=q.generateUnusedInputs(e);t.push(...X),i.push(...W),s.push(...pe),l.push(...Ee);const{updated:Q,added:le,removed:ri,affected:tr}=q.generateUnusedOutputs(e);t.push(...le),i.push(...Q),s.push(...ri),l.push(...tr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(E=>E.toJSONClone({...e,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...e,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(E=>E.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(E=>this.calledBy.length||this.readsValue?E.toJSONClone({...e,newId:null}):E.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.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)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=A1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const E=(M=this.inputs)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=E;const I=(g=this.outputs)==null?void 0:g.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const O=(B=this.internalCalls)==null?void 0:B.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.setParent(e,null),l.initChildren(null),t==null||t.add(l,b.Added),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];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(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),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)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Yr=Ve;function D1(r){var l;const a=J5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Ar(r)];if(r.id==="search-person-by-id-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:D1},Symbol.toStringTag,{value:"Module"}));var O1=(r=>(r.Parent="parent",r))(O1||{});const We=class We extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const y=_(e.parent);i=t.get(y)}const s=e.calledByEntry.map(y=>{const c=_(y);return t.get(c)}),l=e.calledBySuccess.map(y=>{const c=_(y);return t.get(c)}),o=e.calledByError.map(y=>{const c=_(y);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=C(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Rr.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:E,removed:I,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...E),s.push(...I),l.push(...O);const{added:P,updated:V,removed:M,affected:g}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...g),!this.dataType||this.dataType.inferred){const{added:B,updated:G,removed:q,affected:W}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...G),s.push(...q),l.push(...W)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),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,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}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,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,b.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,b.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),xa.initWritesValues(this,this.parent),Rr.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,b.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>x(s,this.project)===x(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,g,B,G;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=C({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,b.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const W=(g=this.dataType)==null?void 0:g.merge(q,e);this.dataType&&(W==null?void 0:W.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((B=W==null?void 0:W.self)==null?void 0:B.id)&&q.remove({ignoreUpstream:!1},e),W!=null&&W.self&&(W.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(W.self,b.Added),this.setDataType(W.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(X=>x(X,this.project)===x(q,this.project))||d.push(q)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if((G=this.dataType)==null||G.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:y,removed:c,affected:E}=this.generateUnusedInputs(e);t.push(...y),i.push(...u),s.push(...c),l.push(...E);const{updated:I,added:O,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...O),i.push(...I),s.push(...P),l.push(...V),this.variableInstances.forEach(q=>{const{updated:W,added:X,removed:pe,affected:Ee}=q.generateUnusedInputs(e);t.push(...X),i.push(...W),s.push(...pe),l.push(...Ee);const{updated:Q,added:le,removed:ri,affected:tr}=q.generateUnusedOutputs(e);t.push(...le),i.push(...Q),s.push(...ri),l.push(...tr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=J){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(E=>E.toJSONClone({...e,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...e,newId:null})),outputs:this.outputs.map(E=>E.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(E=>E.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(E=>E.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(E=>this.calledBy.length||this.readsValue?E.toJSONClone({...e,newId:null}):E.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(E=>E.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.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)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=A1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=nt(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,b.Added);const y=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const E=(M=this.inputs)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=E;const I=(g=this.outputs)==null?void 0:g.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const O=(B=this.internalCalls)==null?void 0:B.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toReference(),x:0,y:0},l=C(s,this.project);return l.hydrateAncestors(),l.setParent(e,t),t==null||t.add(l,b.Added),l.addSelfToProject(t),l.initChildren(t),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];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(c=>!c.getDataType(e)).forEach(c=>{const E=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!E)return;const I=this.getMasterInputWithValueWritterFromAllInstances(E);if(!I)return;const O=ji(I);c.setDataType(O),E.setDeclaration(c)}),o.filter(c=>!this.inputs.find(E=>{var I;return((I=E.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=C(E,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const E=o.find(I=>x(I,this.project)===x(c,this.project));E&&c.setDeclaration(E)})}}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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,b.Added),c.suggestion=!0,this.addOutput(c,e),c});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,O,P,V,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,b.Added),y.suggestion=!0,this.addInternalCall(y),y});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:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),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)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Yr=Ve;function D1(r){var l;const a=J5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Ar(r)];if(r.id==="search-person-by-id-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return Ke(r.errors,s)}const SJ=Object.freeze(Object.defineProperty({__proto__:null,validate:D1},Symbol.toStringTag,{value:"Module"}));var O1=(r=>(r.Parent="parent",r))(O1||{});const We=class We extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const y=_(e.parent);i=t.get(y)}const s=e.calledByEntry.map(y=>{const c=_(y);return t.get(c)}),l=e.calledBySuccess.map(y=>{const c=_(y);return t.get(c)}),o=e.calledByError.map(y=>{const c=_(y);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=C(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ut,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new We(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new We(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===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,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,b.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,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),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await We.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await We.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await We.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await We.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await We.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await We.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}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(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,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})),inputsDeclarations:this.inputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.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=D1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(V=this.inputsDeclarations)==null?void 0:V.map((G,q)=>G.clone(e,this,y+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=E;const I=(M=this.outputsDeclarations)==null?void 0:M.map((G,q)=>G.clone(e,this,y+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const O=(g=this.inputs)==null?void 0:g.map((G,q)=>G.clone(e,c,y+"-input-map-"+q+"-id",s));c.inputs=O;const P=(B=this.outputs)==null?void 0:B.map((G,q)=>G.clone(e,c,y+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var y;return((y=u.declaration)==null?void 0:y.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),t.push(this),i.push(y)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const{updated:u,removed:y}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...y)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(We,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(We,"type",n.Search),f(We,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(We,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(We,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(We,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(We,"BASE_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,...We.INMUTABLE_BASE_PROPERTIES]),f(We,"MUTABLE_META_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,"x","y"]),f(We,"INMUTABLE_META_PROPERTIES",[...We.INMUTABLE_BASE_PROPERTIES]),f(We,"META_PROPERTIES",[...We.MUTABLE_META_PROPERTIES,...We.INMUTABLE_META_PROPERTIES]),f(We,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(We,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(We,"UPSTREAM_PROPERTIES",[...We.MUTABLE_UPSTREAM_PROPERTIES,...We.INMUTABLE_UPSTREAM_PROPERTIES]),f(We,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(We,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(We,"DOWNSTREAM_PROPERTIES",[...We.MUTABLE_DOWNSTREAM_PROPERTIES,...We.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(We,"PROPERTIES",[...ei.META_PROPERTIES,...ei.UPSTREAM_PROPERTIES,...ei.DOWNSTREAM_PROPERTIES]);let Hr=We;function P1(r){const a=UZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const WJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"type",n.InstalledProject);f(this,"implements");f(this,"functions",[]);f(this,"events",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=C(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on 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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){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=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ze.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),this.events.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),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(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,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=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=P1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.functions)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-exported-function-declaration-"+M+"-id",s));c.functions=E;const I=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ze,"type",n.InstalledProject),f(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",[]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),f(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),f(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Kr=Ze;function w1(r){var o;const a=Y5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=Ar(r),s=C1(r),l=[...i,...s];return Ke(r.errors,l)}function C1(r){const a=[],e=jl(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(de({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:D.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) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(de({id:`${r.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new We(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new We(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===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,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,b.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,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),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await We.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await We.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await We.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await We.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await We.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await We.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];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),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}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(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,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})),inputsDeclarations:this.inputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.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=D1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var V,M,g,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(V=this.inputsDeclarations)==null?void 0:V.map((G,q)=>G.clone(e,this,y+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=E;const I=(M=this.outputsDeclarations)==null?void 0:M.map((G,q)=>G.clone(e,this,y+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const O=(g=this.inputs)==null?void 0:g.map((G,q)=>G.clone(e,c,y+"-input-map-"+q+"-id",s));c.inputs=O;const P=(B=this.outputs)==null?void 0:B.map((G,q)=>G.clone(e,c,y+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var y;return((y=u.declaration)==null?void 0:y.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,b.Added),y.addSelfToProject(e),t.push(this),i.push(y)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const{updated:u,removed:y}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...y)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(We,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(We,"type",n.Search),f(We,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(We,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(We,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(We,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(We,"BASE_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,...We.INMUTABLE_BASE_PROPERTIES]),f(We,"MUTABLE_META_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,"x","y"]),f(We,"INMUTABLE_META_PROPERTIES",[...We.INMUTABLE_BASE_PROPERTIES]),f(We,"META_PROPERTIES",[...We.MUTABLE_META_PROPERTIES,...We.INMUTABLE_META_PROPERTIES]),f(We,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(We,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(We,"UPSTREAM_PROPERTIES",[...We.MUTABLE_UPSTREAM_PROPERTIES,...We.INMUTABLE_UPSTREAM_PROPERTIES]),f(We,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(We,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(We,"DOWNSTREAM_PROPERTIES",[...We.MUTABLE_DOWNSTREAM_PROPERTIES,...We.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(We,"PROPERTIES",[...ei.META_PROPERTIES,...ei.UPSTREAM_PROPERTIES,...ei.DOWNSTREAM_PROPERTIES]);let Hr=We;function P1(r){const a=UZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const WJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"type",n.InstalledProject);f(this,"implements");f(this,"functions",[]);f(this,"events",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=C(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on 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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){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=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ze.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),this.events.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:y,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...y),l.push(...c)}),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(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,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=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=P1(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=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.functions)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-exported-function-declaration-"+M+"-id",s));c.functions=E;const I=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ze,"type",n.InstalledProject),f(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",[]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),f(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),f(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Kr=Ze;function w1(r){var o;const a=Y5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=Ar(r),s=C1(r),l=[...i,...s];return Ke(r.errors,l)}function C1(r){const a=[],e=jl(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(de({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:D.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) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(de({id:`${r.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.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:r}).error);else{const i=Ua(t),s=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&s.push(...t.getAllInteractiveMethods());let l="";i?t.methods.length?l=`
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(u=>u.id).join(`
@@ -137,7 +137,7 @@ ${rn}`);const I=i.declaration;if(!t.get(I))s.push(new w({id:`${i.id}--${R.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.${E}`,issue:null})):s.push(new w({id:`${i.id}--${$.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:$.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:D.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) with id "${i.declaration}".${E}`,issue:null}))}}(d.inputs.length||d.outputs.length||d.internalCalls.length)&&s.push(new w({id:`${i.id}--${R.InvalidInternalCallParentRelation}`,code:R.InvalidInternalCallParentRelation,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.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 s.push(...l.errors,...pt(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, 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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),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=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...E),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=C(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const i=this.calledBy.find(s=>!!s.parent&&ut.includes(s.parent.type));if(i){const s=C(i.parent,this.project);this.parent.setParent(s,null)}else if(!i&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=w1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const O=o.includes(E.index)?this.outputs.length-1+I:E.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:E.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,b.Added),V.addSelfToProject(e)}),this.outputs.sort((E,I)=>E.index-I.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Be,"type",n.InternalCall),f(Be,"USER_MANAGED_PARENT_TYPES",[...it]),f(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),f(Be,"MUTABLE_BASE_PROPERTIES",[]),f(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),f(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),f(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),f(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let Xr=Be;function B1(r){const a=Q5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const YJ=Object.freeze(Object.defineProperty({__proto__:null,validate:B1},Symbol.toStringTag,{value:"Module"}));var _1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(_1||{});const _e=class _e extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"name",null);f(this,"description",null);f(this,"type",n.InputMap);f(this,"defaultValue",null);f(this,"readsValue",null);f(this,"dataType",null);f(this,"declaration",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:"",description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.declaration){const y=_(e.declaration);l=t.get(y)}let o=null;if(e.readsValue){const y=_(e.readsValue);o=t.get(y)}const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(s.inputs||[]).length,description:e.description||null,declaration:l,readsValue:o,defaultValue:null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){var y;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...dt,n.InputMap]}},t);i=l.modifiedData;const o=t.get(i.parent),d=i.declaration&&(t.get(i.declaration)||t.getBuiltIn(i.declaration)),u=((o==null?void 0:o.inputs)||[]).find(c=>{var E;return i.declaration&&((E=c.declaration)==null?void 0:E.id)===i.declaration});if(i.declaration?d?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(d.type)?o&&d.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${i.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(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),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=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.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=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...E),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=C(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const i=this.calledBy.find(s=>!!s.parent&&ut.includes(s.parent.type));if(i){const s=C(i.parent,this.project);this.parent.setParent(s,null)}else if(!i&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=w1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const O=o.includes(E.index)?this.outputs.length-1+I:E.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:E.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,b.Added),V.addSelfToProject(e)}),this.outputs.sort((E,I)=>E.index-I.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Be,"type",n.InternalCall),f(Be,"USER_MANAGED_PARENT_TYPES",[...it]),f(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),f(Be,"MUTABLE_BASE_PROPERTIES",[]),f(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),f(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),f(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),f(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let Xr=Be;function B1(r){const a=Q5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const YJ=Object.freeze(Object.defineProperty({__proto__:null,validate:B1},Symbol.toStringTag,{value:"Module"}));var _1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(_1||{});const _e=class _e extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"name",null);f(this,"description",null);f(this,"type",n.InputMap);f(this,"defaultValue",null);f(this,"readsValue",null);f(this,"dataType",null);f(this,"declaration",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);f(this,"_codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:"",description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.declaration){const y=_(e.declaration);l=t.get(y)}let o=null;if(e.readsValue){const y=_(e.readsValue);o=t.get(y)}const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(s.inputs||[]).length,description:e.description||null,declaration:l,readsValue:o,defaultValue:null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){var y;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...dt,n.InputMap]}},t);i=l.modifiedData;const o=t.get(i.parent),d=i.declaration&&(t.get(i.declaration)||t.getBuiltIn(i.declaration)),u=((o==null?void 0:o.inputs)||[]).find(c=>{var E;return i.declaration&&((E=c.declaration)==null?void 0:E.id)===i.declaration});if(i.declaration?d?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(d.type)?o&&d.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${i.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&&d.type===n.Property&&!it.includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.Property}' with id '${i.declaration}'.
143
143
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
@@ -402,7 +402,7 @@ All global 'function-declaration' entity ids are:
402
402
  The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:D.Error,message:`Entity of type "${n.FunctionCall}" with id "${i.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
403
403
  References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${d}`,issue:null}))}return{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
404
404
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
405
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new qe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new qe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...E),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=C(this.initialData.declaration,this.project);this.declaration=t}else{const t=_(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await qe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await qe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await qe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await qe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await qe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await qe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=X1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const O=o.includes(E.index)?this.outputs.length-1+I:E.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:E.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,b.Added),V.addSelfToProject(e)}),this.outputs.sort((E,I)=>E.index-I.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(qe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(qe,"type",n.FunctionCall),f(qe,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(qe,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),f(qe,"MUTABLE_BASE_PROPERTIES",[]),f(qe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(qe,"BASE_PROPERTIES",[...qe.MUTABLE_BASE_PROPERTIES,...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"MUTABLE_META_PROPERTIES",["x","y"]),f(qe,"INMUTABLE_META_PROPERTIES",[...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"META_PROPERTIES",[...qe.MUTABLE_META_PROPERTIES,...qe.INMUTABLE_META_PROPERTIES]),f(qe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(qe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(qe,"UPSTREAM_PROPERTIES",[...qe.MUTABLE_UPSTREAM_PROPERTIES,...qe.INMUTABLE_UPSTREAM_PROPERTIES]),f(qe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),f(qe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(qe,"DOWNSTREAM_PROPERTIES",[...qe.MUTABLE_DOWNSTREAM_PROPERTIES,...qe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(qe,"PROPERTIES",[...qe.META_PROPERTIES,...qe.UPSTREAM_PROPERTIES,...qe.DOWNSTREAM_PROPERTIES]);let nn=qe;function qc(r){return r&&typeof r.then=="function"}class zl{constructor(a){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",Ui());f(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(Ui()),t=p(j(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Ql(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Ql(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Ql(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);qc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);qc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function eP(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var y;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((y=u.getDefaultValue())==null?void 0:y.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=u==null?void 0:u.defaultValue;if(y)y.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},E=C(c,r.project);return E.setParent(u==null?void 0:u.dataType,a),E.initChildren(a),a==null||a.add(E,b.Added),E.addSelfToProject(a),{newEntities:[E]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=Yl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=C(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,b.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function tP(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let y=r.project.entities.filter(I=>I.implements.find(O=>O.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(I=>!!I.properties.find(O=>{var P;return O.implements&&O.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=O.getDefaultValue())==null?void 0:P.value)===!0}));if(!y){y=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const O=y.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=O==null?void 0:O.defaultValue)==null||d.metaSync({value:!0},a),t.push(y)}const c=r.properties.find(I=>I.implements&&I.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),E=c==null?void 0:c.defaultValue;if(c&&!E){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:y,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},O=C(I,r.project);O.hydrateAncestors(),O.setParent(c,a),O.addSelfToProject(a),O.initChildren(a),a==null||a.add(O,b.Added),t.push(O);return}else E&&E.setValueAsTypeSingle(y,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function Yl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r.toJSON()],x:0,y:0,parent:r.project.toReference()};eP(r,e);const o=C(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,b.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),tP(o,e),o}function Jc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function iP(r,a,e,t=Pt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},y=C(u,r.project);return s.push(y),y.setParent(a,e),y.initChildren(e),e==null||e.add(y,b.Added),y.setEntity(r),y.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:y}}function Sc(r,a,e,t,i){var u,y,c,E,I,O,P,V;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const g=new Date(r);if(g instanceof Date&&!isNaN(g.valueOf())&&(M=!0),M){const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(q=>q!==void 0);if(B.every(q=>typeof q==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else{const q=[];let W=!1;B.forEach(pe=>{var Ee,Q,le,ri;if(Array.isArray(pe)&&(W=!0),typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const tr=Hl(pe,a.project,{...e,id:m.UUID.uuid()},t,i);tr.hasCreated&&q.push((Ee=tr.changeSet)==null?void 0:Ee.self),s.push(...(Q=tr.changeSet)==null?void 0:Q.updated),l.push(...(le=tr.changeSet)==null?void 0:le.added),o.push(...(ri=tr.changeSet)==null?void 0:ri.removed)}});const X=p(q);if(!X.length&&!W){B.forEach(pe=>{const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},Q=C(Ee,a.project);switch(Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t),typeof pe){case"string":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}});break}else X.length===1&&!W?a.setEntity(X[0]):B.forEach(pe=>{if(typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const Ee=Jc(Object.keys(pe),a.project);if(Ee){const Q=iP(Ee||X[0],a,t,Pt.OrDataTypeGroup);s.push(...Q.updated),l.push(...Q.added),o.push(...Q.removed)}}else{const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(pe),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},Q=C(Ee,a.project);Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t);const le=Sc(pe,Q,{...e,id:m.UUID.uuid()},t,i);s.push(...le.updated),l.push(...le.added),o.push(...le.removed)}})}}else{const B=Hl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(y=B.changeSet)==null?void 0:y.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(E=B.changeSet)==null?void 0:E.removed);break}else{const B=Hl(r,a.project,{...e},t,i);a.setEntity((I=B.changeSet)==null?void 0:I.self),s.push(...(O=B.changeSet)==null?void 0:O.updated),l.push(...(P=B.changeSet)==null?void 0:P.added),o.push(...(V=B.changeSet)==null?void 0:V.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Hl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),y=Jc(u,a);if(y)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:y}};const c=i?e.name+" of "+i.name:e.name,I={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},O=C(I,a);return O.setParent(a,t),O.initChildren(t),t==null||t.add(O,b.Added),O.addSelfToProject(t),l.push(O),u.forEach((P,V)=>{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:V,hidden:!1,private:!1,required:!0,parent:O.toReference()},B=C(g,a);B.setParent(O,t),B.initChildren(t),t==null||t.add(B,b.Added),B.addSelfToProject(t),l.push(B);const G=r[P],W={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:B.toReference()},X=C(W,a);X.setParent(B,t),X.initChildren(t),t==null||t.add(X,b.Added),X.addSelfToProject(t),l.push(X);const pe=Sc(G,X,{...e,name:P,id:m.UUID.uuid()},t,i||O);s.push(...pe.updated),l.push(...pe.added),o.push(...pe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:O}}}function br(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,y;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((y=s.implements)==null?void 0:y.id)});if(l){const d=new Ye({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new Ye({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:D.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var y,c;return!!u.implements&&((y=u.implements)==null?void 0:y.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new Ye({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new Ye({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:D.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function TS(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Bc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function ES(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===sd.Implements||t.field===sd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function IS(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function AS(r,a){return r.static&&(r.properties.forEach(t=>{t.static&&t.metaSync({static:!1},a)}),r.metaSync({static:!1},a)),r}var rP=(r=>(r.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",r.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",r))(rP||{});function nP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces.`,issue:null,severity:D.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s/g,"-")}}function sP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:D.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}if(t.includes("-")){const i=new Ye({id:r.id+"--string-value-must-not-have-dashes",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:D.Error,code:"string-value-must-not-have-dashes",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s|-/g,"_")}}function ws(r,a){const e=$n(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=ws(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function Wc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=Jt(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||ws(s,t).last?s:(ws(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function K(r,a){var i,s;let e=Wc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!ut.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(ot.includes(r.type))return;Je(r).forEach(l=>{var d,u;const o=Wc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!ut.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function aP(r,a,e=new Set){const t=sn(r),i=sn(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...aP(u,a,e)])),[]);return p([...l,...o])}function Ma(r,a){const e=ws(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function bS(r,a){return!!ws(r,a).last}function RS(r){if(at.includes(r.type))return r;if([...gi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return at.includes(a.type)?a:null}return null}function zc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return zc(e,t)}function Vt(r){if(Wa.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return a;if(a.type===n.Loop)return a}return r}else{const a=r.parent;return a?Vt(a):null}}function Kl(r,a){const e=Na(r,a);if(!e)return null;if(Wa.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Na(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Na(e.parent,a):null;return t?Kl(t,a):null}}function oP(r){if(!r)return null;if(gi.includes(r.type))return r;const a=r.parent;return a?oP(a):null}function lP(r){if(!r)return null;if(dt.includes(r.type))return r;const a=r.parent;return a?lP(a):null}function dP(r){if(!r)return null;if(Gi.includes(r.type))return r;const a=r.parent;return a?dP(a):null}function DS(r){return r.type===n.VariableDeclaration?[r]:dt.includes(r.type)?[...r.inputs,...r.outputs||[]]:ot.includes(r.type)?r.outputs:kn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function OS(r){const a=sn(r),e=[],t=[];df.includes(r.type)&&e.push(...Yc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:gi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>Ma(l,s)?-1:0),t.sort((s,l)=>Ma(l,s)?-1:0),[...e,...t,...i]}function uP(r){return[...r].sort((a,e)=>Ma(e,a)?-1:0)}function PS(r){const a=uP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];Ma(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function ti(r){const a=r.map(e=>Vt(e));return p(a)}function Yc(r){return dt.includes(r.type)?[...ti(r.successCalls),...ti(r.errorCalls)]:at.includes(r.type)?ti(r.calls):[]}function wS(r,a){return Yc(r).includes(a)}function Hc(r){return r.writesValues||[]}function CS(r,a){return Hc(r).includes(a)}function pP(r){var a;return it.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function VS(r){return r.writesValues}function cP(r=[]){return r.map(pP).filter(a=>!!a)}function Xl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>it.includes(a.type))}function fP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&it.includes(a.type))}function yP(r){return it.includes(r.type)?r:null}function hP(r){return r.writesValues.map(yP).filter(a=>!!a)}function mP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...hP(e)]:a,[])}function Je(r){return dt.includes(r.type)?[...er(ti(r.successCalls)),...er(ti(r.errorCalls))]:at.includes(r.type)?er(ti(r.calls)):[]}function BS(r){return dt.includes(r.type)?[...er(ti(r.successCalls)),...er(ti(r.errorCalls))]:at.includes(r.type)?er(ti(r.calls)):[]}function vP(r,a=new Set){return r.writesValues.filter(t=>it.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...He(i,a)],[])}function TP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>it.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...He(s,a)],[])}function He(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return fP(r.outputs).reduce((t,i)=>[...t,...He(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Je(r).reduce((s,l)=>{const o=Vt(l);return[...s,...He(o||l,a)]},[]),...cP(r.inputs),...mP(r.outputs)].reduce((s,l)=>[...s,...He(l,a)],[]);if(kn.includes(r.type)){const e=Xl(r.inputs),i=Je(r).reduce((s,l)=>{const o=Vt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Xl(r.inputs)],i=Je(r).reduce((s,l)=>{const o=Vt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l)],[])}if(it.includes(r.type)){a.add(r.id);const t=Je(r).reduce((i,s)=>{const l=Vt(s);return[...i,...He(l||s,a)]},[]);return[r,...t,...TP(r,a),...vP(r,a)]}return[]}function ui(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...sn(r).reduce((i,s)=>[...i,s,...ui(s,a)],[])])}function er(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Je(e)],[])}function EP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Xl(u.inputs),...er(ti(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...er(ti(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...er(ti(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function IP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return dt.includes(r.type)?zP(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function _S(r){const a=EP(r.project);return IP(r,a)}function Na(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Ql(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(fi.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,y=r,c=r,E=r,I=r,O=r,P=r,V=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(O.calledByEntry||[]).flatMap(G=>G),...(O.calledBySuccess||[]).flatMap(G=>G),...(O.calledByError||[]).flatMap(G=>G),...(s.extends||[]).flatMap(G=>G),...E.parent?[E.parent]:[]];Array.isArray(s.implements)?V.push(...s.implements.flatMap(G=>G)):c.implements&&V.push(c.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&V.push(...o.valueAsTypeList.flatMap(G=>G)),o.valueAsTypeSingle&&V.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(G=>G),...(I.inputsDeclarations||[]).flatMap(G=>G),...(t.outputs||[]).flatMap(G=>G),...(I.outputsDeclarations||[]).flatMap(G=>G),...(P.internalCalls||[]).flatMap(G=>G),...P.writesValues||[],...O.dataType?[O.dataType]:[],...d.body?[d.body]:[],...O.defaultValue?[O.defaultValue]:[],...(O.successCalls||[]).flatMap(G=>G),...(O.errorCalls||[]).flatMap(G=>G),...(s.properties||[]).flatMap(G=>G),...(s.methods||[]).flatMap(G=>G),...(s.abstractMethods||[]).flatMap(G=>G),...u.error?[u.error]:[],...u.process?[u.process]:[],...E.throws?[E.throws]:[],...(i.andChildrenGroup||[]).flatMap(G=>G),...(i.orChildrenGroup||[]).flatMap(G=>G),...(y.entities||[]).flatMap(G=>G),...(y.functions||[]).flatMap(G=>G),...(y.functionCalls||[]).flatMap(G=>G),...(y.events||[]).flatMap(G=>G),...(y.conditions||[]).flatMap(G=>G),...(y.operations||[]).flatMap(G=>G),...(y.loops||[]).flatMap(G=>G),...(y.variableDeclarations||[]).flatMap(G=>G),...(y.variableInstances||[]).flatMap(G=>G),...(y.searches||[]).flatMap(G=>G),...(y.projects||[]).flatMap(G=>G),...(l.calls||[]).flatMap(G=>G)];r.type===n.DataType&&(i.entity&&a[_(i.entity)]&&a[_(i.entity)].parent&&_(a[_(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&V.push(i.entity));const g={},B={};return V.forEach(G=>{const q=_(G);if(q&&e.ignoreBuiltInBaseEntities&&(fi.includes(G.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const W=G.version;q&&(g[q]=W)}),M.forEach(G=>{const q=_(G);if(q&&e.ignoreBuiltInBaseEntities&&(fi.includes(G.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const W=G.version;q&&(B[q]=W)}),{upstream:g,downstream:B}}function MS(r,a){const e=[];if(gi.includes(r.type)){Ii(r).forEach(s=>{const l=Kl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=Na(s,a);return l?HP(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(it.includes(r.type)){const t=ed(r);t&&e.push(t)}return p(e)}function $n(r){const a=[];if(gi.includes(r.type)){r.calledBy.forEach(i=>{const s=Vt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>ed(i)).filter(i=>i!==null);a.push(...p(t))}if(it.includes(r.type)){const e=ed(r);e&&a.push(e)}return p(a)}function Ii(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function AP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>j(t,a,e)),...r.outputs.flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.parent?j(r.parent,a,e):[]]}function bP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a):[],...r.writesValues.flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function RP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function DP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...(r.extends||[]).flatMap(t=>j(t,a,e))]}function OP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function PP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>j(t,a,e)),...(r.implements||[]).flatMap(t=>j(t,a,e)),...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>j(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>j(t,a,e)),...r.entity?j(r.entity,a,e):[],...r.parent?j(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.parent?j(r.parent,a,e):[]]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?j(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>j(t,a,e)):[],...r.parent?j(r.parent,a,e):[]]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.body?j(r.body,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e))]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>j(t,a,e)),...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.variableInstances||[]).flatMap(t=>j(t,a,e)),...(r.operations||[]).flatMap(t=>j(t,a,e)),...(r.conditions||[]).flatMap(t=>j(t,a,e)),...(r.functionCalls||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.loops||[]).flatMap(t=>j(t,a,e)),...(r.searches||[]).flatMap(t=>j(t,a,e))]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function kP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function ZP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function qP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function JP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function SP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function WP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.parent?j(r.parent,a,e):[]]}function Ui(){const r=new Set,a=uI.flatMap(e=>j(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function j(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(fi.includes(r.type)||Ui().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return VP(r,a,e);case n.Operation:return $P(r,a,e);case n.Condition:return OP(r,a,e);case n.Loop:return UP(r,a,e);case n.Search:return qP(r,a,e);case n.GlobalEvent:return _P(r,a,e);case n.ReturnStatement:return ZP(r,a,e);case n.ContinueStatement:return PP(r,a,e);case n.BreakStatement:return RP(r,a,e);case n.VariableDeclaration:return SP(r,a,e);case n.DefinitionEntity:return wP(r,a,e);case n.FunctionDeclaration:return BP(r,a,e);case n.Project:return FP(r,a,e);case n.ActionDescriptor:return AP(r,a,e);case n.ArgumentDeclaration:return bP(r,a,e);case n.ReturnDeclaration:return kP(r,a,e);case n.ValueDescriptor:return JP(r,a,e);case n.InputMap:return MP(r,a,e);case n.OutputMap:return gP(r,a,e);case n.DataType:return CP(r,a,e);case n.InstalledProject:return NP(r,a,e);case n.InternalCall:return LP(r,a,e);case n.LiteralValue:return jP(r,a,e);case n.Property:return xP(r,a,e);case n.VariableInstance:return WP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:DP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:GP(r,a,e)}return[]}function Kc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||kn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function NS(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function zP(r){return dt.includes(r.type)?r.inputs:[]}function YP(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:ot.includes(r.type)?r.outputs:[]}function LS(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function jS(r){return r.type===n.Condition?[]:dt.includes(r.type)?r.outputs:[]}function ed(r){const a=r.readsValue;return a?Vt(a):null}function HP(r,a){const e=r.readsValue;return e?Kl(e,a):null}function KP(r){const a=r.internalCalls||[];return p(ti(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Cs(r){const a=Hc(r),e=[];return a.forEach(t=>{if(it.includes(t.type))e.push(t);else if(Dr.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function sn(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),ut.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:sn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>Vt(s)),i=r.errorCalls.map(s=>Vt(s));e.push(...t,...i)}if(kn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Cs(s)).flat(),i=r.calls.map(s=>Vt(s));e.push(...p(t),...i)}if(dt.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Cs(l)).flat(),i=r.successCalls.map(l=>Vt(l)),s=r.errorCalls.map(l=>Vt(l));e.push(...p(t),...i,...s)}if(it.includes(r.type)){const t=Cs(r),i=KP(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Cs(l)).flat();if(r.body){const l=sn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>Vt(l)),s=r.successCalls.map(l=>Vt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Cs(s)).flat(),i=r.calls.map(s=>Vt(s));e.push(...p(t),...i)}return p(e)}function XP(r,a=!1){const e=sn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...XP(s,a)],[])];return p(t)}function QP(r){const a=$n(r),e=[...a,...a.reduce((t,i)=>[...t,...QP(i)],[])];return p(e)}function La(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...La(e),...ja(e)]:[...a,e.name],[])}function ja(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...ja(e),...La(e)]:[...a,e.name],[])}function Xc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Xc(e),...Qc(e)]:[...a,e],[])}function Qc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Qc(e),...Xc(e)]:[...a,e],[])}function ef(r){return[...ja(r),...La(r)].filter((e,t,i)=>i.indexOf(e)===t)}function ew(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===S.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=ew(i);if(s)return s}return t},null)}function US(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function $S(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function tw(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function qt(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...qt(t)]:e,[]);return p(a)}function Ua(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!qt(r).find(t=>!t.interactive)}function gS(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function tf(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function iw(r){if([...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r))return!1;const a=$n(r);return a.length===0?!0:a.some(e=>iw(e))}function rf(r){return[...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r)?!1:$n(r).length===0}function rw(r,a=0){if(rf(r)){const e=$n(r);return e.length===0?r:e.map(i=>rw(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function nw(r){const a=[];if(rf(r))a.push(r);else return[];return $n(r).forEach(t=>{a.push(...nw(t))}),a}function sw(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function GS(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function $a(r){switch(r){case n.DefinitionEntity:return on;case n.FunctionDeclaration:return xr;case n.VariableDeclaration:return Yr;case n.VariableInstance:return zr;case n.FunctionCall:return nn;case n.Operation:return Zr;case n.Condition:return Wr;case n.ReturnStatement:return Fr;case n.Loop:return Sr;case n.Search:return Hr;case n.InputMap:return Ki;case n.OutputMap:return Xi;case n.ArgumentDeclaration:return Er;case n.ReturnDeclaration:return ei;case n.Property:return Gr;case n.InstalledProject:return Kr;case n.Project:return m;case n.DataType:return kr;case n.GlobalEvent:return qr;case n.InternalCall:return Xr;case n.ValueDescriptor:return Ir;case n.BuiltInBaseEntity:return $i;case n.PrimitiveEntity:return ii;case n.ActionDescriptor:return Se;case n.LiteralValue:return Qr;case n.ContinueStatement:return Ut;case n.BreakStatement:return Jr;default:return null}}function Jt(r,a){const e=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let t=e?a.get(e):null;if(r.type===n.ReturnStatement)return It(r,a);if(r.type===n.FunctionDeclaration&&(t==null?void 0:t.type)===n.Loop)return t;if(ut.includes(r.type))return r;if(fi.includes(r.type))return null;const i=r.parent;if(!i)return null;if(i.type===n.GenericReference){const s=_(i);if(!s)return null;const l=a.get(s);return l?Jt(l,a):null}else return i===a?a:Jt(i,a)}function It(r,a){const e=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let t=e?a.get(e):null;if(r.type===n.FunctionDeclaration&&(t==null?void 0:t.type)===n.Loop)return It(t.parent,a);if(at.includes(r.type))return r;if(fi.includes(r.type))return null;const i=r.parent;if(!i)return null;if(i.type===n.GenericReference){const s=_(i);if(!s)return null;const l=a.get(s);return l?It(l,a):null}else return i===a?a:It(i,a)}function nf(r,a){if(fi.includes(r.type)||a.getBuiltIn(r.id))return null;const e=Ai(r.parent,a);return e?e===a?ut.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:nf(e,a):null}function td(r,a,e){if(r===a||a===e||r===e)return!1;const t=Jt(a.parent,e);return t===r?!0:td(t,a,e)}var id=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(id||{});function ga(r,a,e){const t=Jt(r,e),i=Jt(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(td(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(td(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=zc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Jt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function aw(r,a,e){const t=ga(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=Jt(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=Jt(i.parent,e)}let s=Jt(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=Jt(s.parent,e)}return null}function ow(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=aw(e,t,t.project);return!i||i===t?e:t},r[0])}function Ai(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=_(r):e=r.id,e===a.id?a:a.get(e)}function an(r){if(!r)return null;if(fi.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:an(a)}function Ga(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=nf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Ga(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Ga(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=Vt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=Ga(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function FS(r){return Wa.includes(r.type)?r.type===n.FunctionDeclaration?!sw(r):!0:!1}function xS(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function rd(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ja(r).includes(a)}function kS(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!La(r).includes(a)}function Fa(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ef(r).includes(a)}function ZS(r){const a=[];return r.entities.forEach(e=>{if(rd(e,S.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function qS(r){const a=[];return r.entities.forEach(e=>{if(rd(e,S.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function JS(r){return r.type!==n.DefinitionEntity||r.abstract||!rd(r,S.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][S.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function SS(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!Fa(r,S.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][S.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function WS(r){var e;if(!r||r.type!==n.DefinitionEntity||!Fa(r,S.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][S.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!pf.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function zS(r){switch(r){case n.Project:return m;case n.InstalledProject:return Kr;case n.DefinitionEntity:return on;case n.FunctionDeclaration:return xr;case n.GlobalEvent:return qr;case n.VariableInstance:return zr;case n.VariableDeclaration:return Yr;case n.InputMap:return Ki;case n.OutputMap:return Xi;case n.Condition:return Wr;case n.Operation:return Zr;case n.FunctionCall:return nn;case n.ReturnDeclaration:return ei;case n.ArgumentDeclaration:return Er;case n.PrimitiveEntity:return ii;case n.DataType:return kr;case n.Property:return Gr;case n.ActionDescriptor:return Se;case n.ReturnStatement:return Fr;case n.ContinueStatement:return Ut;case n.BreakStatement:return Jr;case n.Loop:return Sr;case n.Search:return Hr;case n.ValueDescriptor:return Ir;case n.InternalCall:return Xr;case n.LiteralValue:return Qr}return null}function YS(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function ct(r,a){const e=$a(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function nd(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=_(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...nd(t,a)]:[]}function HS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=Vt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function lw(r){const a=P7(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(y=>KS(r,y)),s=r.extends.flatMap(y=>XS(r,y)),l=eW(r),o=QS(r);r.methods.flatMap(y=>y.validate());const d=[...i,...s,...l,...o];return Ke(r.errors,d)}function dw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function uw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function KS(r,a){const e=[];if(!a.abstract){const y=de({id:r.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(y.error),e}const t=a.properties.filter(y=>y.abstract),i=[];let s=[...r.properties];t.forEach(y=>{const c=s.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===y.id});c?s=s.filter(E=>E.id!==c.id):i.push(y)}),i.length&&i.forEach(y=>{const c=de({id:r.id+"--"+F.MissingPropertyImplementation+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(y=>{const c=o.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===y.id});c?o=o.filter(E=>E.id!==c.id):l.push(y)}),l.length&&l.forEach(y=>{const c=de({id:r.id+"--"+F.MissingMethodImplementation+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(y=>{const c=s.find(E=>E.name===y.name);c&&d.push([c,y])}),d.length&&d.forEach(([y])=>{const c=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(y=>{const c=o.find(E=>E.name===y.name);c&&u.push([c,y])}),u.length&&u.forEach(([y])=>{const c=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function XS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function QS(r){const a=[];if(!r.properties.length){const e=de({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:D.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function eW(r){const a=[];if(r.abstract){if(r.methods.length){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=de({id:r.id+"--"+F.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:D.Error,code:F.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}if(r.properties.some(e=>e.abstract)){const e=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract properties`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(e.error),r.properties.forEach(t=>{if(t.abstract){const i=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(i.error)}})}}if(r.static&&r.properties.some(e=>!e.static)){const e=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as static but has non-static properties`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.static){const i=de({id:r.id+"--"+F.NonStaticPropertyInStaticEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:D.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function tW(r,a){const e=[],t=qt(a);if(!a.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+F.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new Ye({id:r.id+"--"+d.id+"--"+l.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{qt(l).forEach(y=>{const c=t.filter(E=>E.id!==y.id);c.length&&c.forEach(E=>{if(E.id!==y.id){const I=new Ye({id:r.id+"--"+E.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:y});e.push(I)}})});const d=br(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=br(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>qt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new Ye({id:r.id+"--"+a.id+"--"+l.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function iW(r,a,e=!1){const t=[],i=qt(a);if(!r.abstract&&a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.abstract&&!a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!r.static&&a.static){const y=de({id:r.id+"--"+a.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.static&&!a.static){const y=de({id:r.id+"--"+a.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!Ua(a)){const y=de({id:r.id+"--"+a.id+"--"+F.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(y.error)}const l=r.extends.filter(y=>y.id!==a.id);l.length&&l.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==y.id);c.length&&c.forEach(E=>{if(E.id!==y.id){const I=de({id:r.id+"--"+E.id+"--"+y.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${E.name}" with id "${E.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:y});t.push(I.error)}})}else{qt(y).forEach(M=>{const g=i.filter(B=>B.id!==M.id);g.length&&g.forEach(B=>{if(B.id!==M.id){const G=new Ye({id:r.id+"--"+B.id+"--"+M.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${B.name}" with id "${B.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push(G)}})});const E=!!qt(y).find(M=>M.id===a.id);let I=[...y.properties];E&&(I=I.filter(M=>!a.properties.find(g=>{var B;return g.id===M.id||g.name===M.name||g.id===((B=M.implements)==null?void 0:B.id)})));let O=[...y.methods];E&&(O=O.filter(M=>!a.methods.find(g=>{var B;return g.id===M.id||g.name===M.name||g.id===((B=M.implements)==null?void 0:B.id)})));const P=br(a.ownDeclaredProperties,I,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const V=br(a.abstractMethods,O,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...V.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==y.id);c.length&&c.forEach(E=>{if(E.id!==y.id){const I=new Ye({id:r.id+"--"+E.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:y});t.push(I)}})}else{qt(y).forEach(O=>{const P=i.filter(V=>V.id!==O.id);P.length&&P.forEach(V=>{if(V.id!==O.id){const M=new Ye({id:r.id+"--"+V.id+"--"+O.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${O.name}" with id "${O.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:V,secondRelationship:O});t.push(M)}})});const E=br(a.ownDeclaredProperties,y.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...E.errors);const I=br(a.abstractMethods,[...y.abstractMethods,...y.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...I.errors)}});const o=br(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=br(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(y=>qt(y))).forEach(y=>{if(!i.find(c=>c.id===y.id)){const c=new Ye({id:r.id+"--"+a.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:y});t.push(c)}}),t}function rW(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function nW(r){const a=[];if(r.implements.length){const e=new Ye({id:r.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function sW(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function aW(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const oW=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:uw,getBasePropertiesNotImplemented:dw,validate:lw,validateCanBecomeAbstract:nW,validateCanBecomeNonAbstract:aW,validateCanBecomeNonStatic:sW,validateCanBecomeStatic:rW,validateCanExtendEntity:iW,validateCanImplementEntity:tW},Symbol.toStringTag,{value:"Module"}));function lW(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var sd=(r=>(r.Extends="extends",r.Implements="implements",r))(sd||{});const Ue=class Ue extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"static");f(this,"abstract");f(this,"type",n.DefinitionEntity);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"implements",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestedProperties",[]);f(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=lW(i,t),o=Ac(i,t);s.push(...l,...o,...pt(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
405
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new qe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new qe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:E}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...E),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,b.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,b.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,b.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,b.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,b.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,b.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,b.Updated),t==null||t.add(s,b.Affected),!1)),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=C(this.initialData.declaration,this.project);this.declaration=t}else{const t=_(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await qe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await qe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await qe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await qe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await qe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await qe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:E}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...E)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=J){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=X1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=E;const I=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(E=>E.declaration.id===c.id));this.inputs.sort((c,E)=>c.index-E.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=C(E,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,b.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,E)=>c.index-E.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(E=>{const I=C(E,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(E=>!this.outputs.find(I=>I.declaration.id===E.id));this.outputs.sort((E,I)=>E.index-I.index),d.forEach((E,I)=>{this.outputs.forEach(M=>{M.index>=E.index&&M.index++});const O=o.includes(E.index)?this.outputs.length-1+I:E.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:E.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,b.Added),V.addSelfToProject(e)}),this.outputs.sort((E,I)=>E.index-I.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(qe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(qe,"type",n.FunctionCall),f(qe,"USER_MANAGED_PARENT_TYPES",[...ut,n.Project]),f(qe,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),f(qe,"MUTABLE_BASE_PROPERTIES",[]),f(qe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(qe,"BASE_PROPERTIES",[...qe.MUTABLE_BASE_PROPERTIES,...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"MUTABLE_META_PROPERTIES",["x","y"]),f(qe,"INMUTABLE_META_PROPERTIES",[...qe.INMUTABLE_BASE_PROPERTIES]),f(qe,"META_PROPERTIES",[...qe.MUTABLE_META_PROPERTIES,...qe.INMUTABLE_META_PROPERTIES]),f(qe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(qe,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(qe,"UPSTREAM_PROPERTIES",[...qe.MUTABLE_UPSTREAM_PROPERTIES,...qe.INMUTABLE_UPSTREAM_PROPERTIES]),f(qe,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),f(qe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(qe,"DOWNSTREAM_PROPERTIES",[...qe.MUTABLE_DOWNSTREAM_PROPERTIES,...qe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(qe,"PROPERTIES",[...qe.META_PROPERTIES,...qe.UPSTREAM_PROPERTIES,...qe.DOWNSTREAM_PROPERTIES]);let nn=qe;function qc(r){return r&&typeof r.then=="function"}class zl{constructor(a){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",Ui());f(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(Ui()),t=p(j(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Ql(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Ql(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Ql(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);qc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);qc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function eP(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var y;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((y=u.getDefaultValue())==null?void 0:y.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=u==null?void 0:u.defaultValue;if(y)y.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},E=C(c,r.project);return E.setParent(u==null?void 0:u.dataType,a),E.initChildren(a),a==null||a.add(E,b.Added),E.addSelfToProject(a),{newEntities:[E]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=Yl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=C(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,b.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function tP(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let y=r.project.entities.filter(I=>I.implements.find(O=>O.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(I=>!!I.properties.find(O=>{var P;return O.implements&&O.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=O.getDefaultValue())==null?void 0:P.value)===!0}));if(!y){y=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const O=y.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=O==null?void 0:O.defaultValue)==null||d.metaSync({value:!0},a),t.push(y)}const c=r.properties.find(I=>I.implements&&I.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),E=c==null?void 0:c.defaultValue;if(c&&!E){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:y,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},O=C(I,r.project);O.hydrateAncestors(),O.setParent(c,a),O.addSelfToProject(a),O.initChildren(a),a==null||a.add(O,b.Added),t.push(O);return}else E&&E.setValueAsTypeSingle(y,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function Yl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r.toJSON()],x:0,y:0,parent:r.project.toReference()};eP(r,e);const o=C(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,b.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),tP(o,e),o}function Jc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function iP(r,a,e,t=Pt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},y=C(u,r.project);return s.push(y),y.setParent(a,e),y.initChildren(e),e==null||e.add(y,b.Added),y.setEntity(r),y.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:y}}function Sc(r,a,e,t,i){var u,y,c,E,I,O,P,V;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const g=new Date(r);if(g instanceof Date&&!isNaN(g.valueOf())&&(M=!0),M){const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(q=>q!==void 0);if(B.every(q=>typeof q==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else{const q=[];let W=!1;B.forEach(pe=>{var Ee,Q,le,ri;if(Array.isArray(pe)&&(W=!0),typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const tr=Hl(pe,a.project,{...e,id:m.UUID.uuid()},t,i);tr.hasCreated&&q.push((Ee=tr.changeSet)==null?void 0:Ee.self),s.push(...(Q=tr.changeSet)==null?void 0:Q.updated),l.push(...(le=tr.changeSet)==null?void 0:le.added),o.push(...(ri=tr.changeSet)==null?void 0:ri.removed)}});const X=p(q);if(!X.length&&!W){B.forEach(pe=>{const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},Q=C(Ee,a.project);switch(Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t),typeof pe){case"string":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":Q.setEntity(Q.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}});break}else X.length===1&&!W?a.setEntity(X[0]):B.forEach(pe=>{if(typeof pe=="object"&&!Array.isArray(pe)&&pe!==null){const Ee=Jc(Object.keys(pe),a.project);if(Ee){const Q=iP(Ee||X[0],a,t,Pt.OrDataTypeGroup);s.push(...Q.updated),l.push(...Q.added),o.push(...Q.removed)}}else{const Ee={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(pe),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:Pt.OrDataTypeGroup,parent:a.toReference()},Q=C(Ee,a.project);Q.setParent(a,t),Q.initChildren(t),t==null||t.add(Q,b.Added),Q.addSelfToProject(t);const le=Sc(pe,Q,{...e,id:m.UUID.uuid()},t,i);s.push(...le.updated),l.push(...le.added),o.push(...le.removed)}})}}else{const B=Hl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(y=B.changeSet)==null?void 0:y.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(E=B.changeSet)==null?void 0:E.removed);break}else{const B=Hl(r,a.project,{...e},t,i);a.setEntity((I=B.changeSet)==null?void 0:I.self),s.push(...(O=B.changeSet)==null?void 0:O.updated),l.push(...(P=B.changeSet)==null?void 0:P.added),o.push(...(V=B.changeSet)==null?void 0:V.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Hl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),y=Jc(u,a);if(y)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:y}};const c=i?e.name+" of "+i.name:e.name,I={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},O=C(I,a);return O.setParent(a,t),O.initChildren(t),t==null||t.add(O,b.Added),O.addSelfToProject(t),l.push(O),u.forEach((P,V)=>{const g={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:V,hidden:!1,private:!1,required:!0,parent:O.toReference()},B=C(g,a);B.setParent(O,t),B.initChildren(t),t==null||t.add(B,b.Added),B.addSelfToProject(t),l.push(B);const G=r[P],W={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:B.toReference()},X=C(W,a);X.setParent(B,t),X.initChildren(t),t==null||t.add(X,b.Added),X.addSelfToProject(t),l.push(X);const pe=Sc(G,X,{...e,name:P,id:m.UUID.uuid()},t,i||O);s.push(...pe.updated),l.push(...pe.added),o.push(...pe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:O}}}function br(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,y;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((y=s.implements)==null?void 0:y.id)});if(l){const d=new Ye({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new Ye({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:D.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var y,c;return!!u.implements&&((y=u.implements)==null?void 0:y.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new Ye({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new Ye({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:D.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function TS(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Bc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function ES(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===sd.Implements||t.field===sd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function IS(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function AS(r,a){return r.static&&(r.properties.forEach(t=>{t.static&&t.metaSync({static:!1},a)}),r.metaSync({static:!1},a)),r}var rP=(r=>(r.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",r.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",r))(rP||{});function nP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces.`,issue:null,severity:D.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s/g,"-")}}function sP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:D.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}if(t.includes("-")){const i=new Ye({id:r.id+"--string-value-must-not-have-dashes",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:D.Error,code:"string-value-must-not-have-dashes",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s|-/g,"_")}}function ws(r,a){const e=$n(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=ws(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function Wc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=Jt(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||ws(s,t).last?s:(ws(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function K(r,a){var i,s;let e=Wc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!ut.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(ot.includes(r.type))return;Je(r).forEach(l=>{var d,u;const o=Wc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!ut.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function aP(r,a,e=new Set){const t=sn(r),i=sn(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...aP(u,a,e)])),[]);return p([...l,...o])}function Ma(r,a){const e=ws(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function bS(r,a){return!!ws(r,a).last}function RS(r){if(at.includes(r.type))return r;if([...gi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return at.includes(a.type)?a:null}return null}function zc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return zc(e,t)}function Vt(r){if(Wa.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return a;if(a.type===n.Loop)return a}return r}else{const a=r.parent;return a?Vt(a):null}}function Kl(r,a){const e=Na(r,a);if(!e)return null;if(Wa.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Na(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Na(e.parent,a):null;return t?Kl(t,a):null}}function oP(r){if(!r)return null;if(gi.includes(r.type))return r;const a=r.parent;return a?oP(a):null}function lP(r){if(!r)return null;if(dt.includes(r.type))return r;const a=r.parent;return a?lP(a):null}function dP(r){if(!r)return null;if(Gi.includes(r.type))return r;const a=r.parent;return a?dP(a):null}function DS(r){return r.type===n.VariableDeclaration?[r]:dt.includes(r.type)?[...r.inputs,...r.outputs||[]]:ot.includes(r.type)?r.outputs:kn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function OS(r){const a=sn(r),e=[],t=[];df.includes(r.type)&&e.push(...Yc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:gi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>Ma(l,s)?-1:0),t.sort((s,l)=>Ma(l,s)?-1:0),[...e,...t,...i]}function uP(r){return[...r].sort((a,e)=>Ma(e,a)?-1:0)}function PS(r){const a=uP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];Ma(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function ti(r){const a=r.map(e=>Vt(e));return p(a)}function Yc(r){return dt.includes(r.type)?[...ti(r.successCalls),...ti(r.errorCalls)]:at.includes(r.type)?ti(r.calls):[]}function wS(r,a){return Yc(r).includes(a)}function Hc(r){return r.writesValues||[]}function CS(r,a){return Hc(r).includes(a)}function pP(r){var a;return it.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function VS(r){return r.writesValues}function cP(r=[]){return r.map(pP).filter(a=>!!a)}function Xl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>it.includes(a.type))}function fP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&it.includes(a.type))}function yP(r){return it.includes(r.type)?r:null}function hP(r){return r.writesValues.map(yP).filter(a=>!!a)}function mP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...hP(e)]:a,[])}function Je(r){return dt.includes(r.type)?[...er(ti(r.successCalls)),...er(ti(r.errorCalls))]:at.includes(r.type)?er(ti(r.calls)):[]}function BS(r){return dt.includes(r.type)?[...er(ti(r.successCalls)),...er(ti(r.errorCalls))]:at.includes(r.type)?er(ti(r.calls)):[]}function vP(r,a=new Set){return r.writesValues.filter(t=>it.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...He(i,a)],[])}function TP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>it.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...He(s,a)],[])}function He(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return fP(r.outputs).reduce((t,i)=>[...t,...He(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Je(r).reduce((s,l)=>{const o=Vt(l);return[...s,...He(o||l,a)]},[]),...cP(r.inputs),...mP(r.outputs)].reduce((s,l)=>[...s,...He(l,a)],[]);if(kn.includes(r.type)){const e=Xl(r.inputs),i=Je(r).reduce((s,l)=>{const o=Vt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Xl(r.inputs)],i=Je(r).reduce((s,l)=>{const o=Vt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l)],[])}if(it.includes(r.type)){a.add(r.id);const t=Je(r).reduce((i,s)=>{const l=Vt(s);return[...i,...He(l||s,a)]},[]);return[r,...t,...TP(r,a),...vP(r,a)]}return[]}function ui(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...sn(r).reduce((i,s)=>[...i,s,...ui(s,a)],[])])}function er(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Je(e)],[])}function EP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Xl(u.inputs),...er(ti(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...er(ti(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...er(ti(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function IP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return dt.includes(r.type)?zP(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function _S(r){const a=EP(r.project);return IP(r,a)}function Na(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Ql(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(fi.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,y=r,c=r,E=r,I=r,O=r,P=r,V=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(O.calledByEntry||[]).flatMap(G=>G),...(O.calledBySuccess||[]).flatMap(G=>G),...(O.calledByError||[]).flatMap(G=>G),...(s.extends||[]).flatMap(G=>G),...E.parent?[E.parent]:[]];Array.isArray(s.implements)?V.push(...s.implements.flatMap(G=>G)):c.implements&&V.push(c.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&V.push(...o.valueAsTypeList.flatMap(G=>G)),o.valueAsTypeSingle&&V.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(G=>G),...(I.inputsDeclarations||[]).flatMap(G=>G),...(t.outputs||[]).flatMap(G=>G),...(I.outputsDeclarations||[]).flatMap(G=>G),...(P.internalCalls||[]).flatMap(G=>G),...P.writesValues||[],...O.dataType?[O.dataType]:[],...d.body?[d.body]:[],...O.defaultValue?[O.defaultValue]:[],...(O.successCalls||[]).flatMap(G=>G),...(O.errorCalls||[]).flatMap(G=>G),...(s.properties||[]).flatMap(G=>G),...(s.methods||[]).flatMap(G=>G),...(s.abstractMethods||[]).flatMap(G=>G),...u.error?[u.error]:[],...u.process?[u.process]:[],...E.throws?[E.throws]:[],...(i.andChildrenGroup||[]).flatMap(G=>G),...(i.orChildrenGroup||[]).flatMap(G=>G),...(y.entities||[]).flatMap(G=>G),...(y.functions||[]).flatMap(G=>G),...(y.functionCalls||[]).flatMap(G=>G),...(y.events||[]).flatMap(G=>G),...(y.conditions||[]).flatMap(G=>G),...(y.operations||[]).flatMap(G=>G),...(y.loops||[]).flatMap(G=>G),...(y.variableDeclarations||[]).flatMap(G=>G),...(y.variableInstances||[]).flatMap(G=>G),...(y.searches||[]).flatMap(G=>G),...(y.projects||[]).flatMap(G=>G),...(l.calls||[]).flatMap(G=>G)];r.type===n.DataType&&(i.entity&&a[_(i.entity)]&&a[_(i.entity)].parent&&_(a[_(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&V.push(i.entity));const g={},B={};return V.forEach(G=>{const q=_(G);if(q&&e.ignoreBuiltInBaseEntities&&(fi.includes(G.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const W=G.version;q&&(g[q]=W)}),M.forEach(G=>{const q=_(G);if(q&&e.ignoreBuiltInBaseEntities&&(fi.includes(G.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const W=G.version;q&&(B[q]=W)}),{upstream:g,downstream:B}}function MS(r,a){const e=[];if(gi.includes(r.type)){Ii(r).forEach(s=>{const l=Kl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=Na(s,a);return l?HP(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(it.includes(r.type)){const t=ed(r);t&&e.push(t)}return p(e)}function $n(r){const a=[];if(gi.includes(r.type)){r.calledBy.forEach(i=>{const s=Vt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>ed(i)).filter(i=>i!==null);a.push(...p(t))}if(it.includes(r.type)){const e=ed(r);e&&a.push(e)}return p(a)}function Ii(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function AP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>j(t,a,e)),...r.outputs.flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.parent?j(r.parent,a,e):[]]}function bP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a):[],...r.writesValues.flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function RP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function DP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...(r.extends||[]).flatMap(t=>j(t,a,e))]}function OP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function PP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>j(t,a,e)),...(r.implements||[]).flatMap(t=>j(t,a,e)),...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>j(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>j(t,a,e)),...r.entity?j(r.entity,a,e):[],...r.parent?j(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.parent?j(r.parent,a,e):[]]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?j(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>j(t,a,e)):[],...r.parent?j(r.parent,a,e):[]]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.body?j(r.body,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e))]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>j(t,a,e)),...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.variableInstances||[]).flatMap(t=>j(t,a,e)),...(r.operations||[]).flatMap(t=>j(t,a,e)),...(r.conditions||[]).flatMap(t=>j(t,a,e)),...(r.functionCalls||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.loops||[]).flatMap(t=>j(t,a,e)),...(r.searches||[]).flatMap(t=>j(t,a,e))]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function kP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function ZP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function qP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function JP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function SP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function WP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ii(r)||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.parent?j(r.parent,a,e):[]]}function Ui(){const r=new Set,a=uI.flatMap(e=>j(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function j(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(fi.includes(r.type)||Ui().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return VP(r,a,e);case n.Operation:return $P(r,a,e);case n.Condition:return OP(r,a,e);case n.Loop:return UP(r,a,e);case n.Search:return qP(r,a,e);case n.GlobalEvent:return _P(r,a,e);case n.ReturnStatement:return ZP(r,a,e);case n.ContinueStatement:return PP(r,a,e);case n.BreakStatement:return RP(r,a,e);case n.VariableDeclaration:return SP(r,a,e);case n.DefinitionEntity:return wP(r,a,e);case n.FunctionDeclaration:return BP(r,a,e);case n.Project:return FP(r,a,e);case n.ActionDescriptor:return AP(r,a,e);case n.ArgumentDeclaration:return bP(r,a,e);case n.ReturnDeclaration:return kP(r,a,e);case n.ValueDescriptor:return JP(r,a,e);case n.InputMap:return MP(r,a,e);case n.OutputMap:return gP(r,a,e);case n.DataType:return CP(r,a,e);case n.InstalledProject:return NP(r,a,e);case n.InternalCall:return LP(r,a,e);case n.LiteralValue:return jP(r,a,e);case n.Property:return xP(r,a,e);case n.VariableInstance:return WP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:DP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:GP(r,a,e)}return[]}function Kc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||kn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function NS(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function zP(r){return dt.includes(r.type)?r.inputs:[]}function YP(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:ot.includes(r.type)?r.outputs:[]}function LS(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function jS(r){return r.type===n.Condition?[]:dt.includes(r.type)?r.outputs:[]}function ed(r){const a=r.readsValue;return a?Vt(a):null}function HP(r,a){const e=r.readsValue;return e?Kl(e,a):null}function KP(r){const a=r.internalCalls||[];return p(ti(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Cs(r){const a=Hc(r),e=[];return a.forEach(t=>{if(it.includes(t.type))e.push(t);else if(Dr.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function sn(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),ut.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:sn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>Vt(s)),i=r.errorCalls.map(s=>Vt(s));e.push(...t,...i)}if(kn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Cs(s)).flat(),i=r.calls.map(s=>Vt(s));e.push(...p(t),...i)}if(dt.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Cs(l)).flat(),i=r.successCalls.map(l=>Vt(l)),s=r.errorCalls.map(l=>Vt(l));e.push(...p(t),...i,...s)}if(it.includes(r.type)){const t=Cs(r),i=KP(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Cs(l)).flat();if(r.body){const l=sn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>Vt(l)),s=r.successCalls.map(l=>Vt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Cs(s)).flat(),i=r.calls.map(s=>Vt(s));e.push(...p(t),...i)}return p(e)}function XP(r,a=!1){const e=sn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...XP(s,a)],[])];return p(t)}function QP(r){const a=$n(r),e=[...a,...a.reduce((t,i)=>[...t,...QP(i)],[])];return p(e)}function La(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...La(e),...ja(e)]:[...a,e.name],[])}function ja(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...ja(e),...La(e)]:[...a,e.name],[])}function Xc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Xc(e),...Qc(e)]:[...a,e],[])}function Qc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Qc(e),...Xc(e)]:[...a,e],[])}function ef(r){return[...ja(r),...La(r)].filter((e,t,i)=>i.indexOf(e)===t)}function ew(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===S.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=ew(i);if(s)return s}return t},null)}function US(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function $S(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function tw(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function qt(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...qt(t)]:e,[]);return p(a)}function Ua(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!qt(r).find(t=>!t.interactive)}function gS(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function tf(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function iw(r){if([...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r))return!1;const a=$n(r);return a.length===0?!0:a.some(e=>iw(e))}function rf(r){return[...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||tf(r)?!1:$n(r).length===0}function rw(r,a=0){if(rf(r)){const e=$n(r);return e.length===0?r:e.map(i=>rw(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function nw(r){const a=[];if(rf(r))a.push(r);else return[];return $n(r).forEach(t=>{a.push(...nw(t))}),a}function sw(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function GS(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function $a(r){switch(r){case n.DefinitionEntity:return on;case n.FunctionDeclaration:return xr;case n.VariableDeclaration:return Yr;case n.VariableInstance:return zr;case n.FunctionCall:return nn;case n.Operation:return Zr;case n.Condition:return Wr;case n.ReturnStatement:return Fr;case n.Loop:return Sr;case n.Search:return Hr;case n.InputMap:return Ki;case n.OutputMap:return Xi;case n.ArgumentDeclaration:return Er;case n.ReturnDeclaration:return ei;case n.Property:return Gr;case n.InstalledProject:return Kr;case n.Project:return m;case n.DataType:return kr;case n.GlobalEvent:return qr;case n.InternalCall:return Xr;case n.ValueDescriptor:return Ir;case n.BuiltInBaseEntity:return $i;case n.PrimitiveEntity:return ii;case n.ActionDescriptor:return Se;case n.LiteralValue:return Qr;case n.ContinueStatement:return Ut;case n.BreakStatement:return Jr;default:return null}}function Jt(r,a){const e=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let t=e?a.get(e):null;if(r.type===n.ReturnStatement)return It(r,a);if(r.type===n.FunctionDeclaration&&(t==null?void 0:t.type)===n.Loop)return t;if(ut.includes(r.type))return r;if(fi.includes(r.type))return null;const i=r.parent;if(!i)return null;if(i.type===n.GenericReference){const s=_(i);if(!s)return null;const l=a.get(s);return l?Jt(l,a):null}else return i===a?a:Jt(i,a)}function It(r,a){const e=r!=null&&r.parent?_(r==null?void 0:r.parent):null;let t=e?a.get(e):null;if(r.type===n.FunctionDeclaration&&(t==null?void 0:t.type)===n.Loop)return It(t.parent,a);if(at.includes(r.type))return r;if(fi.includes(r.type))return null;const i=r.parent;if(!i)return null;if(i.type===n.GenericReference){const s=_(i);if(!s)return null;const l=a.get(s);return l?It(l,a):null}else return i===a?a:It(i,a)}function nf(r,a){if(fi.includes(r.type)||a.getBuiltIn(r.id))return null;const e=Ai(r.parent,a);return e?e===a?ut.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:nf(e,a):null}function td(r,a,e){if(r===a||a===e||r===e)return!1;const t=Jt(a.parent,e);return t===r?!0:td(t,a,e)}var id=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(id||{});function ga(r,a,e){const t=Jt(r,e),i=Jt(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(td(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(td(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=zc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:Jt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function aw(r,a,e){const t=ga(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=Jt(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=Jt(i.parent,e)}let s=Jt(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=Jt(s.parent,e)}return null}function ow(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=aw(e,t,t.project);return!i||i===t?e:t},r[0])}function Ai(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=_(r):e=r.id,e===a.id?a:a.get(e)}function an(r){if(!r)return null;if(fi.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:an(a)}function Ga(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=nf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Ga(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Ga(o);d.reachable||Je(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Je(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=Vt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=Ga(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function FS(r){return Wa.includes(r.type)?r.type===n.FunctionDeclaration?!sw(r):!0:!1}function xS(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function rd(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ja(r).includes(a)}function kS(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!La(r).includes(a)}function Fa(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ef(r).includes(a)}function ZS(r){const a=[];return r.entities.forEach(e=>{if(rd(e,S.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function qS(r){const a=[];return r.entities.forEach(e=>{if(rd(e,S.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function JS(r){return r.type!==n.DefinitionEntity||r.abstract||!rd(r,S.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][S.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function SS(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!Fa(r,S.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][S.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function WS(r){var e;if(!r||r.type!==n.DefinitionEntity||!Fa(r,S.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][S.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!pf.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function zS(r){switch(r){case n.Project:return m;case n.InstalledProject:return Kr;case n.DefinitionEntity:return on;case n.FunctionDeclaration:return xr;case n.GlobalEvent:return qr;case n.VariableInstance:return zr;case n.VariableDeclaration:return Yr;case n.InputMap:return Ki;case n.OutputMap:return Xi;case n.Condition:return Wr;case n.Operation:return Zr;case n.FunctionCall:return nn;case n.ReturnDeclaration:return ei;case n.ArgumentDeclaration:return Er;case n.PrimitiveEntity:return ii;case n.DataType:return kr;case n.Property:return Gr;case n.ActionDescriptor:return Se;case n.ReturnStatement:return Fr;case n.ContinueStatement:return Ut;case n.BreakStatement:return Jr;case n.Loop:return Sr;case n.Search:return Hr;case n.ValueDescriptor:return Ir;case n.InternalCall:return Xr;case n.LiteralValue:return Qr}return null}function YS(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function ct(r,a){const e=$a(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function nd(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=_(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...nd(t,a)]:[]}function HS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=Vt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function lw(r){const a=P7(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(y=>KS(r,y)),s=r.extends.flatMap(y=>XS(r,y)),l=eW(r),o=QS(r);r.methods.flatMap(y=>y.validate());const d=[...i,...s,...l,...o];return Ke(r.errors,d)}function dw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function uw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function KS(r,a){const e=[];if(!a.abstract){const y=de({id:r.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(y.error),e}const t=a.properties.filter(y=>y.abstract),i=[];let s=[...r.properties];t.forEach(y=>{const c=s.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===y.id});c?s=s.filter(E=>E.id!==c.id):i.push(y)}),i.length&&i.forEach(y=>{const c=de({id:r.id+"--"+F.MissingPropertyImplementation+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(y=>{const c=o.find(E=>{var I;return((I=E.implements)==null?void 0:I.id)===y.id});c?o=o.filter(E=>E.id!==c.id):l.push(y)}),l.length&&l.forEach(y=>{const c=de({id:r.id+"--"+F.MissingMethodImplementation+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(y=>{const c=s.find(E=>E.name===y.name);c&&d.push([c,y])}),d.length&&d.forEach(([y])=>{const c=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(y=>{const c=o.find(E=>E.name===y.name);c&&u.push([c,y])}),u.length&&u.forEach(([y])=>{const c=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function XS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=de({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=de({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function QS(r){const a=[];if(!r.properties.length){const e=de({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:D.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function eW(r){const a=[];if(r.abstract){if(r.methods.length){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=de({id:r.id+"--"+F.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:D.Error,code:F.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}if(r.properties.some(e=>e.abstract)){const e=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract properties`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(e.error),r.properties.forEach(t=>{if(t.abstract){const i=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(i.error)}})}}if(r.static&&r.properties.some(e=>!e.static)){const e=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as static but has non-static properties`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.static){const i=de({id:r.id+"--"+F.NonStaticPropertyInStaticEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:D.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function tW(r,a){const e=[],t=qt(a);if(!a.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+F.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new Ye({id:r.id+"--"+d.id+"--"+l.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{qt(l).forEach(y=>{const c=t.filter(E=>E.id!==y.id);c.length&&c.forEach(E=>{if(E.id!==y.id){const I=new Ye({id:r.id+"--"+E.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:y});e.push(I)}})});const d=br(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=br(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>qt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new Ye({id:r.id+"--"+a.id+"--"+l.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function iW(r,a,e=!1){const t=[],i=qt(a);if(!r.abstract&&a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.abstract&&!a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!r.static&&a.static){const y=de({id:r.id+"--"+a.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.static&&!a.static){const y=de({id:r.id+"--"+a.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!Ua(a)){const y=de({id:r.id+"--"+a.id+"--"+F.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(y.error)}const l=r.extends.filter(y=>y.id!==a.id);l.length&&l.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==y.id);c.length&&c.forEach(E=>{if(E.id!==y.id){const I=de({id:r.id+"--"+E.id+"--"+y.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${E.name}" with id "${E.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:y});t.push(I.error)}})}else{qt(y).forEach(M=>{const g=i.filter(B=>B.id!==M.id);g.length&&g.forEach(B=>{if(B.id!==M.id){const G=new Ye({id:r.id+"--"+B.id+"--"+M.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${B.name}" with id "${B.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push(G)}})});const E=!!qt(y).find(M=>M.id===a.id);let I=[...y.properties];E&&(I=I.filter(M=>!a.properties.find(g=>{var B;return g.id===M.id||g.name===M.name||g.id===((B=M.implements)==null?void 0:B.id)})));let O=[...y.methods];E&&(O=O.filter(M=>!a.methods.find(g=>{var B;return g.id===M.id||g.name===M.name||g.id===((B=M.implements)==null?void 0:B.id)})));const P=br(a.ownDeclaredProperties,I,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const V=br(a.abstractMethods,O,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...V.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(E=>E.id!==y.id);c.length&&c.forEach(E=>{if(E.id!==y.id){const I=new Ye({id:r.id+"--"+E.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${E.name}" with id "${E.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:E,secondRelationship:y});t.push(I)}})}else{qt(y).forEach(O=>{const P=i.filter(V=>V.id!==O.id);P.length&&P.forEach(V=>{if(V.id!==O.id){const M=new Ye({id:r.id+"--"+V.id+"--"+O.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${O.name}" with id "${O.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:V,secondRelationship:O});t.push(M)}})});const E=br(a.ownDeclaredProperties,y.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...E.errors);const I=br(a.abstractMethods,[...y.abstractMethods,...y.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...I.errors)}});const o=br(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=br(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(y=>qt(y))).forEach(y=>{if(!i.find(c=>c.id===y.id)){const c=new Ye({id:r.id+"--"+a.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:y});t.push(c)}}),t}function rW(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function nW(r){const a=[];if(r.implements.length){const e=new Ye({id:r.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function sW(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function aW(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const oW=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:uw,getBasePropertiesNotImplemented:dw,validate:lw,validateCanBecomeAbstract:nW,validateCanBecomeNonAbstract:aW,validateCanBecomeNonStatic:sW,validateCanBecomeStatic:rW,validateCanExtendEntity:iW,validateCanImplementEntity:tW},Symbol.toStringTag,{value:"Module"}));function lW(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var sd=(r=>(r.Extends="extends",r.Implements="implements",r))(sd||{});const Ue=class Ue extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"static");f(this,"abstract");f(this,"type",n.DefinitionEntity);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"implements",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestedProperties",[]);f(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=lW(i,t),o=Ac(i,t);s.push(...l,...o,...pt(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
406
406
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
407
407
  ${Qi({describe_entity:u.entity.id})}
408
408
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:s,modifiedData:i}}get interactive(){return this.implements.length?this.implements.every(e=>e.interactive):!0}get allBasePropertiesFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>t.type!==n.DefinitionEntity?[]:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[]),...this.implements.reduce((e,t)=>t.type!==n.DefinitionEntity?t.abstractMethods:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[])])}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])].filter(e=>!!e.abstract))}get extendedMethodsFromOriginalParents(){return p(this.extends.reduce((e,t)=>{if(t.type!==n.DefinitionEntity)return[];const i=[...t.ownDeclaredMethods,...t.extendedMethodsFromOriginalParents].filter(s=>s.type!==n.ActionDescriptor);return[...e,...i]},[]))}get implementedMethodsFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.type===n.DefinitionEntity?t.methods:[],s=[...t.abstractMethods].filter(l=>!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>[...t.abstractMethods,...e],[])].filter(e=>e.type===n.ActionDescriptor))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}get extendedMethods(){return this.methods.filter(e=>e.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(e=>!e.isExtendedMethod)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{fi.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{fi.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.extends.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addExtension(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),this.initialData.implements.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addImplementation(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:y}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...y);const{updated:c,added:E,removed:I,affected:O}=this.addExtendedProperties(e);t.push(...c),i.push(...E),s.push(...I),l.push(...O);const{updated:P,added:V,removed:M}=this.removeUnrecognizedProperties(e);t.push(...P),i.push(...V),s.push(...M);const{updated:g,added:B,removed:G,affected:q}=this.syncImplementationMethods(e);t.push(...g),i.push(...B),s.push(...G),l.push(...q);const{updated:W,added:X,removed:pe}=this.removeUnrecognizedMethods(e);return t.push(...W),i.push(...X),s.push(...pe),this.addSuggestions(),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}addExtension(e){return this.extends.includes(e)||this.extends.push(e),this}removeExtension(e){return this.extends=this.extends.filter(t=>t.id!==e.id),this}addImplementation(e){return this.implements.includes(e)||this.implements.push(e),this}removeImplementation(e){return this.implements=this.implements.filter(t=>t.id!==e.id),this}removeProperty(e){return this.properties=this.properties.filter(t=>t.id!==e.id),this}addMethod(e){return this.methods.includes(e)||(this.methods.push(e),this.suggestedMethods=this.suggestedMethods.filter(t=>t.name!==e.name)),this}removeMethod(e){return this.methods=this.methods.filter(t=>t.id!==e.id),this}addProperty(e){return this.properties.includes(e)||(this.properties.push(e),this.suggestedProperties=this.suggestedProperties.filter(t=>t.name!==e.name)),this}addSuggestedProperty(e){return this.suggestedProperties.includes(e)||this.suggestedProperties.push(e),this}addSuggestedMethod(e){return this.suggestedMethods.includes(e)||this.suggestedMethods.push(e),this}removeSuggestedProperty(e){return this.suggestedProperties=this.suggestedProperties.filter(t=>t.id!==e.id),this}removeSuggestedMethod(e){return this.suggestedMethods=this.suggestedMethods.filter(t=>t.id!==e.id),this}addAbstractMethod(e){return this.abstractMethods.includes(e)||this.abstractMethods.push(e),this}removeAbstractMethod(e){return this.abstractMethods=this.abstractMethods.filter(t=>t.id!==e.id),this}initChildren(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.methods=this.initialData.methods.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.extends=this.initialData.extends.map(t=>C(t,this.project)),this.implements=this.initialData.implements.map(t=>C(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-properties"))){const t=[],i=[],s=[],l=[];let o=[...this.properties];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedProperty);const d=this.implementedPropertiesFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(y=>{var c;return y.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const y=u.remove({ignoreUpstream:!1},e);s.push(...y.removed),t.push(...y.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedMethods(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-methods"))){const t=[],i=[],s=[],l=[];let o=[...this.methods];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedMethod);const d=this.implementedMethodsFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(y=>{var c;return y.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const y=u.remove({ignoreUpstream:!1},e);s.push(...y.removed),t.push(...y.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationMethods(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,d=this.implementedMethodsFromOriginalParents,u=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var O;return((O=I.implements)==null?void 0:O.id)===c.id})).forEach(c=>{if(this.methods.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===c.id}))return;const I=this.methods.find(P=>{var G,q;if(P.name===c.name&&!P.implements)return!0;const V=Fa(this,S.CRON_JOB),M=Fa(this,S.HTTP_ENDPOINT),g=((G=P.implements)==null?void 0:G.id)===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,B=((q=P.implements)==null?void 0:q.id)===k["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(V&&!B&&!M&&g||M&&!g&&!V&&B)});if(I&&I.type===n.FunctionDeclaration){I.setImplements(c),I.metaSync({name:c.name},e),e==null||e.add(I,b.Updated),e==null||e.add(this,b.Updated);return}const O=c.implementAsFunctionDeclaration(e,this);i.push(O),e==null||e.add(O,b.Added),this.addMethod(O)}),e==null||e.attemptAutoclose("sync-implementation-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationProperties(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.implementedPropertiesFromOriginalParents,u=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var O;return((O=I.implements)==null?void 0:O.id)===c.id})).forEach(c=>{if(this.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===c.id}))return;const I=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(I){I.implements=c,I.abstract=!1;return}const O=c.clone(e,this,m.UUID.uuid());O.initChildren(e),i.push(O),e==null||e.add(O,b.Added),O.setImplements(c,e),O.metaSync({abstract:!1},e),this.addProperty(O)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedProperties(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.extendedPropertiesFromOriginalParents,u=d.filter(c=>d.find(I=>{var O;return((O=I.implements)==null?void 0:O.id)===c.id})?!1:!c.abstract),y=new Set(o.map(c=>c.name));return u.forEach(c=>{if(y.has(c.name))return;y.add(c.name);const E=c.clone(e,this,m.UUID.uuid());E.initChildren(e),i.push(E),e==null||e.add(E,b.Added),this.addProperty(E)}),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{dw(this,e).forEach(s=>{const l=s.toJSON();l.id=`_suggestion--parent--${this.id}--${s.id}`;const o=C(l,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),uw(this,e).forEach(s=>{const l=`_suggestion--parent--${this.id}--${s.id}`,o=s.implementAsFunctionDeclaration(null,this,l),d=C(o,this.project);if(d.suggestion=!0,d.setParent(this,null),d.initChildren(null),this.methods=this.methods.filter(u=>u.id!==l),d.inputs.forEach(u=>{u.suggestion=!0}),d.returnStatements.length){const u=d.returnStatements[0];u.suggestion=!0,u.outputs.forEach(y=>{y.suggestion=!0})}this.addSuggestedMethod(d)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.static=e.static!==void 0?e.static:this.static,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.methods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const d=this.parent.setEntity(null);i.push(d)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:y}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...y)}),this.properties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.methods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.abstractMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedProperties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(i=>i.toFlat(e)),...this.implements.flatMap(i=>i.toFlat(e)),...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(i=>i.toFlatIds(e)),...this.implements.flatMap(i=>i.toFlatIds(e)),...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=J){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(u=>u.toJSONClone({...e,newId:null})),methods:this.methods.map(u=>u.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(u=>u.toJSONClone({...e,newId:null})),implements:this.implements.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),extends:this.extends.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toReference(e)),methods:this.methods.map(s=>s.toReference(e)),abstractMethods:this.abstractMethods.map(s=>s.toReference(e)),implements:this.implements.map(s=>s.toReference(e)),extends:this.extends.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e)),...this.implements.flatMap(i=>i.toFlatJSON(e)),...this.extends.flatMap(i=>i.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=lw(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=nt(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const E=(P=this.properties)==null?void 0:P.map(g=>g.clone(e,c,m.UUID.uuid(),s));c.properties=E;const I=(V=this.methods)==null?void 0:V.map((g,B)=>g.clone(e,c,y+"-method-"+B+"-id",s));c.methods=I;const O=(M=this.abstractMethods)==null?void 0:M.map((g,B)=>g.clone(e,c,y+"-abstract-method-"+B+"-id",s));return c.abstractMethods=O,e==null||e.attemptAutoclose("clone-entity",this.id),c}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"implement-definition-entity")),i){const s=Yl(this,e,t,i);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),s}getAllInteractiveMethods(){const e=this.implements.filter(i=>i.type===n.DefinitionEntity||i.type===n.BuiltInBaseEntity&&i.interactive);return p([...this.methods,...this.extends.flatMap(i=>i.getAllInteractiveMethods()),...e.flatMap(i=>i.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const i=[],s=[],l=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const d=[];e.forEach(c=>{d.find(I=>x(I,this.project)===x(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,g;const E=u.find(B=>x(B,this.project)===x(c,this.project));if(!E)return;const O=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=ji(O,t),V=P==null?void 0:P.clone(t,E,m.UUID.uuid(),!0);if(V){const B=(M=E.dataType)==null?void 0:M.merge(V,t);E.dataType&&(B==null?void 0:B.self.id)!==E.dataType.id&&E.dataType.remove({ignoreUpstream:!1},t),V.id!==((g=B==null?void 0:B.self)==null?void 0:g.id)&&V.remove({ignoreUpstream:!1},t),B!=null&&B.self&&(B.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(B.self,b.Added),E.setDataType(B.self),t==null||t.add(E,b.Updated))}c.setDeclaration(E),t==null||t.add(c,b.Updated)});const y=[];return d.forEach(c=>{if(!c.declaration){y.push(c);return}}),y.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(y.forEach(c=>{var B,G,q,W;const E=this.properties.find(X=>x(X,this.project)===x(c,this.project));if(E){if(c.setDeclaration(E),!E.getDataType(t)){const pe=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),Ee=ji(pe),Q=Ee==null?void 0:Ee.clone(t,E,m.UUID.uuid(),!0);if(Q){const le=(B=E.dataType)==null?void 0:B.merge(Q,t);E.dataType&&(le==null?void 0:le.self.id)!==E.dataType.id&&E.dataType.remove({ignoreUpstream:!1},t),Q.id!==((G=le==null?void 0:le.self)==null?void 0:G.id)&&Q.remove({ignoreUpstream:!1},t),le!=null&&le.self&&(le.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(le.self,b.Added),E.setDataType(le.self),t==null||t.add(E,b.Updated))}}return}const I={id:m.UUID.uuid(),type:n.Property,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:x(c,this.project),description:c.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:c.index,implements:null,dataType:null,parent:this.toReference()},O=C(I,this.project);O.setParent(this,t),O.initChildren(t),t==null||t.add(O,b.Added);const V=Un(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=ji(V),g=M==null?void 0:M.clone(t,O,m.UUID.uuid(),!0);if(g){const X=(q=O.dataType)==null?void 0:q.merge(g,t);O.dataType&&(X==null?void 0:X.self.id)!==O.dataType.id&&O.dataType.remove({ignoreUpstream:!1},t),g.id!==((W=X==null?void 0:X.self)==null?void 0:W.id)&&g.remove({ignoreUpstream:!1},t),X!=null&&X.self&&(X.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(X.self,b.Added),O.setDataType(X.self),t==null||t.add(O,b.Updated))}return this.addProperty(O),c.setDeclaration(O),t==null||t.add(c,b.Updated),O}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:p(i),updated:p(s),removed:p(l),affected:p(o),self:this})}};f(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ue,"type",n.DefinitionEntity),f(Ue,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),f(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),f(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),f(Ue,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),f(Ue,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),f(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),f(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let on=Ue;function dW(r){const a=s5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const Za=class Za extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"version");f(this,"name");f(this,"description",null);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",!1);f(this,"static");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"interactive",!1);f(this,"errors",[]);f(this,"project");this.initialData=this.initialData||e,this.project=this.project||t,this.id=this.id||e.id,this.version=this.version||e.version,this.name=this.name||e.name,this.static=this.static||e.static,this.interactive=this.interactive||e.interactive,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.extends=this.initialData.extends.map(i=>C(i,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=U,...t){return await Za.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.extends.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.extends.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=dW(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}implement(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),null,!0,"implement-built-in-base-entity")),i){const s=Yl(this,e,t,i);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),s}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Za&&e.push(...i.getAllInteractiveMethods())})),p(e)}};f(Za,"repository",{APILoad:async(e,...t)=>null});let $i=Za;function uW(r){const a=H3(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const dd=class dd extends lt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.PrimitiveEntity);f(this,"static");f(this,"abstract");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.static=e.static,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.parent=this,s})}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=U,...t){return await dd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=J){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=J){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=uW(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof $i&&e.push(...i.getAllInteractiveMethods())}),p(e)}};f(dd,"repository",{APILoad:async(e,...t)=>null});let ii=dd;function nt(r,a){if(!r)throw new Error("Entity is null");const e=a.get(r.id);switch(r.type){case n.LiteralValue:return e||new Qr(r,a);case n.DefinitionEntity:return e||new on(r,a);case n.PrimitiveEntity:return e||new ii(r,a);case n.FunctionDeclaration:return e||new xr(r,a);case n.GlobalEvent:return e||new qr(r,a);case n.DataType:return e||new kr(r,a);case n.Property:return e||new Gr(r,a);case n.FunctionCall:return e||new nn(r,a);case n.Condition:return e||new Wr(r,a);case n.Operation:return e||new Zr(r,a);case n.VariableDeclaration:return e||new Yr(r,a);case n.VariableInstance:return e||new zr(r,a);case n.OutputMap:return e||new Xi(r,a);case n.ReturnDeclaration:return e||new ei(r,a);case n.ArgumentDeclaration:return e||new Er(r,a);case n.InputMap:return e||new Ki(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Kr(r,a);case n.ActionDescriptor:return e||new Se(r,a);case n.ReturnStatement:return e||new Fr(r,a);case n.Loop:return e||new Sr(r,a);case n.Search:return e||new Hr(r,a);case n.ValueDescriptor:return e||new Ir(r,a);case n.BuiltInBaseEntity:return e||new $i(r,a);case n.InternalCall:return e||new Xr(r,a);case n.ContinueStatement:return e||new Ut(r,a);case n.BreakStatement:return e||new Jr(r,a);case n.GenericReference:return a.get(r.entityId);default:throw new Error("Invalid entity type: "+r.type)}}function C(r,a){if(!r)throw new Error("Entity is null");const e=nt(r,a);return e.subscribe(),e}function pW(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return Qr.fromGenerationTarget(r,a);case n.DefinitionEntity:return on.fromGenerationTarget(r,a);case n.FunctionDeclaration:return xr.fromGenerationTarget(r,a);case n.GlobalEvent:return qr.fromGenerationTarget(r,a);case n.DataType:return kr.fromGenerationTarget(r,a);case n.Property:return Gr.fromGenerationTarget(r,a);case n.FunctionCall:return nn.fromGenerationTarget(r,a);case n.Condition:return Wr.fromGenerationTarget(r,a);case n.Operation:return Zr.fromGenerationTarget(r,a);case n.VariableDeclaration:return Yr.fromGenerationTarget(r,a);case n.VariableInstance:return zr.fromGenerationTarget(r,a);case n.OutputMap:return Xi.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ei.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return Er.fromGenerationTarget(r,a);case n.InputMap:return Ki.fromGenerationTarget(r,a);case n.InstalledProject:return Kr.fromGenerationTarget(r,a);case n.ReturnStatement:return Fr.fromGenerationTarget(r,a);case n.Loop:return Sr.fromGenerationTarget(r,a);case n.Search:return Hr.fromGenerationTarget(r,a);case n.ActionDescriptor:return Se.fromGenerationTarget(r,a);case n.ValueDescriptor:return Ir.fromGenerationTarget(r,a);case n.InternalCall:return Xr.fromGenerationTarget(r,a);case n.ContinueStatement:return Ut.fromGenerationTarget(r,a);case n.BreakStatement:return Jr.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const J={seenEntityMaps:new Map,seenEntities:new Set,timestamp:T().toISOString()};class pw{constructor(){f(this,"initialData")}}const U={cascade:!1},cw={APILoad:async(r,...a)=>null},cW={APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoadVersion:async(r,a,...e)=>null,...cw};class fW{}class yW extends pw{}class hW{}class mW{}class vW{}class sf{}class TW extends sf{}class EW extends sf{}class IW{}class Rr{static initReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=C(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=Ai(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ut.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),a.readsValue.initChildren(null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}static hydrateReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=C(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=Ai(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ut.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}}class xa{static initWritesValues(a,e){const t=a.initialData.writesValues.reduce((s,l)=>{if(l.type===n.GenericReference||a.writesValues.some(d=>d.id===l.id))return s;const o=C(l,a.project);return o.setValueWriter(a,null),it.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class AW{}const re=class re extends lt{constructor(e){super(e);f(this,"initialData");f(this,"id");f(this,"type",n.Project);f(this,"name",null);f(this,"description",null);f(this,"x");f(this,"y");f(this,"entities",[]);f(this,"projects",[]);f(this,"functions",[]);f(this,"events",[]);f(this,"variableDeclarations",[]);f(this,"variableInstances",[]);f(this,"conditions",[]);f(this,"operations",[]);f(this,"functionCalls",[]);f(this,"loops",[]);f(this,"searches",[]);f(this,"primitives",[]);f(this,"builtInBaseEntities",[]);f(this,"operationDeclarations",[]);f(this,"globalEventActionDescriptors",[]);f(this,"loopDeclarations",[]);f(this,"loopDeclarationsBodies",[]);f(this,"conditionDeclarations",[]);f(this,"valueDescriptors",[]);f(this,"dataTypes",[]);f(this,"project");f(this,"instances",{});f(this,"builtInInstances",{});f(this,"deletedInstances",{});f(this,"errors",[]);f(this,"references",[]);f(this,"history",[]);f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"onCloseChangeSetCallback",null);this.initialData=e,this.id=e.id,this.name=e.name,this.description=e.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!re.UUID||re.UUID.isBackup)&&(re.UUID=qo==null?void 0:qo()),re.UUID||(re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:t=>t})}catch(t){console.error("Error initializing UUID module",t),re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){re.UUID=e}static new(e=null){return{id:re.UUID.uuid(),version:re.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||re.sessionAuthor,previousVersion:null,deleted:!1,type:n.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...pt(i)),{errors:s,modifiedData:i}}async closePendingChangeSets(){const e=this.history.find(t=>t.dirty&&!t.open);e&&await this.closeChangeSet(e)}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingChangeSets()}async closeChangeSet(e){const t=this.history.findIndex(l=>l.id===e.id),i=this.history.slice(0,t),s=i[i.length-1];if(!(s!=null&&s.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(e)).success&&(e.dirty=!1,this.closePendingChangeSets());return}}toLatestChangeSet(e,t,i,s=!1,l="here-this"){if(!this.history.length)return new A(this,e,t,i,s,l);const o=this.history[this.history.length-1];return o.open?o:this.addChangeSet(new A(this,e,t,i,s,l))}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(l=>l.id===(e==null?void 0:e.id));if(t)return t;const i=this.history.find(l=>l.open);if(i)throw console.warn("Previous still open: ",i),console.warn("New change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>T(e==null?void 0:e.timestamp).isBefore(T(l==null?void 0:l.timestamp)));return s===-1?this.history.push(e):this.history.splice(s,0,e),e}discardChangeSet(e){const t=this.history.findIndex(i=>i.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}redo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async i=>{await t.init(this),i(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(e=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=re.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new re(this);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[E,I]of c.knownVersions)u.set(E,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new re(u)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=null){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.validate(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e){const t=[],i=[],s=[],l=[];return this.subscribe(),this.subscribeToDependencies(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.projects=this.initialData.projects.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableInstances=this.initialData.variableInstances.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.conditions=this.initialData.conditions.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.operations=this.initialData.operations.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functions=this.initialData.functions.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functionCalls=this.initialData.functionCalls.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.loops=this.initialData.loops.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.searches=this.initialData.searches.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.getBuiltIn(e)?null:this.instances[e]||null}getBuiltIn(e){return this.builtInInstances[e]||null}findSubscribedInstanceFromReference(e){return this.instances[e.entityId]||null}findSubscribedBuiltInInstanceFromReference(e){return this.builtInInstances[e.entityId]||null}metaSync(e,t=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=ct(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,b.Added):i&&(t==null||t.add(this,b.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,re.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(i=>i.toFlat(e)),...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e)),...this.projects.flatMap(i=>i.toFlat(e)),...this.variableDeclarations.flatMap(i=>i.toFlat(e)),...this.variableInstances.flatMap(i=>i.toFlat(e)),...this.conditions.flatMap(i=>i.toFlat(e)),...this.operations.flatMap(i=>i.toFlat(e)),...this.functionCalls.flatMap(i=>i.toFlat(e)),...this.loops.flatMap(i=>i.toFlat(e)),...this.searches.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(i=>i.toFlatIds(e)),...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e)),...this.projects.flatMap(i=>i.toFlatIds(e)),...this.variableDeclarations.flatMap(i=>i.toFlatIds(e)),...this.variableInstances.flatMap(i=>i.toFlatIds(e)),...this.conditions.flatMap(i=>i.toFlatIds(e)),...this.operations.flatMap(i=>i.toFlatIds(e)),...this.functionCalls.flatMap(i=>i.toFlatIds(e)),...this.loops.flatMap(i=>i.toFlatIds(e)),...this.searches.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,i=new Set,s=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(l=>{if(s.includes(l)){t.set(l,l);return}t.set(l,re.UUID.uuid())}),i.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),projects:this.projects.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableDeclarations:this.variableDeclarations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableInstances:this.variableInstances.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),conditions:this.conditions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),operations:this.operations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functions:this.functions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),events:this.events.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functionCalls:this.functionCalls.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),loops:this.loops.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),searches:this.searches.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null}))}}toReference(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+re.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=J){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(s=>s.toReference(e)),functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),projects:this.projects.map(s=>s.toReference(e)),variableDeclarations:this.variableDeclarations.map(s=>s.toReference(e)),variableInstances:this.variableInstances.map(s=>s.toReference(e)),conditions:this.conditions.map(s=>s.toReference(e)),operations:this.operations.map(s=>s.toReference(e)),functionCalls:this.functionCalls.map(s=>s.toReference(e)),loops:this.loops.map(s=>s.toReference(e)),searches:this.searches.map(s=>s.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(i=>i.toFlatJSON(e)),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e)),...this.projects.flatMap(i=>i.toFlatJSON(e)),...this.variableDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.variableInstances.flatMap(i=>i.toFlatJSON(e)),...this.conditions.flatMap(i=>i.toFlatJSON(e)),...this.operations.flatMap(i=>i.toFlatJSON(e)),...this.functionCalls.flatMap(i=>i.toFlatJSON(e)),...this.loops.flatMap(i=>i.toFlatJSON(e)),...this.searches.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e)),...this.projects.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(i=>i.toFlatGenerationTarget(e)),...this.conditions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.operations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.loops.flatMap(i=>i.toFlatGenerationTarget(e)),...this.searches.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=A7(),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=C(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=C(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=C(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=C(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=C(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=C(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=C(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=C(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=C(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=C(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=C(e,this);return this.addSearch(t),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(i=>i.id===e.id);if(t>-1){const i=this.entities[t];return this.entities.splice(t,1),i}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(i=>i.id===e.id);if(t>-1){const i=this.functions[t];return this.functions.splice(t,1),i}return null}removeExternalProject(e){const t=this.projects.findIndex(i=>i.id===e.id);if(t>-1){const i=this.projects[t];return this.projects.splice(t,1),i}return null}removeGlobalEvent(e){const t=this.events.findIndex(i=>i.id===e.id);if(t>-1){const i=this.events[t];return this.events.splice(t,1),i}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(i=>i.id===e.id);if(t>-1){const i=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),i}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.ReturnStatement||l.type===n.ContinueStatement||l.type===n.BreakStatement)]},[])]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=He(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=Je(i);return[...t,...s.filter(l=>l.type===n.Search)]},[])]}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(i=>{if(!i.declaration){const s=i.initialData,l=s.declaration.entityId||s.declaration.id,o=t.find(d=>d.id===l);o&&i.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===S.PERSISTED_ENTITY)||null}};f(re,"sessionAuthor","1"),f(re,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),f(re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(re,"type",n.Project),f(re,"USER_MANAGED_PARENT_TYPES",[]),f(re,"PARENT_TYPES",[...re.USER_MANAGED_PARENT_TYPES]),f(re,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(re,"BASE_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,...re.INMUTABLE_BASE_PROPERTIES]),f(re,"MUTABLE_META_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,"x","y"]),f(re,"INMUTABLE_META_PROPERTIES",[...re.INMUTABLE_BASE_PROPERTIES]),f(re,"META_PROPERTIES",[...re.MUTABLE_META_PROPERTIES,...re.INMUTABLE_META_PROPERTIES]),f(re,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(re,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),f(re,"UPSTREAM_PROPERTIES",[...re.MUTABLE_UPSTREAM_PROPERTIES,...re.INMUTABLE_UPSTREAM_PROPERTIES]),f(re,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),f(re,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(re,"DOWNSTREAM_PROPERTIES",[...re.MUTABLE_DOWNSTREAM_PROPERTIES,...re.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(re,"PROPERTIES",[...re.META_PROPERTIES,...re.UPSTREAM_PROPERTIES,...re.DOWNSTREAM_PROPERTIES]);let m=re;var fw=(r=>(r.PersistChangeSet="persist-change-set",r.CreateSingle="create-single",r.CreateBulk="create-bulk",r.CreateSingleNested="create-single-nested",r.CreateBulkNested="create-bulk-nested",r.Update="update",r.Clone="clone",r.Delete="delete",r.Load="load",r.LoadNested="load-nested",r.LoadVersion="load-version",r))(fw||{});class yw extends Se{constructor(e){super(Vi,e);f(this,"id",Qe.Parallel);f(this,"name",Qe.Parallel);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",Vi);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Vi.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Vi.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Vi.error?C(Vi.error,this.project):null}}class hw extends Se{constructor(e){super(Wt,e);f(this,"id",Wt.id);f(this,"name",Wt.name);f(this,"description",Wt.description);f(this,"version",Wt.version);f(this,"autoexecutable",!1);f(this,"initialData",Wt);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Wt.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Wt.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Wt.error?C(Wt.error,this.project):null}}class mw extends Se{constructor(e){super(or,e);f(this,"id",Qe.Sequential);f(this,"name",Qe.Sequential);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",or);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=or.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=or.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=or.error?C(or.error,this.project):null}}class bW extends Se{constructor(a){super(Ms,a)}}class RW extends Se{constructor(a){super(un,a)}}class DW extends Se{constructor(e){super(pn,e);f(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[tt.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[tt.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[tt.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-entity-to-match-validate-data"))){let i=null;if(e.readsValue){const l=e.readsValue.getDataType(t);l&&l.entity&&l.entity.type===n.DefinitionEntity&&(i=l.entity)}const s=e.getDefaultValue();return!i&&s&&s.valueAsTypeSingle&&!Array.isArray(s.valueAsTypeSingle)&&s.valueAsTypeSingle.type===n.DefinitionEntity&&(i=s.valueAsTypeSingle),i}syncOperationInstance(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const i=[],s=[],l=[],o=[],d=this.getEntityToMatchInputMap(e);if(d){const{added:c,updated:E,removed:I,affected:O}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...E),s.push(...c),l.push(...I),o.push(...O)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:E,removed:I,affected:O}=this.syncDataToValidateInputMapDataType(u,t);i.push(...E),s.push(...c),l.push(...I),o.push(...O)}const y=this.getOutputDataOutputMap(e);if(y){const{added:c,updated:E,removed:I,affected:O}=this.syncOutputDataOutputMapDataType(y,t);i.push(...E),s.push(...c),l.push(...I),o.push(...O)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var u,y,c;const i=[],s=[],l=[],o=[];if(((u=e.declaration)==null?void 0:u.id)!==k.operation[tt.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 E={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},I=C(E,e.project);I.setParent(e,t),I.initChildren(t),t==null||t.add(I,b.Added),i.push(I),e.setDataType(I)}(y=e.dataType)==null||y.metaSync({inferred:!0,like:!1,asType:!0},t);const d=this.getEntityToMatch(e,t);return(c=e.dataType)==null||c.setEntity(d),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var c,E,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[tt.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,b.Added),i.push(P),e.setDataType(P)}(E=e.dataType)==null||E.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var c,E,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[tt.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,b.Added),i.push(P),e.setDataType(P)}(E=e.dataType)==null||E.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var s,l;if(((s=e.declaration)==null?void 0:s.id)===k.operation[tt.Validate].inputs.dataToValidate.id){const{added:o,updated:d,removed:u,affected:y}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(d),added:p(o),removed:p(u),affected:p(y),self:e.dataType}}const i=(l=e.declaration)==null?void 0:l.getDataType(t);if(i&&i.isResolved)return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:i};if(e.readsValue){const o=ji(e.readsValue,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:o}}return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var i;if(((i=e.declaration)==null?void 0:i.id)===k.operation[tt.Validate].outputs.outputEntity.id){const{added:s,updated:l,removed:o,affected:d}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:p(l),added:p(s),removed:p(o),affected:p(d),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class OW extends Se{constructor(a){super(Ad,a)}}class PW extends Se{constructor(a){super(Rd,a)}}class wW extends Se{constructor(a){super(Dd,a)}}class CW extends Se{constructor(a){super(Xa,a)}}class VW extends Se{constructor(a){super(Ya,a)}}class BW extends Se{constructor(a){super(_s,a)}}function _W(r){const a=[new mw(r),new yw(r),new hw(r),new bW(r),new RW(r),new DW(r),new CW(r),new OW(r),new wW(r),new PW(r),new VW(r),new BW(r),new Se(Id,r),new Se(Ed,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class vw extends $i{constructor(e){super(_t,e);f(this,"initialData");f(this,"id",S.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",S.PERSISTED_ENTITY);f(this,"description",_t.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",_t.abstract);f(this,"static",_t.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=_t,this.project=e,this.id=_t.id,this.version=_t.version,this.name=_t.name,this.static=_t.static,this.abstract=_t.abstract,this.properties=this.initialData.properties.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.methods=this.initialData.methods.map(t=>{const i=C(t,this.project);return i.parent=this,i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=C(t,this.project);return i.parent=this,i}),this.extends=this.initialData.extends.map(t=>C(t,this.project))}}var Tw=(r=>(r.StatusCodeMustBeNumber="status-code-must-be-number",r.StatusCodeMustBeBetween100And599="status-code-must-be-between-100-and-599",r))(Tw||{});function Ew(r,a){const e=[];if(typeof a!="number"){const t=new Ye({id:r.id+"--status-code-must-be-number",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number.`,issue:null,severity:D.Error,code:"status-code-must-be-number",entity:r});return e.push(t),{errors:e,override:a}}if(a<100){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:D.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}if(a>599){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:D.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}return{errors:e,override:a}}class Iw extends $i{constructor(e){super(ni,e);f(this,"initialData");f(this,"id",S.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",S.PERSISTED_ENTITY);f(this,"description",ni.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",ni.abstract);f(this,"static",ni.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=ni,this.project=e,this.id=ni.id,this.version=ni.version,this.name=ni.name,this.static=ni.static,this.abstract=ni.abstract,this.properties=this.initialData.properties.map(l=>{const o=C(l,this.project);return o.setParent(this,null),o.initChildren(null),o}),this.methods=this.initialData.methods.map(l=>{const o=C(l,this.project);return o.parent=this,o}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const o=C(l,this.project);return o.parent=this,o}),this.extends=this.initialData.extends.map(l=>C(l,this.project));const t=this.properties.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.path.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(l,o)=>nP(l,o);const i=this.abstractMethods.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id);if(!i)throw new Error("Handler method not found in endpoint entity");const s=i.outputs.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.outputs.statusCode.id);if(!s)throw new Error("Status code output not found in handler method");s.codeNativeValueValidation=(l,o)=>Ew(l,o)}}const MW="test_primitive_entities_export";class NW extends $i{constructor(e){super(Dt,e);f(this,"initialData");f(this,"id",S.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",S.PERSISTED_ENTITY);f(this,"description",Dt.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",Dt.abstract);f(this,"static",Dt.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=Dt,this.project=e,this.id=Dt.id,this.version=Dt.version,this.name=Dt.name,this.static=Dt.static,this.abstract=Dt.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.parent=this,s}),this.extends=this.initialData.extends.map(i=>C(i,this.project));const t=this.properties.find(i=>i.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(i,s)=>sP(i,s)}}function LW(r){const a=[new vw(r),new Iw(r),new NW(r),new $i(Dt,r),new $i(mo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function jW(r){const a=[new ii(ae,r),new ii(rr,r),new ii(ve,r),new ii(fd,r),new ii(wt,r),new ii(nr,r),new ii(Fi,r),new ii(sr,r),new ii(Zn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function UW(r){const a=[new Se(To,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function $W(r){const a=[new Se(Us,r),new Se(Or,r),new Se(Ls,r),new Se(Sn,r),new Se(Wn,r),new Se(ao,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new Se(po,r),new Se(js,r),new Se(lo,r),new Se($d,r),new Se(Gd,r),new Se(oo,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function gW(r){const a=[new Ir(Eo,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function GW(r){const a=[new Se(mn,r),new Se(Xn,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const gn={},ad={},ka={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function Aw(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new zl(e),s=new Set;t[e.id]=e,s.add(e.id);const l=T().toISOString();Object.values(t).forEach(u=>{!u||i.allBuiltInEntityIds.includes(u.id)||s.add(u.id)}),i.order=Array.from(s),i.flatRecord=t,i.orderEntities();const o=od(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new A(o,m.sessionAuthor,l,o,!0,"project-init-from-fetch-result")):null;return i.visit(u=>{if(u.id===o.id)return;const y=C(u,o);y.hydrateAncestors(),y.addSelfToProject(null)}),a?(i.visit(u=>{const y=o.get(u.id);y&&y.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):ld(o,l).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.attemptAutoclose("project-init-from-fetch-result",o.id),o}async function FW(r,a=ka){const e={...ka,...a};if(e.empty)return{data:{project:{id:r.id,type:n.Project,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(e.mock){const i={...up};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{try{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})}catch(s){console.error("Error fetching project: ",s),i({data:null})}})}function od(r){const a=new m(r);return jW(a),LW(a),_W(a),UW(a),$W(a),gW(a),GW(a),Array.from(new Set([...a.getAllBuiltInIds(),...Ui()])).forEach(t=>{if(!a.builtInInstances[t]&&a.instances[t])a.builtInInstances[t]=a.instances[t],delete a.instances[t];else if(!a.builtInInstances[t])throw new Error(`Built in entity was not properly initialized: ${t}`)}),a}function ld(r,a){return r.instancesList.filter(t=>T(t.createdAt).isAfter(T(a)||!!t.previousVersion))}function xW(r,{enrich:a}={enrich:!0}){const e=new Map,t=Array.from(new Set([...r.getAllBuiltInIds(),...Ui()]));Object.keys(r.instances).forEach(u=>{if(t.includes(u)){e.set(u,u);return}const y=r.get(u);if(!nd(y,{...r.instances,...r.builtInInstances}).every(I=>!t.includes(I))){e.set(u,u);return}e.set(u,m.UUID.uuid())});const i=T().toISOString(),s=r.toShallowJSON({seenEntityMaps:e});s.previousVersion=null,s.createdAt=i,s.version=m.UUID.uuid();const l=od(s),o=a?l.addChangeSet(new A(l,m.sessionAuthor,i,l,!0,"project-clone")):null,d=new zl(r);return d.visit(u=>{const y=u.toShallowJSON({seenEntityMaps:e});u.type===n.ValueDescriptor&&u.name==="Iteration result"&&(console.log("Og entity shallow copy: ",y),console.log("Og entity full: ",u)),y.previousVersion=null,y.createdAt=i,y.version=m.UUID.uuid();const c=C(y,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,b.Added)}),a?(d.visit(u=>{const y=l.get(e.get(u.id));y&&y.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):ld(l,i).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.attemptAutoclose("project-clone",l.id),l}function bw(r,{enrich:a}={enrich:!0}){const e=od(r),t=T().toISOString(),i=a?e.addChangeSet(new A(e,m.sessionAuthor,t,e,!0,"project-init")):null;i&&(i.type=Cc.Automatic);const s=new zl(r);return s.visit(l=>{const o=C(l,e);o.hydrateAncestors(),o.addSelfToProject(i)}),a?(s.visit(l=>{const o=e.get(l.id);o&&o.afterAllChildrenInitialized(i)}),e.afterAllChildrenInitialized(i)):ld(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.attemptAutoclose("project-init",e.id),e}async function kW(r,a=ka){const e={...ka,...a};if(r.id&&gn[r.id]&&!e.ignoreCache)return gn[r.id];if(r.id&&ad[r.id]&&!e.ignoreCache)return await ad[r.id],gn[r.id];const t=FW(r,e);r.id&&(ad[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=bw(up,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=Aw(i.data,{enrich:!!e.enrich}),gn[r.id]=s,r.id&&delete ad[r.id],s}return null}function ZW(r){return gn[r.id]&&delete gn[r.id],null}h.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=xc,h.ALL_BUILT_IN_BASE_ENTITIES=qE,h.ALL_BUILT_IN_CONDITION_ENTITIES=nI,h.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=aI,h.ALL_BUILT_IN_LOOP_BODY_ENTITIES=TT,h.ALL_BUILT_IN_LOOP_ENTITIES=vT,h.ALL_BUILT_IN_OPERATION_ENTITIES=V0,h.ALL_BUILT_IN_PRIMITIVE_ENTITIES=vf,h.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=uI,h.ALL_BUILT_IN_VALUE_DESCRIPTORS=dI,h.ActionDescriptorState=Se,h.ActionInputMapState=KJ,h.ActionOutputMapState=eS,h.AppendToListOperationInputIds=Oh,h.AppendToListOperationOutputIds=Ph,h.ArgumentDeclarationDependencyField=j1,h.ArgumentDeclarationState=Er,h.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=$c,h.BUILT_IN_BASE_ENTITY_IDS=k,h.BUILT_IN_ENTITY_TYPES=fi,h.BaseCanvasDraggableState=hW,h.BaseEntityNames=S,h.BaseState=yW,h.BaseValueDescriptorIds=za,h.BreakStatementDependencyField=_c,h.BreakStatementState=Jr,h.BuiltInBaseEntityState=$i,h.CACHED_PROJECTS_BY_ID=gn,h.CALLABLE_ENTITIES_EXPLANATION=lS,h.CALLABLE_TYPES=gi,h.CALLER_ENTITIES_EXPLANATION=k1,h.CALLER_TYPES=Gi,h.CALLS_UPDATE_EXPLANATION=tn,h.COMPARISON_CONDITIONS=iI,h.CONDITIONS=rI,h.CUSTOM_ENTITY_OPERATIONS=Wm,h.CallableEntityClass=vW,h.CallerEntityClass=sf,h.ChangeSet=A,h.ChangeSetChangeCaptureType=Cc,h.ChangeSetEntityChangeType=b,h.ChildEntityState=mW,h.CommonStringValidationErrorCodes=rP,h.ComparisonOperatorTypes=yt,h.ConditionDependencyField=I1,h.ConditionState=Wr,h.ContinueStatementDependencyField=Vc,h.ContinueStatementState=Ut,h.CreateNewInputIds=Am,h.CreateNewOutputIds=bm,h.DRAGGABLE_CALLABLE_TYPES=cd,h.DRAGGABLE_CALLER_TYPES=df,h.DRAGGABLE_ELEMENT_TYPES=Wa,h.DRAGGABLE_EXECUTABLE_TYPES=ww,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Sa,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=pd,h.DataTypeCompatibilityTypes=Pi,h.DataTypeDependencyField=Bc,h.DataTypeParentChildRelation=Pt,h.DataTypeState=kr,h.DefinitionEntityDependencyField=sd,h.DefinitionEntityState=on,h.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=cW,h.ENTITIES_WITH_VALLUES_EXPLANATION=Zl,h.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=U,h.ENTITY_RECUSION_OPTIONS_DEFAULTS=J,h.ENTITY_TYPES=Cw,h.ENTITY_WITH_DECLARATION_TYPES=Ow,h.ENTITY_WITH_LOGIC_SCOPE_TYPES=ut,h.ENTITY_WITH_NAMES_TYPES=uf,h.ENTITY_WITH_PARENT_TYPES=Rw,h.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=of,h.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=Dw,h.ENTITY_WITH_VALUE_TYPES=af,h.ENTRY_POINT_ENTITIES_EXPLANATION=Ba,h.ENTRY_POINT_TYPES=at,h.EVENT_TYPES=kn,h.EXECUTABLE_TYPES=Pw,h.EXECUTION_OPERATIONS=Im,h.EndpointEntity=Iw,h.EntityAction=fw,h.EntityError=Ye,h.EntityErrorSeverity=D,h.EntityGenerationError=w,h.EntityGenerationErrorCode=R,h.EntityInstanceErrorCode=F,h.EntityOperations=tt,h.EntityType=n,h.EntityWithLogicScopeClass=AW,h.EntityWithValueClass=IW,h.EntryPointEntityClass=TW,h.ExecutionOperations=Qe,h.ExecutionTerminationType=v1,h.FunctionCallDependencyField=Q1,h.FunctionCallState=nn,h.FunctionDeclarationDependencyField=u1,h.FunctionDeclarationState=xr,h.GET_PROJECT_OPTIONS_DEFAULTS=ka,h.GLOBAL_EVENT_DECLARATIONS=sI,h.GetLastInListOperationInputIds=fh,h.GetLastInListOperationOutputIds=yh,h.GlobalEventNames=ir,h.GlobalEventState=qr,h.HTTPOperations=Lt,h.HTTPStatucCodeValidationErrorCodes=Tw,h.HTTP_OPERATIONS=w0,h.InputMapDependencyField=_1,h.InputMapState=Ki,h.InstalledProjectState=Kr,h.InternalCallDependencyField=V1,h.InternalCallState=Xr,h.JoinListOperationInputIds=Ny,h.JoinListOperationOutputIds=Ly,h.LIST_OPERATIONS=Gh,h.ListOperations=he,h.LiteralValueDependencyField=$1,h.LiteralValueState=Qr,h.LoopDependencyField=T1,h.LoopState=Sr,h.LoopTypes=ee,h.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=rn,h.NUMBER_OPERATIONS=Wf,h.NumberOperations=et,h.OPERATION_DECLARATIONS=C0,h.OperationDependencyField=f1,h.OperationState=Zr,h.OutputMapDependencyField=N1,h.OutputMapParentChildRelation=xn,h.OutputMapState=Xi,h.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=ql,h.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=en,h.PASS_THROUGH_CALLABLE_TYPES=dt,h.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=lf,h.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Fc,h.ParallelExecutionOperation=yw,h.PassThroughCallableEntityClass=EW,h.PersistedEntity=vw,h.PersistedEntityMethods=ci,h.PrimitiveEntityState=ii,h.PrimitiveTypes=L,h.ProjectState=m,h.PropertyDependencyField=n1,h.PropertyState=Gr,h.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=cw,h.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=dS,h.ReturnDeclarationDependencyField=a1,h.ReturnDeclarationState=ei,h.ReturnStatementDependencyField=Gl,h.ReturnStatementState=Fr,h.STANDALONE_CONDITIONS=WE,h.STRING_OPERATIONS=My,h.ScopeCompatibilityType=id,h.SearchDependencyField=O1,h.SearchState=Hr,h.SequentialExecutionOperation=mw,h.SequentialExecutionOperationInputIds=om,h.SequentialExecutionOperationOutputIds=lm,h.SharedEntityErrorCode=$,h.SharedStateFunctionality=pw,h.SplitListOperationInputIds=Yy,h.SplitListOperationOutputIds=Hy,h.StandaloneOperatorTypes=bi,h.StringOperations=Ie,h.TERMINATION_TYPES=ot,h.Traverser=zl,h.USER_MANAGED_ENTITY_TYPES=pf,h.UserManagedEntityStateTemplate=fW,h.VALUE_READING_ENTITIES_EXPLANATION=Gc,h.VALUE_READING_TYPES=Dr,h.VALUE_WRITING_ENTITIES_EXPLANATION=Z1,h.VALUE_WRITING_TYPES=Tt,h.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=gc,h.VARIABLE_TYPES=it,h.ValueAutogenerationType=vt,h.ValueDescriptorDependencyField=G1,h.ValueDescriptorParentChildRelation=N,h.ValueDescriptorState=Ir,h.ValueReadingEntityClass=Rr,h.ValueWritingEntityClass=xa,h.VariableDeclarationDependencyField=R1,h.VariableDeclarationState=Yr,h.VariableInputMapState=HJ,h.VariableInstanceDependencyField=Nc,h.VariableInstanceState=zr,h.VariableOutputMapState=QJ,h.WaitOperation=hw,h.WaitOperationInputIds=em,h.WaitOperationOutputIds=tm,h.actionDescriptorValidation=kJ,h.appendToListOperation=Xa,h.appendToListOperationElementToAppendArgument=Pd,h.appendToListOperationElementToAppendArgumentParentRef=Lh,h.appendToListOperationElementToAppendArgumentRef=Vh,h.appendToListOperationError=gh,h.appendToListOperationErrorParentRef=$h,h.appendToListOperationListArgument=Od,h.appendToListOperationListArgumentParentRef=Nh,h.appendToListOperationListArgumentRef=wh,h.appendToListOperationListDataType=Ch,h.appendToListOperationResultListDataType=Mh,h.appendToListOperationResultListReturn=Uh,h.appendToListOperationResultListReturnParentRef=jh,h.appendToListOperationResultListReturnRef=_h,h.appendToListOperationSecondListDataType=Bh,h.applyNewScope=K,h.argumentDeclarationValidation=tS,h.asGenerationActionExample=Qi,h.booleanPrototype=rr,h.breakStatementValidation=GJ,h.calculateNewParentBasedOnCallers=Wc,h.capitalizeFirstLetter=Zt,h.changeSetJSONRecordToUniqueIds=wJ,h.checkAreDataTypesCompatible=wi,h.checkAreDefinitionEntitiesCompatibleAsDataType=ZO,h.checkArePropertiesCompatibleAsDataType=kO,h.checkExtendsBaseEntity=rd,h.checkHasBaseEntity=Fa,h.checkHasMetadataChanged=ct,h.checkImplementationsOverlap=br,h.checkImplementsBaseEntity=kS,h.checkIsBranchDependentButNotDirectlyOnBranch=Ma,h.checkIsBranchDependentOnBranch=bS,h.checkIsCallableEntityReachable=Ga,h.checkIsCanvasEntity=FS,h.checkIsDetachedBranch=iw,h.checkIsDetachedBranchShallow=rf,h.checkIsGlobalVariable=gS,h.checkIsGloballyDeclared=tf,h.checkIsMethod=sw,h.checkIsNestedScope=td,h.checkScopeCompatibility=ga,h.cloneProject=xW,h.conditionValidation=ZJ,h.continueStatementValidation=BJ,h.convertToAbstract=TS,h.convertToNonAbstract=ES,h.convertToNonStatic=AS,h.convertToStatic=IS,h.countedLoopActionDescriptor=Us,h.countedLoopActionDescriptorDynamicReturnDeclaration=dT,h.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=lT,h.countedLoopActionDescriptorStringArgumentDeclaration=oT,h.countedLoopActionDescriptorStringArgumentDeclarationDataType=sT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=rT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=iT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=nT,h.countedLoopActionDescriptorStringArgumentDeclarationParentRef=aT,h.countedLoopBodyActionDescriptor=po,h.countedLoopBodyActionDescriptorAnyDynamicArgument=yT,h.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=fT,h.countedLoopBodyActionDescriptorAnyDynamicReturn=mT,h.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=hT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=xd,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=pT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=uT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=cT,h.createDefinitionEntityFromJSONObject=Hl,h.createEntityError=de,h.createNestedDataTypeForEntity=iP,h.createNewInstanceOperation=un,h.createNewInstanceOperationEntityToInstanciateArgument=Bm,h.createNewInstanceOperationEntityToInstanciateArgumentRef=wm,h.createNewInstanceOperationEntityToInstanciateDataType=Cm,h.createNewInstanceOperationError=Lm,h.createNewInstanceOperationErrorParentRef=Nm,h.createNewInstanceOperationNewEntityDataArgument=Pm,h.createNewInstanceOperationNewEntityDataArgumentDataType=Om,h.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Dm,h.createNewInstanceOperationNewEntityDataArgumentParentRef=Rm,h.createNewInstanceOperationOutputEntityDeclaration=Mm,h.createNewInstanceOperationOutputEntityDeclarationParentRef=_m,h.createNewInstanceOperationRef=Vm,h.createSemanticId=t1,h.createStateFromGenerationTargetType=pW,h.createStateFromType=nt,h.createStateFromTypeAndSubscribe=C,h.cronJobBuiltInBaseEntity=mo,h.cronJobBuiltInBaseEntityExpressionProperty=kE,h.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Uw,h.cronJobBuiltInBaseEntityExpressionPropertyRef=FE,h.cronJobBuiltInBaseEntityRef=xE,h.cronJobTriggeredFunctionDeclarationBlueprint=tu,h.cronJobTriggeredFunctionDeclarationBlueprintParentRef=gE,h.dataTypeCompatibilityToErrorExplanation=K1,h.dataTypeValidation=LJ,h.datePrototype=Fi,h.dateValueAutogenerationSchema=hp,h.definitionEntityToZodSchema=PI,h.definitionEntityValidation=oW,h.deletePersistedEntityMethod=eu,h.deletePersistedEntityMethodParentRef=RE,h.deleteRootProject=ZW,h.endpointBuiltInBaseEntity=ni,h.endpointBuiltInBaseEntityRef=bT,h.endpointBuiltInBaseEntityRefFour=nE,h.endpointBuiltInBaseEntityRefThree=_T,h.endpointBuiltInBaseEntityRefTwo=wT,h.endpointBuiltInCorsProperty=RT,h.endpointBuiltInCorsPropertyDataType=AT,h.endpointBuiltInCorsPropertyDataTypeRef=ET,h.endpointBuiltInCorsPropertyRef=IT,h.endpointBuiltInMethodProperty=Zd,h.endpointBuiltInMethodPropertyDataType=BT,h.endpointBuiltInMethodPropertyDataTypeRef=CT,h.endpointBuiltInMethodPropertyRef=VT,h.endpointBuiltInPathProperty=kd,h.endpointBuiltInPathPropertyDataType=PT,h.endpointBuiltInPathPropertyDataTypeRef=DT,h.endpointBuiltInPathPropertyRef=OT,h.endpointPathParamsArgumentDeclaration=Jd,h.endpointPathParamsArgumentDeclarationRef=xT,h.endpointPathParamsVariableDataType=kT,h.endpointPathParamsVariableDataTypeRef=FT,h.endpointReachedTriggerActionDescriptor=Kd,h.endpointReachedTriggerActionDescriptorRef=ZT,h.endpointReachedTriggerActionDescriptorRefFour=ST,h.endpointReachedTriggerActionDescriptorRefThree=JT,h.endpointReachedTriggerActionDescriptorRefTwo=qT,h.endpointRequestBodyArgumentDeclaration=Wd,h.endpointRequestBodyArgumentDeclarationRef=jT,h.endpointRequestBodyVariableDataType=UT,h.endpointRequestHeadersArgumentDeclaration=qd,h.endpointRequestHeadersArgumentDeclarationRef=NT,h.endpointRequestHeadersVariableDataType=LT,h.endpointRequestHeadersVariableDataTypeRef=MT,h.endpointRequestQueryParamsArgumentDeclaration=Sd,h.endpointRequestQueryParamsArgumentDeclarationRef=gT,h.endpointRequestQueryParamsVariableDataType=GT,h.endpointRequestQueryParamsVariableDataTypeRef=$T,h.endpointResponseBodyDataType=iE,h.endpointResponseBodyReturnDeclaration=Hd,h.endpointResponseBodyReturnDeclarationRef=tE,h.endpointResponseCodeDataType=zT,h.endpointResponseCodeReturnDeclaration=zd,h.endpointResponseCodeReturnDeclarationDefaultValueParentRef=HT,h.endpointResponseCodeReturnDeclarationRef=WT,h.endpointResponseHeadersDataType=QT,h.endpointResponseHeadersDataTypeRef=KT,h.endpointResponseHeadersReturnDeclaration=Yd,h.endpointResponseHeadersReturnDeclarationRef=XT,h.endpointReturnStatementRef=YT,h.endpointReturnStatementRefThree=rE,h.endpointReturnStatementRefTwo=eE,h.enrichFromKnownEntities=Na,h.enumOptionsProperty=mf,h.enumOptionsPropertyDataType=yf,h.enumOptionsPropertyDataTypeRef=cf,h.enumOptionsPropertyRef=ff,h.enumPrototype=nr,h.enumPrototypeRef=hf,h.executionBuiltInBaseEntity=vo,h.executionBuiltInEntityAbortMethod=iu,h.executionBuiltInEntityAbortMethodParentRef=ZE,h.filterOutDuplicateEntities=p,h.filterOutDuplicateErrors=x3,h.findEntityFromKeys=Jc,h.findReferenceToSelfInList=IP,h.findReferencesToSelfInProject=_S,h.flattenActionDescriptor=AP,h.flattenArgumentDeclaration=bP,h.flattenBreakStatement=RP,h.flattenBuiltInBaseEntity=DP,h.flattenCalls=er,h.flattenCanvasAncestorsUntil=ws,h.flattenCondition=OP,h.flattenContinueStatement=PP,h.flattenDataType=CP,h.flattenDefinitionEntity=wP,h.flattenDefinitionEntityExtensionAndImplementationTypes=ef,h.flattenDefinitionEntityExtensionTypes=ja,h.flattenDefinitionEntityExtensions=Xc,h.flattenDefinitionEntityImplementations=Qc,h.flattenDefinitionEntityImplementionTypes=La,h.flattenDerivedCanvasEntities=ui,h.flattenDetachedBranch=nw,h.flattenElementCalls=Je,h.flattenElementCallsOnTheSameScope=BS,h.flattenEntity=j,h.flattenFunctionCall=VP,h.flattenFunctionDeclaration=BP,h.flattenGlobalEvent=_P,h.flattenInputMap=MP,h.flattenInstalledProject=NP,h.flattenInternalCall=LP,h.flattenLiteralValue=jP,h.flattenLoop=UP,h.flattenOperation=$P,h.flattenOutputMap=gP,h.flattenPrimitiveEntity=GP,h.flattenProject=FP,h.flattenProjectElements=EP,h.flattenProperty=xP,h.flattenRelatedCanvasElementsOnTheLeft=QP,h.flattenRelatedCanvasElementsOnTheRight=XP,h.flattenReturnDeclaration=kP,h.flattenReturnStatement=ZP,h.flattenSearch=qP,h.flattenValueDescriptor=JP,h.flattenVariableDeclaration=SP,h.flattenVariableInstance=WP,h.flattenVariableReads=TP,h.flattenVariableWrites=vP,h.flattenVariables=He,h.fromChangeSetToRecordChangeSet=YS,h.fromZodParseToEntityGenerationErrors=Lc,h.functionCallValidation=vS,h.functionDeclarationValidation=NJ,h.generate=FV,h.generateActionExample=uS,h.generateExecutionDataType=TJ,h.generateIdFromStrategy=ht,h.generateMutablePropertiesExplanation=Fl,h.generateRandomBoolean=QI,h.generateRandomDate=BI,h.generateRandomDateAfter=wI,h.generateRandomDateBefore=CI,h.generateRandomDateBetweenRange=VI,h.generateRandomNumber=zI,h.generateRandomNumberAfter=JI,h.generateRandomNumberBefore=SI,h.generateRandomNumberBetweenRange=WI,h.generateRandomText=XI,h.generateRandomTextAfter=YI,h.generateRandomTextBefore=HI,h.generateRandomTextBetweenRange=KI,h.generateUniqueUUID=qI,h.getAllActionDescriptorsForConditions=Wl,h.getAllActionDescriptorsForGlobalEvents=Jl,h.getAllActionDescriptorsForLoops=Sl,h.getAllActionDescriptorsForOperations=yS,h.getAllBuiltInEntityIds=Ui,h.getAllGloballyDeclaredFunctionDeclarationsExplanation=z1,h.getBaseBuiltInEntities=qt,h.getBaseSchemaBasedOnType=F1,h.getBuiltInEntityOwner=an,h.getCallableEntityReferenceSchema=Ct,h.getCallableEntityTypeSchema=BD,h.getCalledBy=Ii,h.getCallerEntityReferenceSchema=JZ,h.getCallerEntityTypeSchema=qZ,h.getCalls=Yc,h.getCanvasEntitiesDerivedFromInternalCalls=KP,h.getCanvasEntitiesDerivedFromWrites=Cs,h.getCanvasEntityDerivedFromValueReadingEntity=ed,h.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=HP,h.getCanvasEntityReferenceSchema=l7,h.getCanvasEntityTypeSchema=o7,h.getChildrenEntityWithValues=DS,h.getColumnProperties=SS,h.getCommonAncestor=zc,h.getCommonChildren=aP,h.getDatabaseEntities=qS,h.getDatabaseEntity=WS,h.getDeclaration=Un,h.getDeepestScope=ow,h.getDraggableCallableEntityReferenceSchema=MD,h.getDraggableCallableEntityTypeSchema=_D,h.getDraggableCallerEntityReferenceSchema=WZ,h.getDraggableCallerEntityTypeSchema=SZ,h.getDraggableExecutableEntityReferenceSchema=KZ,h.getDraggableExecutableEntityTypeSchema=HZ,h.getDraggablePassThroughCallableEntityReferenceSchema=Pl,h.getDraggablePassThroughCallableEntityTypeSchema=Ol,h.getDraggablePlayableEntityReferenceSchema=i7,h.getDraggablePlayableEntityTypeSchema=t7,h.getEntitiesCreatedSinceInitialization=ld,h.getEntityArgumentDeclarations=Kc,h.getEntityInputMaps=zP,h.getEntityOutputMaps=jS,h.getEntityReferenceSchema=a7,h.getEntityReturnDeclarations=YP,h.getEntityTypeSchema=s7,h.getEntityWithLogicScopeReferenceSchema=mr,h.getEntityWithLogicScopeTypeSchema=XZ,h.getEntityWithValueReferenceSchema=VD,h.getEntityWithValueTypeSchema=ZZ,h.getEntryPointEntityReferenceSchema=Ot,h.getEntryPointEntityTypeSchema=Ur,h.getEventEntityReferenceSchema=Rl,h.getEventEntityTypeSchema=bl,h.getExecutableEntityReferenceSchema=YZ,h.getExecutableEntityTypeSchema=zZ,h.getExtendedBuiltInEntity=US,h.getExtendedDefinitionEntity=tw,h.getFirstNonLoopScopeOwner=It,h.getGenerationTargetSchemaBasedOnType=x1,h.getHeadIfPartOfDetachedBranch=rw,h.getHighestScope=aw,h.getImplementedBuiltInEntity=$S,h.getIsInteractive=Ua,h.getLastInListOperation=Dd,h.getLastInListOperationError=Dh,h.getLastInListOperationErrorParentRef=Rh,h.getLastInListOperationInputListArgument=Ih,h.getLastInListOperationInputListArgumentParentRef=Eh,h.getLastInListOperationInputListArgumentRef=hh,h.getLastInListOperationInputListDataType=mh,h.getLastInListOperationOutputElementDataType=Th,h.getLastInListOperationOutputElementReturn=bh,h.getLastInListOperationOutputElementReturnParentRef=Ah,h.getLastInListOperationOutputElementReturnRef=vh,h.getLinkedEntitiesFromArgumentDeclaration=VS,h.getLowestPersistedEntityImplementation=ew,h.getParentCallableEntity=oP,h.getParentCallerEntity=dP,h.getParentCanvasEntities=ti,h.getParentCanvasEntity=Vt,h.getParentCanvasEntityFromTransfer=Kl,h.getParentEntryPoint=RS,h.getParentPassthroughCallableEntity=lP,h.getPassThroughCallableEntityReferenceSchema=rt,h.getPassThroughCallableEntityTypeSchema=Dl,h.getPeristedEntities=ZS,h.getPlayableEntityReferenceSchema=e7,h.getPlayableEntityTypeSchema=QZ,h.getProject=kW,h.getPrototypeByType=$a,h.getRecusriveParentsIds=nd,h.getReferenceEntityId=_,h.getReferencedEntitiesStateOrErrors=kl,h.getReferencedEntityStateOrErrors=jc,h.getReferencedIds=Ql,h.getRelatedCanvasElementsOnTheLeft=$n,h.getRelatedCanvasElementsOnTheLeftFromTransfer=MS,h.getRelatedCanvasElementsOnTheRight=sn,h.getRootEntryPointScopeOwner=nf,h.getScopeOwner=Jt,h.getStateClassFromType=zS,h.getTerminationReferenceSchema=n7,h.getTerminationTypeSchema=r7,h.getTouchedCanvasEntitiesFromChangeSet=HS,h.getUsedArgFromDeclaration=NS,h.getUsedReturnFromDeclaration=LS,h.getValueReadingEntityReferenceSchema=CD,h.getValueReadingEntityTypeSchema=hr,h.getValueWritingEntityReferenceSchema=kZ,h.getValueWritingEntityTypeSchema=Ia,h.getVariableFromInputMapping=pP,h.getVariableFromReturnVariablePointer=yP,h.getVariableReferenceSchema=jr,h.getVariableTypeSchema=Bn,h.getVariablesFromArgumentDeclarations=Xl,h.getVariablesFromInputMaps=cP,h.getVariablesFromOutputMapping=hP,h.getVariablesFromOutputMaps=mP,h.getVariablesFromReturnDeclarations=fP,h.getVariablesInSameOrHigherScope=Ic,h.getWrites=Hc,h.globalEventValidation=gJ,h.groupCallsBasedOnParallelizableExecution=PS,h.handleAfterEntityImplementationSideEffects=tP,h.handleBeforeEntityImplementationSideEffects=eP,h.httpRequestBodyArgument=io,h.httpRequestBodyArgumentRef=a0,h.httpRequestBodyDataType=o0,h.httpRequestHeadersArgument=to,h.httpRequestHeadersArgumentRef=n0,h.httpRequestHeadersDataType=s0,h.httpRequestMethodArgument=Qa,h.httpRequestMethodArgumentRef=i0,h.httpRequestMethodDataType=r0,h.httpRequestMethodDataTypeRef=e0,h.httpRequestOperation=Ms,h.httpRequestOperationErrorValueDescriptor=Md,h.httpRequestOperationErrorValueDescriptorDatatype=P0,h.httpRequestOperationErrorValueDescriptorRef=O0,h.httpRequestOperationRef=A0,h.httpRequestOperationRefEight=R0,h.httpRequestOperationRefFive=E0,h.httpRequestOperationRefFour=T0,h.httpRequestOperationRefNine=D0,h.httpRequestOperationRefSeven=b0,h.httpRequestOperationRefSix=I0,h.httpRequestOperationRefThree=v0,h.httpRequestOperationRefTwo=m0,h.httpRequestQueryParamsArgument=_d,h.httpRequestQueryParamsArgumentRef=Xm,h.httpRequestQueryParamsDataType=Qm,h.httpRequestVariableURLArgument=eo,h.httpRequestVariableURLArgumentRef=Hm,h.httpRequestVariableURLDataType=Km,h.httpRequestVariableURLDataTypeRef=zm,h.httpResponseBodyReturnDataType=h0,h.httpResponseBodyReturnDataTypeRef=f0,h.httpResponseBodyReturnReturn=so,h.httpResponseBodyReturnReturnRef=y0,h.httpResponseCodeDataType=d0,h.httpResponseCodeReturn=ro,h.httpResponseCodeReturnRef=l0,h.httpResponseHeadersDataType=c0,h.httpResponseHeadersDataTypeRef=u0,h.httpResponseHeadersReturn=no,h.httpResponseHeadersReturnRef=p0,h.httpStatusCodeValueValidation=Ew,h.implement=Yl,h.inferArgumentDeclarationDataType=qO,h.inferDataType=ji,h.inferInputMapDataType=vc,h.inferOutputMapDataType=Ec,h.inferPropertyDataType=WO,h.inferReturnDeclarationDataType=Tc,h.inferValueDescriptorDataType=zO,h.inferVariableDeclarationDataType=SO,h.inferVariableInstanceDataType=JO,h.initBaseProjectEntity=od,h.initProject=bw,h.initProjectFromFetchResult=Aw,h.inputMapValidation=YJ,h.installedProjectValidation=WJ,h.internalCallValidation=zJ,h.isPromise=qc,h.iterateOverListActionDescriptorListArgumentDeclaration=av,h.iterateOverListActionDescriptorListArgumentDeclarationDataType=nv,h.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=rv,h.iterateOverListActionDescriptorListArgumentDeclarationParentRef=sv,h.iterateOverListLoopActionDescriptor=Or,h.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=lv,h.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=ov,h.iterateOverListLoopBodyActionDescriptor=js,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=vv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=mv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Ev,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=Tv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=uo,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=uv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=dv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=pv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=hv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=fv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=cv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=yv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Dv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=bv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Av,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=Rv,h.iterateOverObjectKeysLoopActionDescriptor=Sn,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Pv,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=Ov,h.iterateOverObjectKeysLoopBodyActionDescriptor=$d,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=jv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Lv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=$v,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Uv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ud,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Cv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=wv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Vv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Nv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=_v,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Bv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Mv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=kv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Fv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Gv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=xv,h.iterateOverObjectValuesLoopActionDescriptor=Wn,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=qv,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Zv,h.iterateOverObjectValuesLoopBodyActionDescriptor=Gd,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Qv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Xv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=tT,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=eT,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=gd,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Sv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Jv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Wv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Kv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Yv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=zv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Hv,h.iterateOverStringActionDescriptorDynamicReturnDeclaration=J0,h.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=q0,h.iterateOverStringActionDescriptorStringArgumentDeclaration=Z0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=x0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=F0,h.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=k0,h.iterateOverStringLoopActionDescriptor=Ls,h.iterateOverStringLoopBodyActionDescriptor=lo,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=Q0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=X0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=tv,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=ev,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ld,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=W0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=S0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=z0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jd,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=H0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Y0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=K0,h.joinListOperation=Ad,h.joinListOperationError=zy,h.joinListOperationErrorParentRef=Wy,h.joinListOperationFirstListArgument=ky,h.joinListOperationFirstListArgumentParentRef=xy,h.joinListOperationFirstListArgumentRef=jy,h.joinListOperationFirstListDataType=Uy,h.joinListOperationResultListDataType=Fy,h.joinListOperationResultListReturn=Sy,h.joinListOperationResultListReturnParentRef=Jy,h.joinListOperationResultListReturnRef=Gy,h.joinListOperationSecondListArgument=qy,h.joinListOperationSecondListArgumentParentRef=Zy,h.joinListOperationSecondListArgumentRef=$y,h.joinListOperationSecondListDataType=gy,h.joinListWithLastSeparator=se,h.joinStringsOperation=_s,h.joinStringsOperationDynamicStringArgument=yy,h.joinStringsOperationDynamicStringArgumentParentRef=fy,h.joinStringsOperationDynamicStringArgumentRef=py,h.joinStringsOperationDynamicStringDataType=cy,h.joinStringsOperationError=uy,h.joinStringsOperationErrorParentRef=dy,h.joinStringsOperationFirstStringArgument=Ha,h.joinStringsOperationFirstStringArgumentParentRef=ey,h.joinStringsOperationFirstStringArgumentRef=zf,h.joinStringsOperationFirstStringDataType=Yf,h.joinStringsOperationResultStringDataType=Qf,h.joinStringsOperationResultStringReturn=Bs,h.joinStringsOperationResultStringReturnParentRef=ly,h.joinStringsOperationResultStringReturnRef=Xf,h.joinStringsOperationSecondStringArgument=Ka,h.joinStringsOperationSecondStringArgumentParentRef=oy,h.joinStringsOperationSecondStringArgumentRef=Hf,h.joinStringsOperationSecondStringDataType=Kf,h.joinStringsOperationSeparatorStringArgument=ay,h.joinStringsOperationSeparatorStringArgumentParentRef=sy,h.joinStringsOperationSeparatorStringArgumentRef=ty,h.joinStringsOperationSeparatorStringDataType=ny,h.joinStringsOperationSeparatorStringDataTypeDefaultValue=ry,h.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=iy,h.keyValuePrototype=Zn,h.literalValudValidation=iS,h.loopValidation=xJ,h.lowercaseFirstLetter=Ll,h.manualFlowActionDescriptorDeclarationArgumentDeclaration=Nd,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=N0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=M0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=L0,h.manualFlowLoopActionDescriptor=ao,h.manualFlowLoopActionDescriptorDynamicReturnDeclaration=_0,h.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=B0,h.manualFlowLoopBodyActionDescriptor=oo,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=U0,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=j0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=g0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=$0,h.mapActionDescriptorToTypeItRepresents=xS,h.mergeEntityErrorsList=k3,h.mergeListOfEntities=GS,h.methodDefaultValue=t0,h.mockClientProject=up,h.moreThanOrEqualCondition=Xn,h.moreThanOrEqualConditionLeftHandArgument=KE,h.moreThanOrEqualConditionLeftHandArgumentDataType=YE,h.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=zE,h.moreThanOrEqualConditionLeftHandArgumentParentRef=HE,h.moreThanOrEqualConditionRightHandArgument=tI,h.moreThanOrEqualConditionRightHandArgumentDataType=QE,h.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=XE,h.moreThanOrEqualConditionRightHandArgumentParentRef=eI,h.noSpacesOrDashesValueValidation=sP,h.noSpacesValueValidation=nP,h.notEmptyCondition=mn,h.notEmptyConditionArgument=SE,h.notEmptyConditionRef=JE,h.nullPrototype=fd,h.numberAdditionOperation=Ya,h.numberAdditionOperationDynamicSummandArgument=Bf,h.numberAdditionOperationDynamicSummandArgumentType=Vf,h.numberAdditionOperationDynamicSummandArgumentTypeParentRef=Cf,h.numberAdditionOperationError=wf,h.numberAdditionOperationErrorParentRef=Pf,h.numberAdditionOperationFirstNumberArgument=yd,h.numberAdditionOperationFirstNumberArgumentRef=Tf,h.numberAdditionOperationFirstNumberDataType=Ef,h.numberAdditionOperationRef=Df,h.numberAdditionOperationRefThree=md,h.numberAdditionOperationRefTwo=Of,h.numberAdditionOperationResultNumberDataType=Rf,h.numberAdditionOperationResultNumberReturn=vd,h.numberAdditionOperationResultNumberReturnRef=bf,h.numberAdditionOperationSecondNumberArgument=hd,h.numberAdditionOperationSecondNumberArgumentRef=If,h.numberAdditionOperationSecondNumberDataType=Af,h.numberPrototype=ve,h.numberSubtractionOperation=Ed,h.numberSubtractionOperationDynamicSubtrahendArgument=Sf,h.numberSubtractionOperationDynamicSubtrahendArgumentType=Jf,h.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=qf,h.numberSubtractionOperationError=Zf,h.numberSubtractionOperationErrorParentRef=kf,h.numberSubtractionOperationFirstNumberArgument=$f,h.numberSubtractionOperationFirstNumberArgumentRef=_f,h.numberSubtractionOperationFirstNumberDataType=Mf,h.numberSubtractionOperationRef=Td,h.numberSubtractionOperationRefThree=Ff,h.numberSubtractionOperationRefTwo=gf,h.numberSubtractionOperationResultNumberDataType=Uf,h.numberSubtractionOperationResultNumberReturn=xf,h.numberSubtractionOperationResultNumberReturnRef=jf,h.numberSubtractionOperationSecondNumberArgument=Gf,h.numberSubtractionOperationSecondNumberArgumentRef=Nf,h.numberSubtractionOperationSecondNumberDataType=Lf,h.numberValueAutogenerationSchema=yp,h.operationValidation=$J,h.outputMapValidation=XJ,h.parallelExecutionOperation=Vi,h.parallelExecutionOperationError=Qh,h.parallelExecutionOperationErrorParentRef=Xh,h.parallelExecutionOperationListOfExecutionResultsDataType=Yh,h.parallelExecutionOperationListOfExecutionResultsReturn=Cd,h.parallelExecutionOperationListOfExecutionResultsReturnRef=zh,h.parallelExecutionOperationListOfFunctionsArgument=wd,h.parallelExecutionOperationListOfFunctionsArgumentDatatype=Wh,h.parallelExecutionOperationListOfFunctionsArgumentRef=Sh,h.parallelExecutionOperationListOfFunctionsBlueprint=Jh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Zh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=kh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=xh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=Fh,h.parallelExecutionOperationListOfFunctionsBlueprintParentRef=qh,h.parallelExecutionOperationRef=Hh,h.parallelExecutionOperationRefThree=Kh,h.persistedBuiltInBaseEntity=_t,h.persistedBuiltInBaseEntityDatabaseProperty=Yn,h.persistedBuiltInBaseEntityDatabasePropertyDataType=PE,h.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=Nw,h.persistedBuiltInBaseEntityDatabasePropertyParentRef=wE,h.persistedBuiltInBaseEntityDatabasePropertyRef=OE,h.persistedBuiltInBaseEntityPrimaryKeyProperty=Hn,h.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=jE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=VE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=CE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=UE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=LE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=_E,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=BE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=NE,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=ME,h.processOutputGlobalValueDescriptorDataType=lI,h.processOutputGlobalValueDescriptorReturn=Eo,h.processOutputGlobalValueDescriptorReturnRef=oI,h.projectPublicationCompletedGlobalEvent=To,h.propertyToZodSchema=OI,h.propertyValidation=OJ,h.relationalDatabaseBuiltInBaseEntity=Dt,h.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Qd,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=AE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=IE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=bE,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=EE,h.relationalDatabaseBuiltInBaseEntityDefaultProperty=Xd,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=TE,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=mE,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=vE,h.relationalDatabaseBuiltInBaseEntityIdentifierProperty=co,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=oE,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=sE,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=aE,h.relationalDatabaseBuiltInBaseEntityMinSizeProperty=ho,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=hE,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=fE,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=yE,h.relationalDatabaseBuiltInBaseEntityPasswordProperty=yo,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=pE,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=Mw,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDefaultValueParentRef=cE,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=uE,h.relationalDatabaseBuiltInBaseEntityRef=zn,h.relationalDatabaseBuiltInBaseEntityUsernameProperty=fo,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=dE,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=_w,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=lE,h.resolveActionDescriptorName=e1,h.resolveBaseEntityName=HO,h.resolveBuiltInBaseEntityDataTypeLabel=KO,h.resolveClonedEntityProject=mt,h.resolveConditionOperatorLabel=gl,h.resolveDataType=jl,h.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Sc,h.resolveDataTypeLabel=$l,h.resolveDefinitionEntityDataTypeLabel=RJ,h.resolveEntityDataTypeLabel=bJ,h.resolveEntityName=x,h.resolveFirstCallsSecond=wS,h.resolveFirstWritesSecond=CS,h.resolvePrimaryKeyProperty=JS,h.resolvePrimitiveEntityName=QO,h.resolveSearchName=XO,h.resolveVariableScope=EJ,h.returnDeclarationValidation=CJ,h.returnStatementValidation=VJ,h.searchValidation=SJ,h.sequentialExecutionOperation=or,h.sequentialExecutionOperationError=Em,h.sequentialExecutionOperationErrorParentRef=Tm,h.sequentialExecutionOperationListOfExecutionResultsDataType=hm,h.sequentialExecutionOperationListOfExecutionResultsReturn=Bd,h.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=vm,h.sequentialExecutionOperationListOfExecutionResultsReturnRef=ym,h.sequentialExecutionOperationListOfFunctionsArgument=Vd,h.sequentialExecutionOperationListOfFunctionsArgumentDatatype=fm,h.sequentialExecutionOperationListOfFunctionsArgumentParentRef=mm,h.sequentialExecutionOperationListOfFunctionsArgumentRef=cm,h.sequentialExecutionOperationListOfFunctionsBlueprint=pm,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=um,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=dm,h.softDeletePersistedEntityMethod=Lw,h.softDeletePersistedEntityMethodParentRef=$E,h.sortCallsBasedOnExecutionDependencies=uP,h.sortChildrenEntitiesBasedOnExecutionDependencies=OS,h.splitListOperation=Rd,h.splitListOperationError=ch,h.splitListOperationErrorParentRef=ph,h.splitListOperationFirstOutputListDataType=th,h.splitListOperationFirstOutputListReturn=oh,h.splitListOperationFirstOutputListReturnParentRef=ah,h.splitListOperationFirstOutputListReturnRef=bd,h.splitListOperationInputListArgument=rh,h.splitListOperationInputListArgumentParentRef=ih,h.splitListOperationInputListArgumentRef=Ky,h.splitListOperationInputListDataType=Xy,h.splitListOperationSecondOutputListDataType=lh,h.splitListOperationSecondOutputListReturn=uh,h.splitListOperationSecondOutputListReturnParentRef=dh,h.splitListOperationSplitIndexArgument=sh,h.splitListOperationSplitIndexArgumentParentRef=nh,h.splitListOperationSplitIndexArgumentRef=Qy,h.splitListOperationSplitIndexDataType=eh,h.splitStringOperation=Id,h.splitStringOperationError=_y,h.splitStringOperationErrorParentRef=By,h.splitStringOperationFirstPartResultStringDataType=Iy,h.splitStringOperationFirstPartResultStringReturn=Vy,h.splitStringOperationFirstPartResultStringReturnParentRef=Cy,h.splitStringOperationFirstPartResultStringReturnRef=Ey,h.splitStringOperationIndexArgument=Py,h.splitStringOperationIndexArgumentParentRef=Oy,h.splitStringOperationIndexArgumentRef=vy,h.splitStringOperationIndexDataType=Ty,h.splitStringOperationSecondPartResultStringDataType=by,h.splitStringOperationSecondPartResultStringReturn=Vw,h.splitStringOperationSecondPartResultStringReturnParentRef=wy,h.splitStringOperationSecondPartResultStringReturnRef=Ay,h.splitStringOperationStringArgument=Dy,h.splitStringOperationStringArgumentParentRef=Ry,h.splitStringOperationStringArgumentRef=hy,h.splitStringOperationStringDataType=my,h.stringPrototype=ae,h.stringValueAutogenerationSchema=fp,h.suggestNewIdForEntity=wc,h.test_primitive_entities_export=MW,h.toCamelCase=IJ,h.toEntityState=Ai,h.toKebabCase=YO,h.toLowerCaseKebabCase=Ul,h.toPascalCase=AJ,h.untypedDataPrototype=wt,h.updateErrorsList=Ke,h.urlDefaultValue=Ym,h.uuidPrototype=sr,h.validateArgumentDeclarationName=Oc,h.validateCalledByErrorIdInAction=cS,h.validateCalledByIdInAction=pS,h.validateCallers=W1,h.validateConditionEntityDeclaration=hS,h.validateDataOperation=pn,h.validateDataOperationDataToValidateArgument=gm,h.validateDataOperationDataToValidateArgumentParentRef=$m,h.validateDataOperationDataToValidateArgumentRef=jm,h.validateDataOperationDataToValidateDataType=Um,h.validateDataOperationEntityToMatchTypeArgument=km,h.validateDataOperationEntityToMatchTypeArgumentParentRef=xm,h.validateDataOperationEntityToMatchTypeArgumentRef=Gm,h.validateDataOperationEntityToMatchTypeDataType=Fm,h.validateDataOperationError=Sm,h.validateDataOperationErrorParentRef=Jm,h.validateDataOperationOutputEntityDeclaration=qm,h.validateDataOperationOutputEntityDeclarationParentRef=Zm,h.validateDefinitionEntityName=Ac,h.validateEntryCaller=S1,h.validateErrorCaller=J1,h.validateFunctionCallDeclaration=Y1,h.validateFunctionDeclarationName=bc,h.validateGeneratedEntityParentIsNotBuiltInEntity=oS,h.validateGeneration=sS,h.validateGenerationTarget=pt,h.validateGenerationUpdate=aS,h.validateLoopEntityDeclaration=mS,h.validateName=DJ,h.validateOperationEntityDeclaration=H1,h.validatePropertyName=Dc,h.validateReachability=Ar,h.validateReadsValueInActionPayload=fS,h.validateReferenceObject=xl,h.validateReferenceToOne=Uc,h.validateReferences=bt,h.validateReturnDeclarationName=Pc,h.validateSuccessCaller=q1,h.validateValueReaderGenerationUpdate=_a,h.validateValueWritter=kc,h.validateVariableDeclarationName=Rc,h.validateVariableInternalCallUse=Zc,h.valueAutogenerationCurrentDateAndTimeSchema=oD,h.valueAutogenerationGenericSchema=ol,h.valueAutogenerationOptions=mp,h.valueAutogenerationOptionsSchema=aD,h.valueAutogenerationRandomBooleanSchema=cp,h.valueAutogenerationRandomDateBetweenSchema=mD,h.valueAutogenerationRandomDateFromSchema=yD,h.valueAutogenerationRandomDateSchema=ul,h.valueAutogenerationRandomDateUntilSchema=hD,h.valueAutogenerationRandomNumberBetweenSchema=uD,h.valueAutogenerationRandomNumberFromSchema=lD,h.valueAutogenerationRandomNumberSchema=ll,h.valueAutogenerationRandomNumberUntilSchema=dD,h.valueAutogenerationRandomSchema=fa,h.valueAutogenerationRandomTextBetweenSchema=fD,h.valueAutogenerationRandomTextFromSchema=pD,h.valueAutogenerationRandomTextSchema=dl,h.valueAutogenerationRandomTextUntilSchema=cD,h.valueAutogenerationRangeValueTypesSchema=ca,h.valueAutogenerationUniqueSchema=pp,h.valueDescriptorValidation=nS,h.variableDeclarationValidation=qJ,h.variableInstanceValidation=JJ,h.waitOperation=Wt,h.waitOperationMillisecondsNumberArgument=dn,h.waitOperationMillisecondsNumberArgumentRef=im,h.waitOperationMillisecondsNumberDataType=rm,h.waitOperationOperationError=am,h.waitOperationOperationErrorParentRef=sm,h.waitOperationRef=nm,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});