@elyx-code/project-logic-tree 0.0.6170 → 0.0.6172
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.cjs
CHANGED
|
@@ -40,9 +40,9 @@ Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInS
|
|
|
40
40
|
Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function pp(i,s){const e=[];i.name||e.push(new O({id:`${i.id}--${j.EmptyName}`,message:`Entity with id "${i.id}" and type "${i.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=g(i.parent);if(!t)e.push(new O({id:`${i.id}--parent-reference--${I.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${i.id}" and type "${i.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:I.InvalidReferenceObjectStructure,issue:null}));else{const r=s.get(t);if(!r)e.push(new O({id:`${i.id}--parent-reference--${I.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:I.ReferencedEntityNotFound,issue:null}));else{const d=Up(r).filter(o=>o.name===i.name);d.length&&e.push(new O({id:`${i.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${i.id}" and type "${i.type}" has a name "${i.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${d[0].id}" has the same name.
|
|
41
41
|
Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function fp(i,s){const e=[];i.name||e.push(new O({id:`${i.id}--${j.EmptyName}`,message:`Entity with id "${i.id}" and type "${i.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=g(i.parent);if(!t)e.push(new O({id:`${i.id}--parent-reference--${I.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${i.id}" and type "${i.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:I.InvalidReferenceObjectStructure,issue:null}));else{const r=s.get(t);if(!r)e.push(new O({id:`${i.id}--parent-reference--${I.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:I.ReferencedEntityNotFound,issue:null}));else{const d=dP(r).filter(o=>o.name===i.name);d.length&&e.push(new O({id:`${i.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${i.id}" and type "${i.type}" has a name "${i.name}" that is not unique among all outputs declared in the parent entity. Entity with id "${d[0].id}" has the same name.
|
|
42
42
|
Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function N7(i,s){switch(i.type){case n.DefinitionEntity:return gd(i,s);case n.FunctionDeclaration:return lp(i,s);case n.VariableDeclaration:return up(i,s);case n.Property:return cp(i,s);case n.ArgumentDeclaration:return pp(i,s);case n.ReturnDeclaration:return fp(i,s);default:return[]}}function S1(i,s,e){const r=`${wd(i)}-${s}-id`;return e.instances[r]?R.UUID.uuid():r}function yp(i,s){let e="",t=null;if(i.parent){const a=s.get(i.parent);a&&(t=a)}let r="";return t&&(r=`${wd(G(t,s))}-`),e=`${r}${wd(G(i,s))}-id`,s.instances[e]?R.UUID.uuid():e}function pt(i,s,e="uuid"){return e==="semantic"?S1(G(i,s),i.type,s):R.UUID.uuid()}function L7(i){var d;const s=i6(),e=i.toJSON();s.safeParse(e).success;const r=U7(i);(d=i.dataType)==null||d.validate();const a=[...r];if(i.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return a}function U7(i){const s=[];if(!i.implements)return s;const e=i.implements;if(!e.abstract){const r=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(e,i.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});s.push(r.error)}if(i.static&&!e.static){const r=ye({id:`${i.id}--${q.NonStaticPropertyImplementsStatic}`,message:`Static property "${G(i,i.project)}" with id "${i.id}" implements a non-static property "${G(e,i.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:q.NonStaticPropertyImplementsStatic,entity:i});s.push(r.error)}if(!i.static&&e.static){const r=ye({id:`${i.id}--${q.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${G(i,i.project)}" with id "${i.id}" implements a static property "${G(e,i.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:q.StaticPropertyImplementsNonStatic,entity:i});s.push(r.error)}if(!Ir(i.dataType,e.dataType)){const r=ye({id:`${i.id}--${q.PropertyImplementsIncompatibleType}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a property "${G(e,i.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:D.Error,code:q.PropertyImplementsIncompatibleType,entity:i});s.push(r.error)}return Ye(i.errors,s)}function j7(i,s){const e=[];if(i.parent){const r=s.get(i.parent);if(!r)e.push(new O({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const a=Yi(r);if(a){const d=r!==a?`The entity of type '${i.type}' with id '${i.id}' have 'parent' with id '${i.parent}' because the entity belongs to a built-in '${a.type}' entity with id '${a.id}' (${G(a,r.project)}) higher up in the tree.`:`The entity of type '${i.type}' with id '${i.id}' have 'parent' with id '${i.parent}' because it is a built-in entity of type ${a.type}.`;e.push(new O({id:`${i.id}--${I.InvalidBuiltInEntityReference}`,code:I.InvalidBuiltInEntityReference,severity:D.Error,message:d,issue:null}))}else if(![n.DefinitionEntity].includes(r.type))e.push(new O({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=Wi(r).filter(l=>!l.interactive);if(o.length){let l=o.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${r.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ie(o.map(c=>G(c,c.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${r.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${G(o[0],o[0].project)}").`;l+=`
|
|
43
|
-
${Zi}`,e.push(new O({id:`${i.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:D.Error,message:l,issue:null}))}else if(i.implements){const l=s.get(i.implements);if(i.id===i.implements)return e.push(new O({id:`${i.id}--${i.implements}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!l)e.push(new O({id:`${i.id}--${i.implements}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const c=r.properties.find(h=>{var p;return((p=h.implements)==null?void 0:p.id)===i.implements});c?e.push(new O({id:`${i.id}--${j.PropertyOverwrite}`,code:j.PropertyOverwrite,severity:D.Error,message:`The property with id "${i.id}" is trying to implement the property with id "${i.implements}", but the parent entity already has a property with id '${c.id}' that implements the same base property.`,issue:null})):[n.Property].includes(l.type)?l.abstract||e.push(new O({id:`${i.id}--${i.implements}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new O({id:`${i.id}--${i.implements}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=Et(i,{},s);return e.push(...t.errors),e}class rt{constructor(s){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=s.version,this.previousVersion=s.previousVersion,this.createdAt=T(s.createdAt).toISOString(),this.deleted=s.deleted,this.author=s.author}metaSync(s){this.deleted=s.deleted!==void 0?s.deleted:this.deleted}}var hp=(i=>(i.Manual="manual",i.Automatic="automatic",i))(hp||{}),b=(i=>(i.Added="added",i.Updated="updated",i.Removed="removed",i.Affected="affected",i))(b||{});class A{constructor(s,e,t,r,a=!1,d=""){f(this,"id",R.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=s,this.author=e,this.timestamp=t,this.self=r,this.autoclose=a,this.autoCloseActionName=d,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var s;return!(this.isEmpty&&this.self&&!this.affected[(s=this.self)==null?void 0:s.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const s=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=Wr(),r=e.filter(d=>!t.includes(d));s.filter(d=>!r.includes(d)).forEach(d=>{this.remove(d)})}attemptAutoclose(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}close(){return this.open=!1,!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.isEmpty?(
|
|
43
|
+
${Zi}`,e.push(new O({id:`${i.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:D.Error,message:l,issue:null}))}else if(i.implements){const l=s.get(i.implements);if(i.id===i.implements)return e.push(new O({id:`${i.id}--${i.implements}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!l)e.push(new O({id:`${i.id}--${i.implements}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const c=r.properties.find(h=>{var p;return((p=h.implements)==null?void 0:p.id)===i.implements});c?e.push(new O({id:`${i.id}--${j.PropertyOverwrite}`,code:j.PropertyOverwrite,severity:D.Error,message:`The property with id "${i.id}" is trying to implement the property with id "${i.implements}", but the parent entity already has a property with id '${c.id}' that implements the same base property.`,issue:null})):[n.Property].includes(l.type)?l.abstract||e.push(new O({id:`${i.id}--${i.implements}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new O({id:`${i.id}--${i.implements}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=Et(i,{},s);return e.push(...t.errors),e}class rt{constructor(s){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=s.version,this.previousVersion=s.previousVersion,this.createdAt=T(s.createdAt).toISOString(),this.deleted=s.deleted,this.author=s.author}metaSync(s){this.deleted=s.deleted!==void 0?s.deleted:this.deleted}}var hp=(i=>(i.Manual="manual",i.Automatic="automatic",i))(hp||{}),b=(i=>(i.Added="added",i.Updated="updated",i.Removed="removed",i.Affected="affected",i))(b||{});class A{constructor(s,e,t,r,a=!1,d=""){f(this,"id",R.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=s,this.author=e,this.timestamp=t,this.self=r,this.autoclose=a,this.autoCloseActionName=d,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var s;return!(this.isEmpty&&this.self&&!this.affected[(s=this.self)==null?void 0:s.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const s=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=Wr(),r=e.filter(d=>!t.includes(d));s.filter(d=>!r.includes(d)).forEach(d=>{this.remove(d)})}attemptAutoclose(s,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===s&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}close(){return this.open=!1,!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.isEmpty?(this.project.discardChangeSet(this),this):(this.discardOrphans(),this.project.closeChangeSet(this),this)}get(s){return this.added[s]?this.added[s]:this.updated[s]?this.updated[s]:this.removed[s]?this.removed[s]:null}remove(s){return this.has(s)&&(delete this.added[s],delete this.updated[s],delete this.removed[s],delete this.affected[s],this.seenEntities=this.seenEntities.filter(e=>e!==s)),this}add(s,e){if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),...Wr()]));if(t.includes(s.id))return this;if(!Kd(s,{...this.project.instances,...this.project.builtInInstances}).every(d=>!t.includes(d)))return this;if(this.seenEntities.indexOf(s.id)===-1&&this.seenEntities.push(s.id),e!=="affected"&&s.createdAt!==this.timestamp){s.increaseVersion(this.timestamp);const{added:d,updated:o,removed:l,affected:c}=s.recursiveCaptureUpstreamVersions(this.timestamp);for(const h of d)this.add(h,"added");for(const h of o)this.add(h,"updated");for(const h of l)this.add(h,"removed");for(const h of c)this.add(h,"affected")}if(e==="removed"){if(this.added[s.id])return delete this.added[s.id],this.seenEntities=this.seenEntities.filter(d=>d!==s.id),delete this.project.deletedInstances[s.id],this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],this.removed[s.id]=s}if(e==="added"){if(this.removed[s.id])return this;this.updated[s.id]&&delete this.updated[s.id],this.affected[s.id]&&delete this.affected[s.id],this.added[s.id]=s}if(e==="updated"){if(this.removed[s.id])return this;if(this.added[s.id])return this;this.affected[s.id]&&delete this.affected[s.id],this.updated[s.id]=s}if(e==="affected"){if(this.removed[s.id])return this;if(this.added[s.id])return this;if(this.updated[s.id])return this;this.affected[s.id]=s}return this}toJSON(){const s={},e={},t={},r=new Set;for(const a of Object.values(this.added))s[a.id]=a.toShallowJSON();for(const a of Object.values(this.updated))e[a.id]=a.toShallowJSON();for(const a of Object.values(this.removed))t[a.id]=a.toShallowJSON();for(const a of Object.values(this.affected))r.add(a.id);return{added:s,updated:e,removed:t,affected:Array.from(r),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(s){return!!this.added[s]||!!this.removed[s]||!!this.updated[s]||!!this.affected[s]}hasAdded(s){return!!this.added[s]}hasUpdated(s){return!!this.updated[s]}hasRemoved(s){return!!this.removed[s]}hasAffected(s){return!!this.affected[s]}}function $7(i){return new Set([...Object.keys(i.added),...Object.keys(i.updated),...Object.keys(i.removed),...Array.from(i.affected)])}var F1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(F1||{});const Ie=class Ie extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.implements){const c=g(e.implements);d=t.get(c)}const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:a.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:d,dataType:null,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=j7(r,t),o=cp(r,t);return a.push(...d,...o,...ot(r)),{errors:a,modifiedData:r}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);return!!e&&e.id!==this.id&&!e.abstract}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
44
44
|
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),(e.readsValue||e.writesValue)&&t.push(new O({id:`${this.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
|
|
45
|
-
${Ld}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ie(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ie(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=V(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?this.index:0),this.static=e.static!==void 0?e.static:this.static,this.hidden=e.hidden!==void 0?e.hidden:this.hidden,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ie.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ie.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ie.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ie.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ie.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ie.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),r.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),r.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:(()=>{var p;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((p=this.implements)==null?void 0:p.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((d=this.implements)==null?void 0:d.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=L7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,P;let d=ft(t,this);const o=r||R.UUID.uuid();let l=t||this.parent;const c={hidden:!1,id:o,version:R.UUID.uuid(),createdAt:this.createdAt,author:this.author,previousVersion:this.version,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:l},h=lt(c,d);a&&h.subscribe(),h.setParent(l,null),h.initChildren(e),e==null||e.add(h,b.Added);const p=((E=this.dataType)==null?void 0:E.clone(e,h,R.UUID.uuid(),a))||null;p&&h.setDataType(p);const v=(P=this.defaultValue)==null?void 0:P.clone(e,h,R.UUID.uuid(),a);return h.defaultValue=v||null,this.implements&&(h.implements=this.implements),h.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),h}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ie,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ie,"type",n.Property),f(Ie,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ie,"PARENT_TYPES",[...Ie.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ie,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ie,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ie,"BASE_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,...Ie.INMUTABLE_BASE_PROPERTIES]),f(Ie,"MUTABLE_META_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,"index"]),f(Ie,"INMUTABLE_META_PROPERTIES",[...Ie.INMUTABLE_BASE_PROPERTIES]),f(Ie,"META_PROPERTIES",[...Ie.MUTABLE_META_PROPERTIES,...Ie.INMUTABLE_META_PROPERTIES]),f(Ie,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ie,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ie,"UPSTREAM_PROPERTIES",[...Ie.MUTABLE_UPSTREAM_PROPERTIES,...Ie.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ie,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ie,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ie,"DOWNSTREAM_PROPERTIES",[...Ie.MUTABLE_DOWNSTREAM_PROPERTIES,...Ie.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ie,"PROPERTIES",[...Ie.META_PROPERTIES,...Ie.UPSTREAM_PROPERTIES,...Ie.DOWNSTREAM_PROPERTIES]);let gi=Ie;function G7(i){var a;const s=w6(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const d=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var x1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(x1||{});const be=class be extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.readsValue){const c=g(e.readsValue);d=t.get(c)}const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:a.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:d,dataType:null,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l,c;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=fp(r,t);if(r=d.modifiedData,r.parent){const h=t.get(g(r.parent));if(h&&[n.BreakStatement,n.ContinueStatement].includes(h.type)){const p=h,v=p.parent,E=[...v.breakStatements.filter(w=>w.id!==h.id),...v.continueStatements.filter(w=>w.id!==h.id)];if(p.outputs.length)a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${p.type}' with id '${p.id}'. This '${p.type}' already has return declarations.
|
|
45
|
+
${Ld}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ie(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ie(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=V(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?this.index:0),this.static=e.static!==void 0?e.static:this.static,this.hidden=e.hidden!==void 0?e.hidden:this.hidden,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ie.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ie.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ie.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ie.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ie.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ie.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),r.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),r.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:(()=>{var p;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((p=this.implements)==null?void 0:p.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...((d=this.implements)==null?void 0:d.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=L7(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,P;let d=ft(t,this);const o=r||R.UUID.uuid();let l=t||this.parent;const c={hidden:!1,id:o,version:R.UUID.uuid(),createdAt:this.createdAt,author:this.author,previousVersion:this.version,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:l},h=lt(c,d);a&&h.subscribe(),h.setParent(l,null),h.initChildren(e),e==null||e.add(h,b.Added);const p=((E=this.dataType)==null?void 0:E.clone(e,h,R.UUID.uuid(),a))||null;p&&h.setDataType(p);const v=(P=this.defaultValue)==null?void 0:P.clone(e,h,R.UUID.uuid(),a);return h.defaultValue=v||null,this.implements&&(h.implements=this.implements),h.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),h}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ie,"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,...r)=>null}),f(Ie,"type",n.Property),f(Ie,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ie,"PARENT_TYPES",[...Ie.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ie,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ie,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ie,"BASE_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,...Ie.INMUTABLE_BASE_PROPERTIES]),f(Ie,"MUTABLE_META_PROPERTIES",[...Ie.MUTABLE_BASE_PROPERTIES,"index"]),f(Ie,"INMUTABLE_META_PROPERTIES",[...Ie.INMUTABLE_BASE_PROPERTIES]),f(Ie,"META_PROPERTIES",[...Ie.MUTABLE_META_PROPERTIES,...Ie.INMUTABLE_META_PROPERTIES]),f(Ie,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ie,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ie,"UPSTREAM_PROPERTIES",[...Ie.MUTABLE_UPSTREAM_PROPERTIES,...Ie.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ie,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ie,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ie,"DOWNSTREAM_PROPERTIES",[...Ie.MUTABLE_DOWNSTREAM_PROPERTIES,...Ie.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ie,"PROPERTIES",[...Ie.META_PROPERTIES,...Ie.UPSTREAM_PROPERTIES,...Ie.DOWNSTREAM_PROPERTIES]);let gi=Ie;function G7(i){var a;const s=w6(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const d=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var x1=(i=>(i.Implements="implements",i.DataTypeEntity="data-type-entity",i))(x1||{});const be=class be extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.readsValue){const c=g(e.readsValue);d=t.get(c)}const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:a.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:d,dataType:null,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l,c;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=fp(r,t);if(r=d.modifiedData,r.parent){const h=t.get(g(r.parent));if(h&&[n.BreakStatement,n.ContinueStatement].includes(h.type)){const p=h,v=p.parent,E=[...v.breakStatements.filter(w=>w.id!==h.id),...v.continueStatements.filter(w=>w.id!==h.id)];if(p.outputs.length)a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${p.type}' with id '${p.id}'. This '${p.type}' already has return declarations.
|
|
46
46
|
${Rp}`,issue:null}));else{const w=(c=(l=E[0])==null?void 0:l.outputs[0])==null?void 0:c.name;w!==r.name&&a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' cannot be added to the parent entity of type '${p.type}' with id '${p.id}'. This new 'return-declaration' doesn't have the same name "${w}" as the return declarations on the other statements in the same scope.
|
|
47
47
|
${Rp}`,issue:null}))}}else if(h&&h.type===n.ReturnStatement){const p=h.parent;if(p&&at.includes(p.type)){const v=p.implements;if(v){const E=v.outputs.find(B=>B.name===r.name),P=v.outputs.filter(B=>!h.outputs.find(k=>k.type===n.ReturnDeclaration&&k.name===B.name)),w=h.outputs.filter(B=>B.type===n.ReturnDeclaration),C=w.find(B=>B.name===r.name),U=w.length?`The parent entity already implements the following return declarations: ${ie(w.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",S=P.length?`The parent entity is still missing the following returns in the implementation: ${ie(P.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";E?C&&a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${h.type}' with id '${h.id}' that implements a ${n.ActionDescriptor} with fixed outputs.
|
|
48
48
|
Adding a new return would make the implementation invalid. An return with the same name already exists in the parent entity.
|
|
@@ -51,13 +51,13 @@ ${S}`,issue:null})):a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSigna
|
|
|
51
51
|
Adding a new return would make the implementation invalid. There are no returns in the descriptor with the same name.
|
|
52
52
|
${U}
|
|
53
53
|
${S}`,issue:null}))}}}}return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),r.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
54
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}propagateChanges(){const e=[this],t=[],r=[],a=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.parent.parent,{updated:o,added:l,removed:c}=d.syncChildren();e.push(...o),t.push(...l),r.push(...c)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return yi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,this.isError=e.isError||this.isError,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await be.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...((d=this.dataType)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatIds(e))||[],...((d=this.dataType)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:((p=this.implements)==null?void 0:p.toJSONClone({...e,newId:null}))||null,readsValue:((v=this.readsValue)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatJSON(e))||[],...((d=this.dataType)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.dataType)==null?void 0:d.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=G7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var v,E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.dataType=null,o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(v=this.dataType)==null?void 0:v.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(E=this.defaultValue)==null?void 0:E.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=p||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type"))){const t=sp(this,e);if(t&&t.parent===this){if(this.dataType){const r=this.dataType.merge(t,e);r.self!==this.dataType&&this.setDataType(r.self)}}else if(t&&t.parent!==this){const r=t.clone(e,this);if(r&&this.dataType){const a=this.dataType.merge(r,e);a.self!==this.dataType?this.setDataType(a.self):e==null||e.add(r,b.Added)}else r&&(e==null||e.add(r,b.Added),r.inferred=!0,this.setDataType(r))}return this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(d=>d.outputs).filter(d=>G(d,this.project)===G(this,this.project)&&d.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const r=this.parent.parent.returnStatements.flatMap(a=>a.outputs);this.implements?e=r.filter(d=>{var o;return this.implements.id===((o=d.implements)==null?void 0:o.id)}):e=r.filter(d=>G(d,this.project)===G(this,this.project)&&d.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var a,d;const t=this.getCounterparts(),r=t.find(o=>{var l;return(l=o.dataType)==null?void 0:l.isResolved});if(r)this.setDataType(r.dataType),e==null||e.add(this,b.Updated);else for(let o=0;o<t.length;o++){const l=t[o];if((!l.dataType||!l.dataType.isResolved||(a=l.dataType)!=null&&a.inferred)&&l.readsValue&&l.inferDataType(e),(d=l.dataType)!=null&&d.isResolved){this.setDataType(l.dataType),e==null||e.add(this,b.Updated);break}}return this}getDataType(e=this.project.addChangeSet(new A(this.project,"",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)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>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 rr=be;function S7(i){var a;const s=A6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}function F7(i){var a;const s=E6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var mp=(i=>(i.Parent="parent",i))(mp||{});const Ge=class Ge extends rt{constructor(e,t){super(e);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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),o=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),l=e.calledByError.map(p=>{const v=g(p);return t.get(v)}),c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},h=V(c,t);return h.setParent(a,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
54
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}propagateChanges(){const e=[this],t=[],r=[],a=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.parent.parent,{updated:o,added:l,removed:c}=d.syncChildren();e.push(...o),t.push(...l),r.push(...c)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return yi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,this.isError=e.isError||this.isError,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...((d=this.dataType)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatIds(e))||[],...((d=this.dataType)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:((p=this.implements)==null?void 0:p.toJSONClone({...e,newId:null}))||null,readsValue:((v=this.readsValue)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,readsValue:((d=this.readsValue)==null?void 0:d.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatJSON(e))||[],...((d=this.dataType)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.readsValue)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.dataType)==null?void 0:d.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=G7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var v,E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.dataType=null,o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(v=this.dataType)==null?void 0:v.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(E=this.defaultValue)==null?void 0:E.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=p||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type"))){const t=sp(this,e);if(t&&t.parent===this){if(this.dataType){const r=this.dataType.merge(t,e);r.self!==this.dataType&&this.setDataType(r.self)}}else if(t&&t.parent!==this){const r=t.clone(e,this);if(r&&this.dataType){const a=this.dataType.merge(r,e);a.self!==this.dataType?this.setDataType(a.self):e==null||e.add(r,b.Added)}else r&&(e==null||e.add(r,b.Added),r.inferred=!0,this.setDataType(r))}return this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(d=>d.outputs).filter(d=>G(d,this.project)===G(this,this.project)&&d.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const r=this.parent.parent.returnStatements.flatMap(a=>a.outputs);this.implements?e=r.filter(d=>{var o;return this.implements.id===((o=d.implements)==null?void 0:o.id)}):e=r.filter(d=>G(d,this.project)===G(this,this.project)&&d.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var a,d;const t=this.getCounterparts(),r=t.find(o=>{var l;return(l=o.dataType)==null?void 0:l.isResolved});if(r)this.setDataType(r.dataType),e==null||e.add(this,b.Updated);else for(let o=0;o<t.length;o++){const l=t[o];if((!l.dataType||!l.dataType.isResolved||(a=l.dataType)!=null&&a.inferred)&&l.readsValue&&l.inferDataType(e),(d=l.dataType)!=null&&d.isResolved){this.setDataType(l.dataType),e==null||e.add(this,b.Updated);break}}return this}getDataType(e=this.project.addChangeSet(new A(this.project,"",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,...r)=>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 rr=be;function S7(i){var a;const s=A6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}function F7(i){var a;const s=E6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var mp=(i=>(i.Parent="parent",i))(mp||{});const Ge=class Ge extends rt{constructor(e,t){super(e);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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),o=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),l=e.calledByError.map(p=>{const v=g(p);return t.get(v)}),c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},h=V(c,t);return h.setParent(a,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ge.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),throws:((c=this.throws)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.calledBy.flatMap(a=>a.toFlatJSON(e)),...((r=this.throws)==null?void 0:r.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=F7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.outputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.outputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-return-declaration-"+w+"-id",a));return p.outputs=v,this.throws&&(p.throws=this.throws.clone(e,p,h+"-throws-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(Ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ge,"type",n.ContinueStatement),f(Ge,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Ge,"PARENT_TYPES",[...Ge.USER_MANAGED_PARENT_TYPES]),f(Ge,"MUTABLE_BASE_PROPERTIES",[]),f(Ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ge,"BASE_PROPERTIES",[...Ge.MUTABLE_BASE_PROPERTIES,...Ge.INMUTABLE_BASE_PROPERTIES]),f(Ge,"MUTABLE_META_PROPERTIES",["x","y"]),f(Ge,"INMUTABLE_META_PROPERTIES",[...Ge.INMUTABLE_BASE_PROPERTIES]),f(Ge,"META_PROPERTIES",[...Ge.MUTABLE_META_PROPERTIES,...Ge.INMUTABLE_META_PROPERTIES]),f(Ge,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Ge,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Ge,"UPSTREAM_PROPERTIES",[...Ge.MUTABLE_UPSTREAM_PROPERTIES,...Ge.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ge,"DOWNSTREAM_PROPERTIES",[...Ge.MUTABLE_DOWNSTREAM_PROPERTIES,...Ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ge,"PROPERTIES",[...Ge.META_PROPERTIES,...Ge.UPSTREAM_PROPERTIES,...Ge.DOWNSTREAM_PROPERTIES]);let $t=Ge;var Bd=(i=>(i.Parent="parent",i))(Bd||{});const tt=class tt extends rt{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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),o=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),l=e.calledByError.map(p=>{const v=g(p);return t.get(v)}),c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},h=V(c,t);return h.setParent(a,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:mt}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ge.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),throws:((c=this.throws)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.calledBy.flatMap(a=>a.toFlatJSON(e)),...((r=this.throws)==null?void 0:r.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=F7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.outputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.outputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-return-declaration-"+w+"-id",a));return p.outputs=v,this.throws&&(p.throws=this.throws.clone(e,p,h+"-throws-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(Ge,"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,...r)=>null}),f(Ge,"type",n.ContinueStatement),f(Ge,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Ge,"PARENT_TYPES",[...Ge.USER_MANAGED_PARENT_TYPES]),f(Ge,"MUTABLE_BASE_PROPERTIES",[]),f(Ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ge,"BASE_PROPERTIES",[...Ge.MUTABLE_BASE_PROPERTIES,...Ge.INMUTABLE_BASE_PROPERTIES]),f(Ge,"MUTABLE_META_PROPERTIES",["x","y"]),f(Ge,"INMUTABLE_META_PROPERTIES",[...Ge.INMUTABLE_BASE_PROPERTIES]),f(Ge,"META_PROPERTIES",[...Ge.MUTABLE_META_PROPERTIES,...Ge.INMUTABLE_META_PROPERTIES]),f(Ge,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Ge,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Ge,"UPSTREAM_PROPERTIES",[...Ge.MUTABLE_UPSTREAM_PROPERTIES,...Ge.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ge,"DOWNSTREAM_PROPERTIES",[...Ge.MUTABLE_DOWNSTREAM_PROPERTIES,...Ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ge,"PROPERTIES",[...Ge.META_PROPERTIES,...Ge.UPSTREAM_PROPERTIES,...Ge.DOWNSTREAM_PROPERTIES]);let $t=Ge;var Bd=(i=>(i.Parent="parent",i))(Bd||{});const tt=class tt extends rt{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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),o=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),l=e.calledByError.map(p=>{const v=g(p);return t.get(v)}),c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},h=V(c,t);return h.setParent(a,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:mt}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new tt(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new tt(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await tt.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await tt.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await tt.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await tt.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await tt.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await tt.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((h=this.throws)==null?void 0:h.toJSONClone({...e,newId:null}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=S7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.outputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.outputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-return-declaration-"+w+"-id",a));return p.outputs=v,this.throws&&(p.throws=this.throws.clone(e,p,h+"-throws-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(tt,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(tt,"type",n.ReturnStatement),f(tt,"USER_MANAGED_PARENT_TYPES",[...mt]),f(tt,"PARENT_TYPES",[...tt.USER_MANAGED_PARENT_TYPES]),f(tt,"MUTABLE_BASE_PROPERTIES",[]),f(tt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(tt,"BASE_PROPERTIES",[...$t.MUTABLE_BASE_PROPERTIES,...$t.INMUTABLE_BASE_PROPERTIES]),f(tt,"MUTABLE_META_PROPERTIES",["x","y"]),f(tt,"INMUTABLE_META_PROPERTIES",[...$t.INMUTABLE_BASE_PROPERTIES]),f(tt,"META_PROPERTIES",[...$t.MUTABLE_META_PROPERTIES,...$t.INMUTABLE_META_PROPERTIES]),f(tt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(tt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(tt,"UPSTREAM_PROPERTIES",[...$t.MUTABLE_UPSTREAM_PROPERTIES,...$t.INMUTABLE_UPSTREAM_PROPERTIES]),f(tt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(tt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(tt,"DOWNSTREAM_PROPERTIES",[...$t.MUTABLE_DOWNSTREAM_PROPERTIES,...$t.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(tt,"PROPERTIES",[...rr.META_PROPERTIES,...rr.UPSTREAM_PROPERTIES,...rr.DOWNSTREAM_PROPERTIES]);let Bi=tt;function x7(i){const s=E5(),e=i.toJSON();s.safeParse(e).success;const r=k7(i),a=Z7(i),d=ir(i);i.inputs.forEach(l=>l.validate()),d.forEach(l=>l.validate());const o=[...r,...a];if(i.id==="getCompanyByIdEndpointReachedEntityEvent"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});o.push(l.error)}return Ye(i.errors,o)}function k7(i){const s=[];if(!i.calls.length){const e=ye({id:`${i.id}--${q.ScopeWithoutLogic}`,message:`Action "${G(i,i.project)}" with id "${i.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:D.Warning,code:q.ScopeWithoutLogic,entity:i});s.push(e.error)}return Ye(i.errors,s)}function Z7(i){const s=[];return i.implements,Ye(i.errors,s)}var k1=(i=>(i.Implements="implements",i))(k1||{});const Re=class Re extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a=null;if(e.implements){const l=g(e.implements);a=t.get(l)}const d={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:r.type===n.DefinitionEntity?r.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=V(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var p;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);r=d.modifiedData;const o=lp(r,t),l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DefinitionEntity){const v=l,P=Wi(v).filter(w=>!w.interactive);if(P.length){let w=P.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ie(P.map(C=>G(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${G(P[0],P[0].project)}").`;w+=`
|
|
60
|
+
Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new tt(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new tt(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await tt.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await tt.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await tt.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await tt.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await tt.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await tt.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),outputs:this.outputs.map(a=>a.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((h=this.throws)==null?void 0:h.toJSONClone({...e,newId:null}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=S7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.outputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.outputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-return-declaration-"+w+"-id",a));return p.outputs=v,this.throws&&(p.throws=this.throws.clone(e,p,h+"-throws-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(tt,"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,...r)=>null}),f(tt,"type",n.ReturnStatement),f(tt,"USER_MANAGED_PARENT_TYPES",[...mt]),f(tt,"PARENT_TYPES",[...tt.USER_MANAGED_PARENT_TYPES]),f(tt,"MUTABLE_BASE_PROPERTIES",[]),f(tt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(tt,"BASE_PROPERTIES",[...$t.MUTABLE_BASE_PROPERTIES,...$t.INMUTABLE_BASE_PROPERTIES]),f(tt,"MUTABLE_META_PROPERTIES",["x","y"]),f(tt,"INMUTABLE_META_PROPERTIES",[...$t.INMUTABLE_BASE_PROPERTIES]),f(tt,"META_PROPERTIES",[...$t.MUTABLE_META_PROPERTIES,...$t.INMUTABLE_META_PROPERTIES]),f(tt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(tt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(tt,"UPSTREAM_PROPERTIES",[...$t.MUTABLE_UPSTREAM_PROPERTIES,...$t.INMUTABLE_UPSTREAM_PROPERTIES]),f(tt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(tt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(tt,"DOWNSTREAM_PROPERTIES",[...$t.MUTABLE_DOWNSTREAM_PROPERTIES,...$t.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(tt,"PROPERTIES",[...rr.META_PROPERTIES,...rr.UPSTREAM_PROPERTIES,...rr.DOWNSTREAM_PROPERTIES]);let Bi=tt;function x7(i){const s=E5(),e=i.toJSON();s.safeParse(e).success;const r=k7(i),a=Z7(i),d=ir(i);i.inputs.forEach(l=>l.validate()),d.forEach(l=>l.validate());const o=[...r,...a];if(i.id==="getCompanyByIdEndpointReachedEntityEvent"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});o.push(l.error)}return Ye(i.errors,o)}function k7(i){const s=[];if(!i.calls.length){const e=ye({id:`${i.id}--${q.ScopeWithoutLogic}`,message:`Action "${G(i,i.project)}" with id "${i.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:D.Warning,code:q.ScopeWithoutLogic,entity:i});s.push(e.error)}return Ye(i.errors,s)}function Z7(i){const s=[];return i.implements,Ye(i.errors,s)}var k1=(i=>(i.Implements="implements",i))(k1||{});const Re=class Re extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a=null;if(e.implements){const l=g(e.implements);a=t.get(l)}const d={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:r.type===n.DefinitionEntity?r.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=V(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var p;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);r=d.modifiedData;const o=lp(r,t),l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DefinitionEntity){const v=l,P=Wi(v).filter(w=>!w.interactive);if(P.length){let w=P.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ie(P.map(C=>G(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${G(P[0],P[0].project)}").`;w+=`
|
|
61
61
|
${Zi}`,a.push(new O({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:D.Error,message:w,issue:null}))}else{const w=v.methods.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===r.implements});w&&a.push(new O({id:`${r.id}--${j.MethodOverwrite}`,code:j.MethodOverwrite,severity:D.Error,message:`The '${n.FunctionDeclaration}' with id "${r.id}" is trying to implement the '${n.ActionDescriptor}' with id "${r.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${w.id}' that implements the same base method.
|
|
62
62
|
A ${n.FunctionDeclaration} that has a parent of type '${n.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${n.ActionDescriptor}' more than once.
|
|
63
63
|
${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
|
|
@@ -67,48 +67,48 @@ If you want to implement a new method, you can create a new 'function-declaratio
|
|
|
67
67
|
If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${n.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null}))}}else if(l&&l.type===n.Loop){const v=l.body;v&&((p=v.implements)==null?void 0:p.id)===r.implements&&a.push(new O({id:`${r.id}--${j.MethodOverwrite}`,code:j.MethodOverwrite,severity:D.Error,message:`The '${n.FunctionDeclaration}' with id "${r.id}" is being added as the 'body' of the ${n.Loop} with id "${l.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`,issue:null}))}const c=r.parent&&t.get(r.parent)||t.getBuiltIn(r.parent),h=c?Yi(c):null;return h&&a.push(new O({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${G(h,t)}" with id '${h.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Bd.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&(this.parent.type===n.Project?t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
68
68
|
This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`,issue:null})):t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
69
69
|
This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.
|
|
70
|
-
Please consider that any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.setImplements(null,r),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(e)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'parent' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else if(d)throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.indexOf(e);return t!==-1&&this.inputs.splice(t,1),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=V(t,this.project);return r.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.initialData.implements&&(this.implements=V(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.private=e.private||this.private,this.index=e.index||(e.index!==0?this.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Re.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Re.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),ir(this).forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),ir(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ir(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(r=>r.toJSON(e)),inputs:this.inputs.map(r=>r.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(d=>d.toReference(e)),calls:this.calls.map(d=>d.toReference(e)),implements:((a=this.implements)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=x7(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ir(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0,d=!1){var w;let o=ft(t,this);const l=this.toJSON(),c=r||R.UUID.uuid();l.inputs=[],l.calls=[];const h=c.split("-id"),p=h[h.length-1||0]||c;l.id=c,l.version=R.UUID.uuid();const v=lt(l,o);t?v.setParent(t,null):v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e),e==null||e.add(v,b.Added);const E=(w=this.inputs)==null?void 0:w.map((C,U)=>C.clone(e,v,p+"-argument-declaration-"+U+"-id",a));return v.inputs=E,d?(ir(this).map((C,U)=>C.clone(e,v,p+"-body-entity-"+U+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),v):(e==null||e.attemptAutoclose("clone-entity",this.id),v)}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project,t={}){const r={id:t.id||R.UUID.uuid(),version:t.version||"1",createdAt:t.createdAt||"2024-01-01T00:00:00.000Z",author:t.author||"1",previousVersion:t.previousVersion||null,deleted:t.deleted||!1,type:n.FunctionCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addFunctionCall(a),a}createInternalCall(e,t={}){const r={id:t.id||R.UUID.uuid(),version:t.version||"1",type:n.InternalCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toShallowJSON(),index:e.internalCalls.length},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),a}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],r=[...this.returnStatements].flatMap(a=>a.outputs);if(this.implements){const a=this.implements.outputs;return r.forEach(d=>{const o=a.find(c=>c===d.implements),l=e.find(c=>c.implements===d.implements);o&&!l&&e.push(d)}),u(e)}else return r.forEach(a=>{e.find(o=>o===a||G(o,this.project)===G(a,this.project)&&Ir(o.dataType,a.dataType))||e.push(a)}),u(e)}};f(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Re,"type",n.FunctionDeclaration),f(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),f(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),f(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),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","index","collapsed"]),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,"INMUATABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUATABLE_UPSTREAM_PROPERTIES]),f(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),f(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),f(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let _i=Re;function q7(i){const s=D3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.entity&&i.andChildrenGroup||i.entity&&i.orChildrenGroup||i.andChildrenGroup&&i.orChildrenGroup){const a=ye({id:i.id+"--"+q.InvalidPropertiesCombination,message:`Data type with id "${i.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:D.Error,code:q.InvalidPropertiesCombination,entity:i});r.push(a.error)}return Ye(i.errors,r)}function J7(i,s){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],r=`'${ie(t,"', '","' or '")}'`;if(i.parent)if(i.id===i.parent)e.push(new O({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=s.get(i.parent);a?t.includes(a.type)||e.push(new O({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type ${r}.`,issue:null})):e.push(new O({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new O({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${r}.`,issue:null}));if(i.entity){if(i.id===i.entity)return e.push(new O({id:`${i.id}--${i.entity}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const a=s.get(i.entity);a?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(a.type)||e.push(new O({id:`${i.id}--${i.entity}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new O({id:`${i.id}--${i.entity}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Z1=(i=>(i.Entity="entity",i))(Z1||{});const Ae=class Ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"isList",null);f(this,"asType",null);f(this,"type",n.DataType);f(this,"options");f(this,"parentRelationType");f(this,"like");f(this,"implementationChooseOne",!1);f(this,"inferred",!1);f(this,"entity",null);f(this,"andChildrenGroup",null);f(this,"orChildrenGroup",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);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;e.entity&&(d=t.get(e.entity));const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:d,asType:e.asType,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var c;let r=JSON.parse(JSON.stringify(e));const a=[],d=J7(r,t);if(a.push(...d,...ot(r)),r.entity){const h=t.get(r.entity);if(h.type===n.DefinitionEntity){const v=Wi(h).filter(E=>!E.interactive);if(v.length){const E=v.length>1?`entities with ids '${ie(v.map(P=>P.id),"', '","' and '")}'`:`entity with id '${v[0].id}'`;a.push(new O({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${r.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
|
|
70
|
+
Please consider that any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.setImplements(null,r),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(e)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'parent' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else if(d)throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.indexOf(e);return t!==-1&&this.inputs.splice(t,1),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=V(t,this.project);return r.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.initialData.implements&&(this.implements=V(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.private=e.private||this.private,this.index=e.index||(e.index!==0?this.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Re.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),ir(this).forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),ir(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ir(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(r=>r.toJSON(e)),inputs:this.inputs.map(r=>r.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(d=>d.toReference(e)),calls:this.calls.map(d=>d.toReference(e)),implements:((a=this.implements)==null?void 0:a.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=x7(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ir(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0,d=!1){var w;let o=ft(t,this);const l=this.toJSON(),c=r||R.UUID.uuid();l.inputs=[],l.calls=[];const h=c.split("-id"),p=h[h.length-1||0]||c;l.id=c,l.version=R.UUID.uuid();const v=lt(l,o);t?v.setParent(t,null):v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e),e==null||e.add(v,b.Added);const E=(w=this.inputs)==null?void 0:w.map((C,U)=>C.clone(e,v,p+"-argument-declaration-"+U+"-id",a));return v.inputs=E,d?(ir(this).map((C,U)=>C.clone(e,v,p+"-body-entity-"+U+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),v):(e==null||e.attemptAutoclose("clone-entity",this.id),v)}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project,t={}){const r={id:t.id||R.UUID.uuid(),version:t.version||"1",createdAt:t.createdAt||"2024-01-01T00:00:00.000Z",author:t.author||"1",previousVersion:t.previousVersion||null,deleted:t.deleted||!1,type:n.FunctionCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addFunctionCall(a),a}createInternalCall(e,t={}){const r={id:t.id||R.UUID.uuid(),version:t.version||"1",type:n.InternalCall,parent:e.toReference(),successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],error:t.error||null,process:t.process||null,calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],calledByEntry:t.calledByEntry||[],declaration:this.toShallowJSON(),index:e.internalCalls.length},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),a}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],r=[...this.returnStatements].flatMap(a=>a.outputs);if(this.implements){const a=this.implements.outputs;return r.forEach(d=>{const o=a.find(c=>c===d.implements),l=e.find(c=>c.implements===d.implements);o&&!l&&e.push(d)}),u(e)}else return r.forEach(a=>{e.find(o=>o===a||G(o,this.project)===G(a,this.project)&&Ir(o.dataType,a.dataType))||e.push(a)}),u(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,...r)=>null}),f(Re,"type",n.FunctionDeclaration),f(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),f(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),f(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),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","index","collapsed"]),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,"INMUATABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUATABLE_UPSTREAM_PROPERTIES]),f(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),f(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),f(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let _i=Re;function q7(i){const s=D3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.entity&&i.andChildrenGroup||i.entity&&i.orChildrenGroup||i.andChildrenGroup&&i.orChildrenGroup){const a=ye({id:i.id+"--"+q.InvalidPropertiesCombination,message:`Data type with id "${i.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:D.Error,code:q.InvalidPropertiesCombination,entity:i});r.push(a.error)}return Ye(i.errors,r)}function J7(i,s){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],r=`'${ie(t,"', '","' or '")}'`;if(i.parent)if(i.id===i.parent)e.push(new O({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=s.get(i.parent);a?t.includes(a.type)||e.push(new O({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type ${r}.`,issue:null})):e.push(new O({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new O({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${r}.`,issue:null}));if(i.entity){if(i.id===i.entity)return e.push(new O({id:`${i.id}--${i.entity}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const a=s.get(i.entity);a?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(a.type)||e.push(new O({id:`${i.id}--${i.entity}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new O({id:`${i.id}--${i.entity}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Z1=(i=>(i.Entity="entity",i))(Z1||{});const Ae=class Ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"isList",null);f(this,"asType",null);f(this,"type",n.DataType);f(this,"options");f(this,"parentRelationType");f(this,"like");f(this,"implementationChooseOne",!1);f(this,"inferred",!1);f(this,"entity",null);f(this,"andChildrenGroup",null);f(this,"orChildrenGroup",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);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;e.entity&&(d=t.get(e.entity));const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:d,asType:e.asType,parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var c;let r=JSON.parse(JSON.stringify(e));const a=[],d=J7(r,t);if(a.push(...d,...ot(r)),r.entity){const h=t.get(r.entity);if(h.type===n.DefinitionEntity){const v=Wi(h).filter(E=>!E.interactive);if(v.length){const E=v.length>1?`entities with ids '${ie(v.map(P=>P.id),"', '","' and '")}'`:`entity with id '${v[0].id}'`;a.push(new O({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${r.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
|
|
71
71
|
${Zi}`,issue:null}))}}}const o=r.parent&&t.get(r.parent)||t.getBuiltIn(r.parent),l=o?Yi(o):null;if(l)a.push(new O({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${G(l,t)}" with id '${l.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(o){const h=o.type,p=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(p.includes(h)&&(r.parentRelationType&&a.push(new O({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${h}'.
|
|
72
72
|
The entitities of type '${ie(p,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const v=(c=o.dataType)==null?void 0:c.id;a.push(new O({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${r.parent}' and type '${h}', because it already has a 'data-type' child with id '${v}'.
|
|
73
73
|
The entitities of type '${ie(p,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
|
|
74
74
|
${qr({describe_entity:v})}
|
|
75
|
-
Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}h===n.DataType&&(!r.parentRelationType||!(r.parentRelationType===Rt.AndDataTypeGroup||r.parentRelationType===Rt.OrDataTypeGroup))&&a.push(new O({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:a,modifiedData:r}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const r of e)if(r.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||Yi(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(null),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`Data type with id '${this.id}' has a parent reference '${d}' that isn't found in the project`)}else throw new Error(`Data type with id '${this.id}' must have a parent`);if(this.initialData.entity){const d=g(this.initialData.entity),o=this.project.get(d);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.type===n.DataType?this.parentRelationType===Rt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Rt.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){var t,r;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=a}else this.entity=V(this.initialData.entity,this.project),((r=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:r.id)===this.id&&this.entity.setParent(this,null),this.entity.type===n.DefinitionEntity&&this.entity.initChildren(e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const d=V(a,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const d=V(a,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.options=e.options||this.options,this.parentRelationType=e.parentRelationType||this.parentRelationType,this.isList=e.isList!==void 0?e.isList:this.isList,this.inferred=e.inferred!==void 0?e.inferred:this.inferred,this.like=e.like!==void 0?e.like:this.like,this.asType=e.asType!==void 0?e.asType:this.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:this.implementationChooseOne,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ae.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ae.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:c,removed:h}=this.entity.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(!e){((l=this.parent)==null?void 0:l.type)===n.DataType&&this.parent.removeChildGroup(this);const c=this.parent;if((c==null?void 0:c.type)===n.DataType){if(this.parentRelationType===Rt.AndDataTypeGroup){if(Array.isArray(c.andChildrenGroup)){const h=c.andChildrenGroup.findIndex(p=>p.id===this.id);h!==-1&&c.andChildrenGroup.splice(h,1)}}else if(this.parentRelationType===Rt.OrDataTypeGroup&&Array.isArray(c.orChildrenGroup)){const h=c.orChildrenGroup.findIndex(p=>p.id===this.id);h!==-1&&c.orChildrenGroup.splice(h,1)}}else{const h=this.parent;h==null||h.removeDataType()}c&&r.push(c)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);r.push(...o)}if(this.parent.type===n.DataType){const o=this.parent;Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this)}if(this.parent.type===n.DataType){const o=this.parent;this.parentRelationType===Rt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Rt.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),r.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlat(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlat(e)))||[],...((d=this.entity)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatIds(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatIds(e)))||[],...((d=this.entity)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((r=this.orChildrenGroup)==null?void 0:r.map(o=>o.toJSON(e)))||null,entity:((a=this.entity)==null?void 0:a.parent)===this?this.entity.toJSON(e):((d=this.entity)==null?void 0:d.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((c=this.andChildrenGroup)==null?void 0:c.map(E=>E.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((h=this.orChildrenGroup)==null?void 0:h.map(E=>E.toJSONClone({...e,newId:null})))||null,entity:((p=this.entity)==null?void 0:p.parent)===this?this.entity.toJSONClone({...e,newId:null}):((v=this.entity)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(l=>l.toReference(e)))||null,orChildrenGroup:((d=this.orChildrenGroup)==null?void 0:d.map(l=>l.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatJSON(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatJSON(e)))||[],...((d=this.entity)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,r,a;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(d=>d.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(d=>d.clearErrors()),this.inferred&&this.entity&&this.entity.type===n.DefinitionEntity&&((r=this.entity)==null?void 0:r.parent)===this&&((a=this.entity)==null||a.clearErrors()),this}validate(){const e=q7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,P,w;let d=ft(t,this),o=t||this.parent;const c={id:r||R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},h=lt(c,d);t&&h.setParent(t,null),a&&h.subscribe(),h.initChildren(e),e==null||e.add(h,b.Added);const p=(E=this.andChildrenGroup)==null?void 0:E.map(C=>C.clone(e,h,R.UUID.uuid(),a)),v=(P=this.orChildrenGroup)==null?void 0:P.map(C=>C.clone(e,h,R.UUID.uuid(),a));if(h.andChildrenGroup=p||null,h.orChildrenGroup=v||null,this.entity&&this.entity.type===n.DefinitionEntity&&((w=this.entity)==null?void 0:w.parent)===this){const C=this.entity.clone(e,h,R.UUID.uuid(),a);h.setEntity(C)}else this.entity&&h.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),h}merge(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"merge-entity"))){const r=[],a=[],d=[],o=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},t),r.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},t),r.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},t),r.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const l=e.entity.clone(t,this,R.UUID.uuid(),!0);this.setEntity(l),a.push(l)}else e.entity&&(this.setEntity(e.entity),r.push(this));this.inferred||(this.metaSync({inferred:!0},t),r.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},t),r.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:l,removed:c}=this.entity.remove({ignoreUpstream:!0},t);d.push(...c),l.push(...l)}e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,b.Updated),r.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,b.Updated),r.push(this));return t==null||t.attemptAutoclose("merge-entity",this.id),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===n.DefinitionEntity||this.entity.name===M.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-from-inputs"))){var l;const r=[],a=[],d=[],o=[];if(!this.inferred)return t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&e.length){const c=G(this.parent,this.project)+" data type definition",h={id:R.UUID.uuid(),type:n.DefinitionEntity,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:c,description:((l=this.parent)==null?void 0:l.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},p=V(h,this.project);p.setParent(this,t),p.initChildren(t),t==null||t.add(p,b.Added),p.metaSync(h,t),this.setEntity(p),t==null||t.add(this,b.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:c,added:h,removed:p,affected:v}=this.entity.inferFromInputs(e,t);a.push(...c),r.push(...h),d.push(...p),o.push(...v)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:this}}};f(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ae,"type",n.DataType),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES]),f(Ae,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"inferred"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let wn=Ae;function W7(i){var o;const s=s3(),e=i.toJSON();s.safeParse(e).success;const r=Y7(i),a=fi(i),d=[...r,...a];if(i.id==="exec-sequentially-operation-call-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});d.push(l.error)}return i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate(),Ye(i.errors,d)}function Y7(i){const s=[];return i.inputs.forEach(e=>{e.validate()}),Ye(i.errors,s)}var q1=(i=>(i.Parent="parent",i))(q1||{});const De=class De extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Operation);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);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}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),h={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:r},p=V(h,t);return p.setParent(r,null),p.initChildren(null),p}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=g(r.declaration);if(o){const l=fO(o,t);a.push(...l)}else{const l=`
|
|
75
|
+
Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}h===n.DataType&&(!r.parentRelationType||!(r.parentRelationType===Rt.AndDataTypeGroup||r.parentRelationType===Rt.OrDataTypeGroup))&&a.push(new O({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:a,modifiedData:r}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const r of e)if(r.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||Yi(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="entity"&&this.setEntity(null),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`Data type with id '${this.id}' has a parent reference '${d}' that isn't found in the project`)}else throw new Error(`Data type with id '${this.id}' must have a parent`);if(this.initialData.entity){const d=g(this.initialData.entity),o=this.project.get(d);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.type===n.DataType?this.parentRelationType===Rt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Rt.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(r=>r.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){var t,r;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=a}else this.entity=V(this.initialData.entity,this.project),((r=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:r.id)===this.id&&this.entity.setParent(this,null),this.entity.type===n.DefinitionEntity&&this.entity.initChildren(e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const d=V(a,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const d=V(a,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.options=e.options||this.options,this.parentRelationType=e.parentRelationType||this.parentRelationType,this.isList=e.isList!==void 0?e.isList:this.isList,this.inferred=e.inferred!==void 0?e.inferred:this.inferred,this.like=e.like!==void 0?e.like:this.like,this.asType=e.asType!==void 0?e.asType:this.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:this.implementationChooseOne,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ae.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:c,removed:h}=this.entity.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(!e){((l=this.parent)==null?void 0:l.type)===n.DataType&&this.parent.removeChildGroup(this);const c=this.parent;if((c==null?void 0:c.type)===n.DataType){if(this.parentRelationType===Rt.AndDataTypeGroup){if(Array.isArray(c.andChildrenGroup)){const h=c.andChildrenGroup.findIndex(p=>p.id===this.id);h!==-1&&c.andChildrenGroup.splice(h,1)}}else if(this.parentRelationType===Rt.OrDataTypeGroup&&Array.isArray(c.orChildrenGroup)){const h=c.orChildrenGroup.findIndex(p=>p.id===this.id);h!==-1&&c.orChildrenGroup.splice(h,1)}}else{const h=this.parent;h==null||h.removeDataType()}c&&r.push(c)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);r.push(...o)}if(this.parent.type===n.DataType){const o=this.parent;Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this)}if(this.parent.type===n.DataType){const o=this.parent;this.parentRelationType===Rt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Rt.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),r.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlat(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlat(e)))||[],...((d=this.entity)==null?void 0:d.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatIds(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatIds(e)))||[],...((d=this.entity)==null?void 0:d.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a,d;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((r=this.orChildrenGroup)==null?void 0:r.map(o=>o.toJSON(e)))||null,entity:((a=this.entity)==null?void 0:a.parent)===this?this.entity.toJSON(e):((d=this.entity)==null?void 0:d.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((c=this.andChildrenGroup)==null?void 0:c.map(E=>E.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((h=this.orChildrenGroup)==null?void 0:h.map(E=>E.toJSONClone({...e,newId:null})))||null,entity:((p=this.entity)==null?void 0:p.parent)===this?this.entity.toJSONClone({...e,newId:null}):((v=this.entity)==null?void 0:v.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(l=>l.toReference(e)))||null,orChildrenGroup:((d=this.orChildrenGroup)==null?void 0:d.map(l=>l.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(o=>o.toFlatJSON(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(o=>o.toFlatJSON(e)))||[],...((d=this.entity)==null?void 0:d.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.andChildrenGroup)==null?void 0:r.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...((a=this.orChildrenGroup)==null?void 0:a.flatMap(d=>d.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,r,a;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(d=>d.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(d=>d.clearErrors()),this.inferred&&this.entity&&this.entity.type===n.DefinitionEntity&&((r=this.entity)==null?void 0:r.parent)===this&&((a=this.entity)==null||a.clearErrors()),this}validate(){const e=q7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,P,w;let d=ft(t,this),o=t||this.parent;const c={id:r||R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},h=lt(c,d);t&&h.setParent(t,null),a&&h.subscribe(),h.initChildren(e),e==null||e.add(h,b.Added);const p=(E=this.andChildrenGroup)==null?void 0:E.map(C=>C.clone(e,h,R.UUID.uuid(),a)),v=(P=this.orChildrenGroup)==null?void 0:P.map(C=>C.clone(e,h,R.UUID.uuid(),a));if(h.andChildrenGroup=p||null,h.orChildrenGroup=v||null,this.entity&&this.entity.type===n.DefinitionEntity&&((w=this.entity)==null?void 0:w.parent)===this){const C=this.entity.clone(e,h,R.UUID.uuid(),a);h.setEntity(C)}else this.entity&&h.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),h}merge(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"merge-entity"))){const r=[],a=[],d=[],o=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},t),r.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},t),r.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},t),r.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const l=e.entity.clone(t,this,R.UUID.uuid(),!0);this.setEntity(l),a.push(l)}else e.entity&&(this.setEntity(e.entity),r.push(this));this.inferred||(this.metaSync({inferred:!0},t),r.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},t),r.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:l,removed:c}=this.entity.remove({ignoreUpstream:!0},t);d.push(...c),l.push(...l)}e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,b.Updated),r.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,b.Updated),r.push(this));return t==null||t.attemptAutoclose("merge-entity",this.id),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===n.DefinitionEntity||this.entity.name===M.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-from-inputs"))){var l;const r=[],a=[],d=[],o=[];if(!this.inferred)return t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&e.length){const c=G(this.parent,this.project)+" data type definition",h={id:R.UUID.uuid(),type:n.DefinitionEntity,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:c,description:((l=this.parent)==null?void 0:l.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},p=V(h,this.project);p.setParent(this,t),p.initChildren(t),t==null||t.add(p,b.Added),p.metaSync(h,t),this.setEntity(p),t==null||t.add(this,b.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:c,added:h,removed:p,affected:v}=this.entity.inferFromInputs(e,t);a.push(...c),r.push(...h),d.push(...p),o.push(...v)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:this}}};f(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ae,"type",n.DataType),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES]),f(Ae,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"inferred"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let wn=Ae;function W7(i){var o;const s=s3(),e=i.toJSON();s.safeParse(e).success;const r=Y7(i),a=fi(i),d=[...r,...a];if(i.id==="exec-sequentially-operation-call-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});d.push(l.error)}return i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate(),Ye(i.errors,d)}function Y7(i){const s=[];return i.inputs.forEach(e=>{e.validate()}),Ye(i.errors,s)}var q1=(i=>(i.Parent="parent",i))(q1||{});const De=class De extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Operation);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);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}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),h={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:r},p=V(h,t);return p.setParent(r,null),p.initChildren(null),p}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=g(r.declaration);if(o){const l=fO(o,t);a.push(...l)}else{const l=`
|
|
76
76
|
All built-in 'action-descriptor' entity ids are:
|
|
77
77
|
- ${t.operationDeclarations.map(c=>`${c.id} (${G(c,t)})`).join(`
|
|
78
78
|
- `)}.
|
|
79
79
|
`;a.push(new O({id:`${r.id}--${I.InvalidReference}`,code:I.InvalidReference,severity:D.Error,message:`Entity of type "${n.Operation}" with id "${r.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'action-descriptor' entity.
|
|
80
80
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${l}`,issue:null}))}return{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:h,added:p,removed:v}=this.syncMissingFixedOutputs(e),{updated:E,added:P,removed:w}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...h,...E),r.push(...l,...p,...E),a.push(...c,...v,...E),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?r.setParent(this.parent.parent,null):r.type!==n.InternalCall&&r.setParent(this.parent,null),r.initChildren(e),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await De.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await De.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.process){const{updated:c,removed:h}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.outputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.error){const{updated:c,removed:h}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(h=this.error)==null?void 0:h.toJSONClone({...e,newId:null})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=W7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>p.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id}));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1},e)});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.outputs.filter(p=>p.parentRelationType===_.FixedReturns&&!this.outputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id}));this.outputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.outputs.forEach(P=>{P.index>=p.index&&P.index++});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:p.toJSON(),defaultValue:null,writesValues:[],index:p.index,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.outputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedOutputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(De,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(De,"type",n.Operation),f(De,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),f(De,"MUTABLE_BASE_PROPERTIES",[]),f(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),f(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"x","y"]),f(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),f(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),f(De,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(De,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),f(De,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let Mi=De;function z7(i){const s=Z3(),e=i.toJSON();s.safeParse(e).success;const r=ir(i);i.inputs.forEach(d=>d.validate()),r.forEach(d=>d.validate());const a=[];return Ye(i.errors,a)}const Oe=class Oe extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a;e.implements&&(a=t.getBuiltIn(e.implements));const d={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=V(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{},t);if(r=d.modifiedData,a.push(...d.errors,...ot(r)),!e.implements)a.push(new O({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:h,added:p,removed:v}=this.syncMissingFixedOutputs(e),{updated:E,added:P,removed:w}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...h,...E),r.push(...l,...p,...E),a.push(...c,...v,...E),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?r.setParent(this.parent.parent,null):r.type!==n.InternalCall&&r.setParent(this.parent,null),r.initChildren(e),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await De.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.process){const{updated:c,removed:h}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.outputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.error){const{updated:c,removed:h}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(h=this.error)==null?void 0:h.toJSONClone({...e,newId:null})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=W7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>p.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id}));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1},e)});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.outputs.filter(p=>p.parentRelationType===_.FixedReturns&&!this.outputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id}));this.outputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.outputs.forEach(P=>{P.index>=p.index&&P.index++});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:p.toJSON(),defaultValue:null,writesValues:[],index:p.index,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.outputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedOutputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(De,"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,...r)=>null}),f(De,"type",n.Operation),f(De,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),f(De,"MUTABLE_BASE_PROPERTIES",[]),f(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),f(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"x","y"]),f(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),f(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),f(De,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(De,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),f(De,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let Mi=De;function z7(i){const s=Z3(),e=i.toJSON();s.safeParse(e).success;const r=ir(i);i.inputs.forEach(d=>d.validate()),r.forEach(d=>d.validate());const a=[];return Ye(i.errors,a)}const Oe=class Oe extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const l=g(e.parent);r=t.get(l)}let a;e.implements&&(a=t.getBuiltIn(e.implements));const d={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:a,x:0,y:0,parent:r},o=V(d,t);return o.setParent(r,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{},t);if(r=d.modifiedData,a.push(...d.errors,...ot(r)),!e.implements)a.push(new O({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.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
|
${jd(t)}`,issue:null}));else if(!t.get(e.implements))a.push(new O({id:`${e.id}--${I.ReferencedEntityNotFound}`,code:I.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
|
${jd(t)}`,issue:null}));else if(!t.globalEventActionDescriptors.find(c=>c.id===e.implements))a.push(new O({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.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
|
${jd(t)}`,issue:null}));else{const c=t.events.find(h=>h.implements.id===e.implements);c&&a.push(new O({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.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 '${c.id}' in the project. Each global event must implement a unique action descriptor.
|
|
86
|
-
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Bd.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 O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=V(t,this.project);return r.addEntryCaller(this,null),r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.implements=V(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Oe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Oe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),ir(this).forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),ir(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ir(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),calls:this.calls.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=z7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ir(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0,d=!1){var w;let o=ft(t,this);const l=this.toJSON(),c=r||R.UUID.uuid();l.inputs=[];const h=c.split("-id"),p=h[h.length-1||0]||c;l.id=c,l.version=R.UUID.uuid();const v=lt(l,o);t?v.setParent(t,null):v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e),e==null||e.add(v,b.Added);const E=(w=this.inputs)==null?void 0:w.map((C,U)=>C.clone(e,v,p+"-argument-declaration-"+U+"-id",a));return v.inputs=E,d?(ir(this).map((C,U)=>C.clone(e,v,p+"-body-entity-"+U+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),v):(e==null||e.attemptAutoclose("clone-entity",this.id),v)}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};f(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Oe,"type",n.GlobalEvent),f(Oe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),f(Oe,"MUTABLE_BASE_PROPERTIES",["description"]),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","collapsed"]),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",[]),f(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),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 Vn=Oe;function H7(i){var a;const s=B6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var vp=(i=>(i.Parent="parent",i))(vp||{});const Se=class Se extends rt{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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),o=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),l=e.calledByError.map(p=>{const v=g(p);return t.get(v)}),c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},h=V(c,t);return h.setParent(a,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
86
|
+
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:a,modifiedData:r}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Bd.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 O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a 'implements' reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e){return this.calls.includes(e)||this.calls.push(e),this}removeCall(e){const t=this.calls.indexOf(e);return t!==-1&&this.calls.splice(t,1),this}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.calls=this.initialData.calls.map(t=>{const r=V(t,this.project);return r.addEntryCaller(this,null),r.type!==n.InternalCall&&(r.setParent(this,null),r.initChildren(e)),r}),this.implements=V(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.collapsed=e.collapsed!==void 0?e.collapsed:this.collapsed,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Oe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),ir(this).forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),ir(this).forEach(l=>{const{updated:c}=l.restore({},e);r.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.calls.flatMap(r=>r.toFlat(e)),...this.returnStatements.flatMap(r=>r.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ir(this);return[this.id,...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.calls.flatMap(a=>a.toFlatIds(e)),...this.returnStatements.flatMap(a=>a.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(a=>a.toFlatIds(e))]}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),calls:this.calls.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),calls:this.calls.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.calls.flatMap(r=>r.toFlatJSON(e)),...this.returnStatements.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.calls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=z7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ir(this);return[...this.errors,...this.inputs.flatMap(r=>r.getErrors()),...e.flatMap(r=>r.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0,d=!1){var w;let o=ft(t,this);const l=this.toJSON(),c=r||R.UUID.uuid();l.inputs=[];const h=c.split("-id"),p=h[h.length-1||0]||c;l.id=c,l.version=R.UUID.uuid();const v=lt(l,o);t?v.setParent(t,null):v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e),e==null||e.add(v,b.Added);const E=(w=this.inputs)==null?void 0:w.map((C,U)=>C.clone(e,v,p+"-argument-declaration-"+U+"-id",a));return v.inputs=E,d?(ir(this).map((C,U)=>C.clone(e,v,p+"-body-entity-"+U+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),v):(e==null||e.attemptAutoclose("clone-entity",this.id),v)}getVariableInstances(){return We(this).filter(r=>r.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};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,...r)=>null}),f(Oe,"type",n.GlobalEvent),f(Oe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),f(Oe,"MUTABLE_BASE_PROPERTIES",["description"]),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","collapsed"]),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",[]),f(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),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 Vn=Oe;function H7(i){var a;const s=B6(),e=i.toJSON();s.safeParse(e).success,i.outputs.forEach(d=>d.validate()),(a=i.throws)==null||a.validate();const r=[];return Ye(i.errors,r)}var vp=(i=>(i.Parent="parent",i))(vp||{});const Se=class Se extends rt{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 fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),o=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),l=e.calledByError.map(p=>{const v=g(p);return t.get(v)}),c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:l,calledByEntry:d,throws:null,parent:a},h=V(c,t);return h.setParent(a,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.Loop]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Se(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addCall(this),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addSuccessCall(this),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addErrorCall(this),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Se.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Se.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((h=this.throws)==null?void 0:h.toJSONClone({...e,newId:null}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=H7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.outputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.outputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-return-declaration-"+w+"-id",a));return p.outputs=v,this.throws&&(p.throws=this.throws.clone(e,p,h+"-throws-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(Se,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Se,"type",n.BreakStatement),f(Se,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(Se,"MUTABLE_BASE_PROPERTIES",[]),f(Se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"MUTABLE_META_PROPERTIES",["x","y"]),f(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),f(Se,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Se,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),f(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Se,"PROPERTIES",[...Se.META_PROPERTIES,...Se.UPSTREAM_PROPERTIES,...Se.DOWNSTREAM_PROPERTIES]);let Cn=Se;function K7(i){var d,o;const s=h6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(d=i.error)==null||d.validate(),(o=i.body)==null||o.validate();const a=[...fi(i)];return Ye(i.errors,a)}function X7(i){const s=nD(),e=i.toJSON();s.safeParse(e).success,i.inputs.flatMap(a=>a.validate()),i.outputs.flatMap(a=>a.validate());const r=[];return Ye(i.errors,r)}var J1=(i=>(i.Success="success",i.Error="error",i.Break="break",i.Continue="continue",i.Return="return",i))(J1||{});const Pe=class Pe extends rt{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 fromGenerationTarget(e,t){let r=null;if(e.parent){const o=g(e.parent);r=t.get(o)}const a={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:r},d=V(a,t);return r&&d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);r=d.modifiedData;const o=r.parent?t.get(r.parent):null;if(o&&o.type===n.DefinitionEntity){const l=o,h=Wi(l).filter(p=>!p.interactive);if(h.length){let p=h.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ie(h.map(v=>G(v,v.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${G(h[0],h[0].project)}").`;p+=`
|
|
89
|
+
Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Se(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addCall(this),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addSuccessCall(this),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(l.addErrorCall(this),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutputDeclaration(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.throws&&(this.throws=V(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Se.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.throws){const{updated:l,removed:c}=this.throws.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.throws){const{updated:o}=this.throws.restore({},e);r.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(r=>r.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((r=this.throws)==null?void 0:r.toJSON(e))||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((h=this.throws)==null?void 0:h.toJSONClone({...e,newId:null}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((a=this.throws)==null?void 0:a.toReference(e))||null,parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=H7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.outputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.outputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-return-declaration-"+w+"-id",a));return p.outputs=v,this.throws&&(p.throws=this.throws.clone(e,p,h+"-throws-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(Se,"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,...r)=>null}),f(Se,"type",n.BreakStatement),f(Se,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(Se,"MUTABLE_BASE_PROPERTIES",[]),f(Se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"MUTABLE_META_PROPERTIES",["x","y"]),f(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),f(Se,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Se,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),f(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Se,"PROPERTIES",[...Se.META_PROPERTIES,...Se.UPSTREAM_PROPERTIES,...Se.DOWNSTREAM_PROPERTIES]);let Cn=Se;function K7(i){var d,o;const s=h6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(d=i.error)==null||d.validate(),(o=i.body)==null||o.validate();const a=[...fi(i)];return Ye(i.errors,a)}function X7(i){const s=nD(),e=i.toJSON();s.safeParse(e).success,i.inputs.flatMap(a=>a.validate()),i.outputs.flatMap(a=>a.validate());const r=[];return Ye(i.errors,r)}var J1=(i=>(i.Success="success",i.Error="error",i.Break="break",i.Continue="continue",i.Return="return",i))(J1||{});const Pe=class Pe extends rt{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 fromGenerationTarget(e,t){let r=null;if(e.parent){const o=g(e.parent);r=t.get(o)}const a={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:r},d=V(a,t);return r&&d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);r=d.modifiedData;const o=r.parent?t.get(r.parent):null;if(o&&o.type===n.DefinitionEntity){const l=o,h=Wi(l).filter(p=>!p.interactive);if(h.length){let p=h.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ie(h.map(v=>G(v,v.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${G(h[0],h[0].project)}").`;p+=`
|
|
90
90
|
${Zi}`,a.push(new O({id:`${e.id}--${I.NonInteractiveEntityReferenced}`,code:I.NonInteractiveEntityReferenced,severity:D.Error,message:p,issue:null}))}}else if(o&&o.type===n.DataType){const l=o;l.entity&&a.push(new O({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.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 '${l.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
91
91
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
92
92
|
${qr({describe_entity:l.entity.id})}
|
|
93
93
|
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}syncOperationInstance(e,t){return{updated:[],added:[],removed:[],affected:[],self:e}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type"))){const r=ap(e);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type"))){const r=op(e);return t==null||t.attemptAutoclose("infer-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
94
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this})}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.outputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.error){const l=this.error.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.outputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}implementAsFunctionDeclaration(e){var a;const t=this.inputs.map((d,o)=>{var c;const l={id:e+"--"+d.id+"--parent-ref",type:n.GenericReference,version:R.UUID.uuid(),entityType:n.FunctionDeclaration,entityId:e};return{id:R.UUID.uuid(),version:d.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:d.name,required:d.required,implements:d.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:d.description,index:o,dataType:((c=d.dataType)==null?void 0:c.toJSON())||null,parent:l}}),r=[];if(this.outputs.length){const d=this.outputs.map((h,p)=>{var E;const v={id:e+"--return-statement--"+h.id+"--parent-ref",type:n.GenericReference,entityId:e,version:R.UUID.uuid(),entityType:n.ReturnStatement};return{id:R.UUID.uuid(),version:h.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:h.name,description:h.description,readsValue:null,constant:!0,required:h.required,defaultValue:null,implements:h.toJSON(),isError:!1,index:p,dataType:((E=h.dataType)==null?void 0:E.toJSON())||null,parent:v}}),o={id:e+"--return-statement-parent-ref",type:n.GenericReference,version:R.UUID.uuid(),entityType:n.FunctionDeclaration,entityId:e},l={id:e+"--return-statement-called-by-ref",type:n.GenericReference,version:R.UUID.uuid(),entityType:n.FunctionDeclaration,entityId:e},c={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:d,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[l],parent:o,x:0,y:0};r.push(c)}return{id:e,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:t,calls:r,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((a=this.parent)==null?void 0:a.toReference())||null,x:0,y:0}}implementAsLoop(e){const t=e||this.project,r=R.UUID.uuid(),a={id:r,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:t.toReference()};this.inputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Loop}};a.inputs.push(h)}),this.outputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Loop}};a.outputs.push(h)});const d={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"body",description:null,inputs:[],calls:[],implements:null,index:null,collapsed:!1,private:!1,x:0,y:0,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Loop}};d.inputs=[{id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Current iteration number",description:"The number of the current iteration of the loop. Starts at 1.",dataType:null,required:!0,constant:!0,defaultValue:null,writesValues:[],implements:null,index:0,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:R.UUID.uuid(),entityType:n.FunctionDeclaration}},{id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Previous iterations results",description:"The results of the previous iterations of the loop.",dataType:null,constant:!0,required:!0,defaultValue:null,writesValues:[],implements:null,index:1,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:R.UUID.uuid(),entityType:n.FunctionDeclaration}}],a.body=d;const o=V(a,this.project);return o.setParent(t,null),o.initChildren(null),o}implementAsOperation(e,t){const r=e||this.project,a=t||R.UUID.uuid(),d={id:a,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,successCalls:[],errorCalls:[],process:null,calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:r.toReference()};if(this.inputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:a,version:R.UUID.uuid(),entityType:n.Operation}};d.inputs.push(h)}),this.outputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:a,version:R.UUID.uuid(),entityType:n.Operation}};d.outputs.push(h)}),this.error){const l={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:this.error,writesValues:[],defaultValue:null,index:-1,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:a,version:R.UUID.uuid(),entityType:n.Operation}};d.error=l}const o=V(d,this.project);return o.setParent(r,null),o.initChildren(null),o}implementAsCondition(e){const t=e||this.project,r=R.UUID.uuid(),a={id:r,version:this.version,type:n.Condition,declaration:this.toJSON(),operator:null,inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:t.toReference()};this.inputs.forEach((o,l)=>{const c={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,declaration:o,defaultValue:null,readsValue:null,index:l,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Condition}};a.inputs.push(c)});const d=V(a,this.project);return d.setParent(t,null),d.initChildren(null),d}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=X7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C;if(Array.from(new Set([...Wr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const l=this.toJSON(),c=r||R.UUID.uuid();l.inputs=[],l.outputs=[],l.error=null;const h=c.split("-id"),p=h[h.length-1||0]||c;l.id=c,l.version=R.UUID.uuid();const v=lt(l,o);e==null||e.add(v,b.Added),t?v.setParent(t,null):this.parent&&v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e);const E=(w=this.inputs)==null?void 0:w.map((U,S)=>U.clone(e,v,p+"-argument-value-descriptor-"+S+"-id",a));v.inputs=E;const P=(C=this.outputs)==null?void 0:C.map((U,S)=>U.clone(e,v,p+"-return-value-descriptor-"+S+"-id",a));return v.outputs=P,this.error&&(v.error=this.error.clone(e,v,p+"-error-action-descriptor-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),v}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Pe,"type",n.ActionDescriptor),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Pe,"MUTABLE_BASE_PROPERTIES",["name","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]),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"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),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 qe=Pe;var W1=(i=>(i.Parent="parent",i))(W1||{});const ae=class ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Loop);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"outputsDeclarations",[]);f(this,"body");f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"currentIterationNumberArgumentDeclaration");f(this,"currentValueArgumentDeclaration",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);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),h={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},p=V(h,t);return p.setParent(r,null),p.initChildren(null),p}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new O({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.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.
|
|
94
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent&&this.parent.type!==n.BuiltInBaseEntity&&this.parent.type!==n.PrimitiveEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent?(this.parent.type===n.DefinitionEntity?(this.parent.addAbstractMethod(this),t.push(this.parent)):this.parent.type===n.DataType&&(this.parent.setEntity(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this})}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Pe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.outputs.forEach(l=>{const c=l.remove({ignoreUpstream:!0},t);r.push(...c.updated),a.push(...c.removed)}),this.error){const l=this.error.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.outputs.forEach(o=>{const l=o.restore({},e);r.push(...l.updated)}),this.error){const o=this.error.restore({},e);r.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(a=>a.toJSON()),outputs:this.outputs.map(a=>a.toJSON()),parent:((r=this.parent)==null?void 0:r.toReference())||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),parent:((h=this.parent)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((a=this.error)==null?void 0:a.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((d=this.parent)==null?void 0:d.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,parent:((e=this.parent)==null?void 0:e.id)||void 0}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e))])}implementAsFunctionDeclaration(e){var a;const t=this.inputs.map((d,o)=>{var c;const l={id:e+"--"+d.id+"--parent-ref",type:n.GenericReference,version:R.UUID.uuid(),entityType:n.FunctionDeclaration,entityId:e};return{id:R.UUID.uuid(),version:d.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:d.name,required:d.required,implements:d.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:d.description,index:o,dataType:((c=d.dataType)==null?void 0:c.toJSON())||null,parent:l}}),r=[];if(this.outputs.length){const d=this.outputs.map((h,p)=>{var E;const v={id:e+"--return-statement--"+h.id+"--parent-ref",type:n.GenericReference,entityId:e,version:R.UUID.uuid(),entityType:n.ReturnStatement};return{id:R.UUID.uuid(),version:h.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:h.name,description:h.description,readsValue:null,constant:!0,required:h.required,defaultValue:null,implements:h.toJSON(),isError:!1,index:p,dataType:((E=h.dataType)==null?void 0:E.toJSON())||null,parent:v}}),o={id:e+"--return-statement-parent-ref",type:n.GenericReference,version:R.UUID.uuid(),entityType:n.FunctionDeclaration,entityId:e},l={id:e+"--return-statement-called-by-ref",type:n.GenericReference,version:R.UUID.uuid(),entityType:n.FunctionDeclaration,entityId:e},c={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:d,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[l],parent:o,x:0,y:0};r.push(c)}return{id:e,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:t,calls:r,collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:((a=this.parent)==null?void 0:a.toReference())||null,x:0,y:0}}implementAsLoop(e){const t=e||this.project,r=R.UUID.uuid(),a={id:r,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],outputsDeclarations:[],body:null,x:0,y:0,parent:t.toReference()};this.inputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Loop}};a.inputs.push(h)}),this.outputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Loop}};a.outputs.push(h)});const d={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"body",description:null,inputs:[],calls:[],implements:null,index:null,collapsed:!1,private:!1,x:0,y:0,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Loop}};d.inputs=[{id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Current iteration number",description:"The number of the current iteration of the loop. Starts at 1.",dataType:null,required:!0,constant:!0,defaultValue:null,writesValues:[],implements:null,index:0,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:R.UUID.uuid(),entityType:n.FunctionDeclaration}},{id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"Previous iterations results",description:"The results of the previous iterations of the loop.",dataType:null,constant:!0,required:!0,defaultValue:null,writesValues:[],implements:null,index:1,parent:{id:d.id,type:n.GenericReference,entityId:d.id,version:R.UUID.uuid(),entityType:n.FunctionDeclaration}}],a.body=d;const o=V(a,this.project);return o.setParent(t,null),o.initChildren(null),o}implementAsOperation(e,t){const r=e||this.project,a=t||R.UUID.uuid(),d={id:a,version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,successCalls:[],errorCalls:[],process:null,calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:r.toReference()};if(this.inputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,type:n.InputMap,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,declaration:l,defaultValue:null,readsValue:null,index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:a,version:R.UUID.uuid(),entityType:n.Operation}};d.inputs.push(h)}),this.outputs.forEach((l,c)=>{const h={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:l,defaultValue:null,writesValues:[],index:c,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:a,version:R.UUID.uuid(),entityType:n.Operation}};d.outputs.push(h)}),this.error){const l={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:this.error,writesValues:[],defaultValue:null,index:-1,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:a,version:R.UUID.uuid(),entityType:n.Operation}};d.error=l}const o=V(d,this.project);return o.setParent(r,null),o.initChildren(null),o}implementAsCondition(e){const t=e||this.project,r=R.UUID.uuid(),a={id:r,version:this.version,type:n.Condition,declaration:this.toJSON(),operator:null,inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:t.toReference()};this.inputs.forEach((o,l)=>{const c={id:R.UUID.uuid(),version:this.version,createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,declaration:o,defaultValue:null,readsValue:null,index:l,parent:{id:R.UUID.uuid(),type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.Condition}};a.inputs.push(c)});const d=V(a,this.project);return d.setParent(t,null),d.initChildren(null),d}clearErrors(){var e;return this.errors=[],this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=X7(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C;if(Array.from(new Set([...Wr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const l=this.toJSON(),c=r||R.UUID.uuid();l.inputs=[],l.outputs=[],l.error=null;const h=c.split("-id"),p=h[h.length-1||0]||c;l.id=c,l.version=R.UUID.uuid();const v=lt(l,o);e==null||e.add(v,b.Added),t?v.setParent(t,null):this.parent&&v.setParent(this.parent,null),a&&v.subscribe(),v.initChildren(e);const E=(w=this.inputs)==null?void 0:w.map((U,S)=>U.clone(e,v,p+"-argument-value-descriptor-"+S+"-id",a));v.inputs=E;const P=(C=this.outputs)==null?void 0:C.map((U,S)=>U.clone(e,v,p+"-return-value-descriptor-"+S+"-id",a));return v.outputs=P,this.error&&(v.error=this.error.clone(e,v,p+"-error-action-descriptor-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),v}addInput(e){return this.inputs.find(t=>t.id===e.id)||this.inputs.push(e),this}removeInput(e){return this.inputs=this.inputs.filter(t=>t.id!==e.id),this}addOutput(e){return this.outputs.find(t=>t.id===e.id)||this.outputs.push(e),this}removeOutput(e){return this.outputs=this.outputs.filter(t=>t.id!==e.id),this}};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,...r)=>null}),f(Pe,"type",n.ActionDescriptor),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Pe,"MUTABLE_BASE_PROPERTIES",["name","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]),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"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),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 qe=Pe;var W1=(i=>(i.Parent="parent",i))(W1||{});const ae=class ae extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Loop);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"outputsDeclarations",[]);f(this,"body");f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"currentIterationNumberArgumentDeclaration");f(this,"currentValueArgumentDeclaration",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);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const v=g(e.parent);r=t.get(v)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(v=>{const E=g(v);return t.get(E)}),l=e.calledBySuccess.map(v=>{const E=g(v);return t.get(E)}),c=e.calledByError.map(v=>{const E=g(v);return t.get(E)}),h={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Loop,declaration:d,calledByEntry:o,calledBySuccess:l,calledByError:c,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:r},p=V(h,t);return p.setParent(r,null),p.initChildren(null),p}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new O({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.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.
|
|
95
95
|
${$d(t)}`,issue:null})):a.push(new O({id:`${e.id}--${I.ReferencedEntityNotFound}`,code:I.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.
|
|
96
96
|
${$d(t)}`,issue:null})):a.push(new O({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.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
|
${$d(t)}`,issue:null})),{errors:a,modifiedData:r}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${G(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 '${G(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===mp.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===vp.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 O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ae(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ae(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncChildren(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=V(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ae.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ae.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ae.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.body.restore({},e),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(r=>r.toFlat(e)),...this.breakStatements.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(r=>r.toFlatIds(e)),...this.breakStatements.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),error:((r=this.error)==null?void 0:r.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:((c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(p=>p.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),error:((h=this.error)==null?void 0:h.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((a=this.declaration)==null?void 0:a.toReference(e))||null,body:((d=this.body)==null?void 0:d.toReference(e))||null,inputs:this.inputs.map(c=>c.toReference(e)),outputs:this.outputs.map(c=>c.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(c=>c.toReference(e)),successCalls:this.successCalls.map(c=>c.toReference(e)),errorCalls:this.errorCalls.map(c=>c.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(c=>c.toReference(e)),calledByError:this.calledByError.map(c=>c.toReference(e)),calledByEntry:this.calledByEntry.map(c=>c.toReference(e)),error:((l=this.error)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.body)==null?void 0:r.toFlatJSON(e))||[],...this.successCalls.flatMap(a=>a.toFlatJSON(e)),...this.errorCalls.flatMap(a=>a.toFlatJSON(e)),...this.inputs.flatMap(a=>a.toFlatJSON(e)),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.continueStatements.flatMap(a=>a.toFlatJSON(e)),...this.breakStatements.flatMap(a=>a.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.body)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.inputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.outputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.continueStatements.forEach(r=>r.clearErrors()),this.breakStatements.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=K7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.body&&(p.body=this.body.clone(e,p,h+"-body-id",a,!0)),this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}getVariableInstances(){return this.body?We(this.body).filter(r=>r.type===n.VariableInstance):[]}addReturnStatement(e){return at.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return at.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(r=>{r.outputs.forEach(d=>{e.find(l=>l===d||G(l,this.project)===G(d,this.project)&&Ir(l.dataType,d.dataType))||e.push(d)})}),u(e)}syncTerminationStatements(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(c=>{const h=c.outputs,p=o.filter(v=>!h.find(E=>G(v,this.project)===G(E,this.project)&&Ir(v.dataType,E.dataType)));p.length&&(t.push(c),e==null||e.add(c,b.Updated)),p.forEach(v=>{const E=v.clone(e,c);e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],r=[],a=[],d=[];return this.body.inputs.sort((l,c)=>l.index-c.index),this.body.inputs.forEach((l,c)=>{l.index!==c&&(l.metaSync({index:c},e),t.push(l))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),r.push(...l),a.push(...c);const h=this.getUniqueReturnDeclarations(),p=this.body.inputs;h.sort((w,C)=>w.index-C.index),h.forEach(w=>{const C=w.getDataType(e);let S=p.find(ce=>G(ce,this.project)===ae.fromReturnDeclarationToBodyArgumentDeclarationName(w)&&Ir(ce.dataType,w.dataType));if(!S){const ce=ae.fromReturnDeclarationToBodyArgumentDeclarationName(w),Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ce,description:`Aggretated list of all previously outputted values from each iteration by the output '${G(w,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:w.index,required:w.required,parent:this.body.toReference(),writesValues:[]},Q=V(Te,this.project);Q.setParent(this.body,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),r.push(Q),S=Q}const B=this.body.inputs.find(ce=>ce.index===S.index&&ce!==S),$=this.body.inputs.filter(ce=>ce!==S);let k=S.index;B&&(k=Math.max(...$.map(ce=>ce.index))+1),S.index!==k&&(S.metaSync({index:k},e),t.push(S));const W=S.getDataType(e);let ee=W;if(C)if(!W||!Ir(W,C)){if(!ee){const Te=C.clone(e,S);e==null||e.add(Te,b.Added),Te.addSelfToProject(e),ee=Te,r.push(Te),t.push(S)}const ce=ee.merge(C,e);ce.self===ee?C.remove({ignoreUpstream:!1},e):ce.self===C&&(ee.remove({ignoreUpstream:!1},e),ee=C),ee.metaSync({isList:!0},e)}else ee.isList||(ee.metaSync({isList:!0},e),t.push(ee));if(!C&&!ee){const ce={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},Te=V(ce,this.project);Te.metaSync({isList:!0},e),Te.setParent(S,e),Te.initChildren(e),e==null||e.add(Te,b.Added),Te.addSelfToProject(e),r.push(Te)}});const{updated:v,added:E,removed:P}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...v),r.push(...E),a.push(...P),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations(),l=this.outputsDeclarations;return o.forEach((h,p)=>{h.index!==p&&(h.metaSync({index:p},e),t.push(h))}),o.forEach(h=>{const p=h.getDataType(e);let E=l.find(C=>G(C,this.project)===ae.fromReturnDeclarationToLoopOutputDeclarationName(h)&&Ir(C.dataType,h.dataType));if(!E){const C=ae.fromReturnDeclarationToLoopOutputDeclarationName(h),U={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:C,description:`Aggretated list of all previously outputted values from each iteration by the output '${G(h,this.project)}'`,defaultValue:null,dataType:null,index:h.index,required:h.required,parentRelationType:_.FixedReturns,parent:this.toReference()},S=V(U,this.project);S.setParent(this,e),S.initChildren(e),e==null||e.add(S,b.Added),S.addSelfToProject(e),r.push(S),E=S}E.index!==h.index&&(E.metaSync({index:h.index},e),t.push(E));let w=E.getDataType(e);if(p)if(!w||!Ir(w,p)){if(!w){const U=p.clone(e,E);e==null||e.add(U,b.Added),U.addSelfToProject(e),w=U,r.push(U),t.push(E)}const C=w.merge(p,e);C.self===w?p.remove({ignoreUpstream:!1},e):C.self===p&&(w.remove({ignoreUpstream:!1},e),w=p),w.metaSync({isList:!0},e)}else w.isList||(w.metaSync({isList:!0},e),t.push(w));if(!p&&!w){const C={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:E.toReference()},U=V(C,this.project);U.metaSync({isList:!0},e),U.setParent(E,e),U.initChildren(e),e==null||e.add(U,b.Added),U.addSelfToProject(e),r.push(U)}}),l.filter(h=>!o.find(v=>G(h,this.project)===ae.fromReturnDeclarationToLoopOutputDeclarationName(v))).forEach(h=>{const{updated:p,removed:v}=h.remove({ignoreUpstream:!1},e);t.push(...p),a.push(...v)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.outputsDeclarations,l=this.outputs;return o.forEach(h=>{var E;let v=l.find(P=>{var w,C;return((w=P.declaration)==null?void 0:w.id)===h.id&&Ir((C=P.declaration)==null?void 0:C.dataType,h.dataType)});if(v)((E=v.declaration)==null?void 0:E.id)!==h.id&&(v.setDeclaration(h),t.push(v));else{const P={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:h.index,declaration:h.toJSON(),writesValues:[],parent:this.toReference()},w=V(P,this.project);w.setParent(this,e),w.initChildren(e),e==null||e.add(w,b.Added),w.addSelfToProject(e),r.push(w),v=w}v.index!==h.index&&(v.metaSync({index:h.index},e),t.push(v))}),l.filter(h=>!o.find(v=>{var E;return((E=h.declaration)==null?void 0:E.id)===v.id})).forEach(h=>{const{updated:p,removed:v}=h.remove({ignoreUpstream:!1},e);t.push(...p),a.push(...v)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],r=[],a=[],d=[];let l=this.body.inputs.find(v=>{var E;return v.name===ae.CURRENT_ITERATION_NUMBER_ARG_NAME||v.id===((E=this.currentIterationNumberArgumentDeclaration)==null?void 0:E.id)});const c=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!l){const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:c==null?void 0:c.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},E=V(v,this.project);E.setParent(this.body,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),l=E}!l.index&&l.index!==0&&(l.metaSync({index:0},e),t.push(l)),(!l.implements||l.implements.id!==c.id)&&(l.setImplements(c,e),t.push(l));let p=l.getDataType(e);if(!p){const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:l.toReference()},E=V(v,this.project);E.setParent(l,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),p=E}if(!p.entity||p.entity.type!==n.PrimitiveEntity||p.entity.name!==M.Number||p.entity.id!==F["primitive-entity"].number.id){const v=this.project.getBuiltIn(F["primitive-entity"].number.id);p.setEntity(v),t.push(p)}return this.currentIterationNumberArgumentDeclaration=l,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],r=[],a=[],d=[],o=this.body.inputs,l=this.getUniqueReturnDeclarations();return o.filter(h=>h===this.currentIterationNumberArgumentDeclaration||h===this.currentValueArgumentDeclaration?!1:!l.find(v=>G(h,this.project)===ae.fromReturnDeclarationToBodyArgumentDeclarationName(v))).forEach(h=>{const{updated:p,removed:v}=h.remove({ignoreUpstream:!1},e);t.push(...p),a.push(...v)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var h,p,v,E,P;const t=[],r=[],a=[],d=[];switch(this.declaration.id){case K.List:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.List].body.inputs.currentValue.id}),C=this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.List].inputs.list.id});if(!C)break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop][K.List].inputs.list.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U,e),t.push(w));let $=w.getDataType(e);if(!$){const W={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},ee=V(W,this.project);ee.setParent(S,e),ee.initChildren(e),e==null||e.add(ee,b.Added),ee.addSelfToProject(e),r.push(ee),$=ee}const k=C.getDataType(e);$.merge(k,e),$.metaSync({isList:!1},e)}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case K.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case K.Counted:{this.currentValueArgumentDeclaration=null;break}case K.ObjectKeys:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.ObjectKeys].inputs.object.id}))break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop][K.ObjectKeys].inputs.object.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U),t.push(w));let $=w.getDataType(e);if($){const k=this.project.getBuiltIn(F["primitive-entity"].string.id);((h=$.entity)==null?void 0:h.id)!==k.id&&($.setEntity(k),t.push($))}else{const k={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},W=V(k,this.project);W.setParent(S,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),$=W}}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case K.ObjectValues:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.ObjectValues].body.inputs.currentValue.id}),C=this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.ObjectValues].inputs.object.id});if(!C)break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop][K.ObjectValues].inputs.object.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U,e),t.push(w));let $=w.getDataType(e);if($){const k=C.getDataType(e),W=((v=k==null?void 0:k.entity)==null?void 0:v.properties)||[];(E=$.orChildrenGroup)==null||E.forEach(ee=>{const{updated:ce,removed:Te}=ee.remove({ignoreUpstream:!1},e);t.push(...ce),a.push(...Te)}),W.forEach(ee=>{if(!ee.getDataType(e)){const Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Rt.OrDataTypeGroup,parent:$.toReference()},Q=V(Te,this.project);Q.setParent($,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),r.push(Q)}})}else{const k={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},W=V(k,this.project);W.setParent(S,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),$=W;const ee=C.getDataType(e);(((p=ee==null?void 0:ee.entity)==null?void 0:p.properties)||[]).forEach(Te=>{if(!Te.getDataType(e)){const se={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Rt.OrDataTypeGroup,parent:W.toReference()},Ht=V(se,this.project);Ht.setParent(W,e),Ht.initChildren(e),e==null||e.add(Ht,b.Added),Ht.addSelfToProject(e),r.push(Ht)}})}}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case K.String:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.String].body.inputs.currentValue.id});if(!this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.String].inputs.string.id}))break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U,e),t.push(w));let $=w.getDataType(e);if($){const k=this.project.getBuiltIn(F["primitive-entity"].string.id);((P=$.entity)==null?void 0:P.id)!==k.id&&($.setEntity(k),t.push($))}else{const k={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},W=V(k,this.project);W.setParent(S,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),r.push(W),$=W}}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:l,removed:c}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),r.push(...l),a.push(...c);const{updated:h,added:p,removed:v}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...h),r.push(...p),a.push(...v),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];switch(this.declaration.id){case K.List:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["list-loop"].inputs.list.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["list-loop"].inputs.list.id){const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),a.push(o)});break}case K.Counted:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["counted-loop"].inputs.number.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["counted-loop"].inputs.number.id){const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.ObjectKeys:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-keys-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-keys-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.ObjectValues:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-values-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-values-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.String:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["string-loop"].inputs.string.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["string-loop"].inputs.string.id){const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=F[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=F[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body"))){var c;const t=[],r=[],a=[],d=[],o=F[n.Loop][this.declaration.id].body.id,l=this.project.getBuiltIn(o);if(this.body)((c=this.body.implements)==null?void 0:c.id)!==l.id&&(this.body.setImplements(l,e),this.body.setParent(this,e),t.push(this.body));else{const h={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:l.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:l.toJSON(),x:0,y:0,parent:this.toReference()},p=V(h,this.project);p.initChildren(e),p.setParent(this,e),e==null||e.add(p,b.Added),p.addSelfToProject(e),r.push(p)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}syncChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-children"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncBody(e);t.push(...o),r.push(...l),a.push(...c);const{updated:h,added:p,removed:v}=this.syncInputMaps(e);t.push(...h),r.push(...p),a.push(...v);const{updated:E,added:P,removed:w}=this.syncTerminationStatements(e);t.push(...E),r.push(...P),a.push(...w);const{updated:C,added:U,removed:S}=this.syncBodyArgumentsDeclarations(e);t.push(...C),r.push(...U),a.push(...S);const{updated:B,added:$,removed:k}=this.syncBodyInputIndexes(e);t.push(...B),r.push(...$),a.push(...k);const{updated:W,added:ee,removed:ce}=this.syncOutputsDeclarations(e);t.push(...W),r.push(...ee),a.push(...ce);const{updated:Te,added:Q,removed:se}=this.syncOutputMaps(e);return t.push(...Te),r.push(...Q),a.push(...se),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}};f(ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(ae,"type",n.Loop),f(ae,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(ae,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),f(ae,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(ae,"CURRENT_VALUE_ARG_NAME","Current value"),f(ae,"MUTABLE_BASE_PROPERTIES",[]),f(ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ae,"BASE_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"MUTABLE_META_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,"x","y"]),f(ae,"INMUTABLE_META_PROPERTIES",[...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"META_PROPERTIES",[...ae.MUTABLE_META_PROPERTIES,...ae.INMUTABLE_META_PROPERTIES]),f(ae,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(ae,"UPSTREAM_PROPERTIES",[...ae.MUTABLE_UPSTREAM_PROPERTIES,...ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ae,"DOWNSTREAM_PROPERTIES",[...ae.MUTABLE_DOWNSTREAM_PROPERTIES,...ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ae,"PROPERTIES",[...ae.META_PROPERTIES,...ae.UPSTREAM_PROPERTIES,...ae.DOWNSTREAM_PROPERTIES]);let Ni=ae;function Q7(i){const s=Z6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(d=>d.validate());const a=[...fi(i)];return Ye(i.errors,a)}var Y1=(i=>(i.Parent="parent",i))(Y1||{});const Fe=class Fe extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const p=g(e.parent);r=t.get(p)}const a=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),d=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),o=e.calledByError.map(p=>{const v=g(p);return t.get(v)});let l;if(e.declaration){const p=g(e.declaration);l=t.get(p)}const c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Condition,declaration:l,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:r},h=V(c,t);return h.setParent(r,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new O({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ae(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ae(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncChildren(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const r=this.detachedChildren.indexOf(e);return r!==-1&&(this.detachedChildren[r]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=V(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ae.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ae.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.body.restore({},e),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(r=>r.toFlat(e)),...this.breakStatements.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(r=>r.toFlatIds(e)),...this.breakStatements.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),error:((r=this.error)==null?void 0:r.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:((c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(p=>p.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),error:((h=this.error)==null?void 0:h.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o,l;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((a=this.declaration)==null?void 0:a.toReference(e))||null,body:((d=this.body)==null?void 0:d.toReference(e))||null,inputs:this.inputs.map(c=>c.toReference(e)),outputs:this.outputs.map(c=>c.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(c=>c.toReference(e)),successCalls:this.successCalls.map(c=>c.toReference(e)),errorCalls:this.errorCalls.map(c=>c.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(c=>c.toReference(e)),calledByError:this.calledByError.map(c=>c.toReference(e)),calledByEntry:this.calledByEntry.map(c=>c.toReference(e)),error:((l=this.error)==null?void 0:l.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.body)==null?void 0:r.toFlatJSON(e))||[],...this.successCalls.flatMap(a=>a.toFlatJSON(e)),...this.errorCalls.flatMap(a=>a.toFlatJSON(e)),...this.inputs.flatMap(a=>a.toFlatJSON(e)),...this.outputs.flatMap(a=>a.toFlatJSON(e)),...this.continueStatements.flatMap(a=>a.toFlatJSON(e)),...this.breakStatements.flatMap(a=>a.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.body)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(a=>a.toFlatGenerationTarget(e)),...this.inputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.outputs.flatMap(a=>a.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(a=>a.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.continueStatements.forEach(r=>r.clearErrors()),this.breakStatements.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=K7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.body&&(p.body=this.body.clone(e,p,h+"-body-id",a,!0)),this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}getVariableInstances(){return this.body?We(this.body).filter(r=>r.type===n.VariableInstance):[]}addReturnStatement(e){return at.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return at.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(r=>{r.outputs.forEach(d=>{e.find(l=>l===d||G(l,this.project)===G(d,this.project)&&Ir(l.dataType,d.dataType))||e.push(d)})}),u(e)}syncTerminationStatements(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(c=>{const h=c.outputs,p=o.filter(v=>!h.find(E=>G(v,this.project)===G(E,this.project)&&Ir(v.dataType,E.dataType)));p.length&&(t.push(c),e==null||e.add(c,b.Updated)),p.forEach(v=>{const E=v.clone(e,c);e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],r=[],a=[],d=[];return this.body.inputs.sort((l,c)=>l.index-c.index),this.body.inputs.forEach((l,c)=>{l.index!==c&&(l.metaSync({index:c},e),t.push(l))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),r.push(...l),a.push(...c);const h=this.getUniqueReturnDeclarations(),p=this.body.inputs;h.sort((w,C)=>w.index-C.index),h.forEach(w=>{const C=w.getDataType(e);let S=p.find(ce=>G(ce,this.project)===ae.fromReturnDeclarationToBodyArgumentDeclarationName(w)&&Ir(ce.dataType,w.dataType));if(!S){const ce=ae.fromReturnDeclarationToBodyArgumentDeclarationName(w),Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ce,description:`Aggretated list of all previously outputted values from each iteration by the output '${G(w,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:w.index,required:w.required,parent:this.body.toReference(),writesValues:[]},Q=V(Te,this.project);Q.setParent(this.body,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),r.push(Q),S=Q}const B=this.body.inputs.find(ce=>ce.index===S.index&&ce!==S),$=this.body.inputs.filter(ce=>ce!==S);let k=S.index;B&&(k=Math.max(...$.map(ce=>ce.index))+1),S.index!==k&&(S.metaSync({index:k},e),t.push(S));const W=S.getDataType(e);let ee=W;if(C)if(!W||!Ir(W,C)){if(!ee){const Te=C.clone(e,S);e==null||e.add(Te,b.Added),Te.addSelfToProject(e),ee=Te,r.push(Te),t.push(S)}const ce=ee.merge(C,e);ce.self===ee?C.remove({ignoreUpstream:!1},e):ce.self===C&&(ee.remove({ignoreUpstream:!1},e),ee=C),ee.metaSync({isList:!0},e)}else ee.isList||(ee.metaSync({isList:!0},e),t.push(ee));if(!C&&!ee){const ce={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},Te=V(ce,this.project);Te.metaSync({isList:!0},e),Te.setParent(S,e),Te.initChildren(e),e==null||e.add(Te,b.Added),Te.addSelfToProject(e),r.push(Te)}});const{updated:v,added:E,removed:P}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...v),r.push(...E),a.push(...P),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],r=[],a=[],d=[],o=this.getUniqueReturnDeclarations(),l=this.outputsDeclarations;return o.forEach((h,p)=>{h.index!==p&&(h.metaSync({index:p},e),t.push(h))}),o.forEach(h=>{const p=h.getDataType(e);let E=l.find(C=>G(C,this.project)===ae.fromReturnDeclarationToLoopOutputDeclarationName(h)&&Ir(C.dataType,h.dataType));if(!E){const C=ae.fromReturnDeclarationToLoopOutputDeclarationName(h),U={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:C,description:`Aggretated list of all previously outputted values from each iteration by the output '${G(h,this.project)}'`,defaultValue:null,dataType:null,index:h.index,required:h.required,parentRelationType:_.FixedReturns,parent:this.toReference()},S=V(U,this.project);S.setParent(this,e),S.initChildren(e),e==null||e.add(S,b.Added),S.addSelfToProject(e),r.push(S),E=S}E.index!==h.index&&(E.metaSync({index:h.index},e),t.push(E));let w=E.getDataType(e);if(p)if(!w||!Ir(w,p)){if(!w){const U=p.clone(e,E);e==null||e.add(U,b.Added),U.addSelfToProject(e),w=U,r.push(U),t.push(E)}const C=w.merge(p,e);C.self===w?p.remove({ignoreUpstream:!1},e):C.self===p&&(w.remove({ignoreUpstream:!1},e),w=p),w.metaSync({isList:!0},e)}else w.isList||(w.metaSync({isList:!0},e),t.push(w));if(!p&&!w){const C={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:E.toReference()},U=V(C,this.project);U.metaSync({isList:!0},e),U.setParent(E,e),U.initChildren(e),e==null||e.add(U,b.Added),U.addSelfToProject(e),r.push(U)}}),l.filter(h=>!o.find(v=>G(h,this.project)===ae.fromReturnDeclarationToLoopOutputDeclarationName(v))).forEach(h=>{const{updated:p,removed:v}=h.remove({ignoreUpstream:!1},e);t.push(...p),a.push(...v)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncOutputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.outputsDeclarations,l=this.outputs;return o.forEach(h=>{var E;let v=l.find(P=>{var w,C;return((w=P.declaration)==null?void 0:w.id)===h.id&&Ir((C=P.declaration)==null?void 0:C.dataType,h.dataType)});if(v)((E=v.declaration)==null?void 0:E.id)!==h.id&&(v.setDeclaration(h),t.push(v));else{const P={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:h.index,declaration:h.toJSON(),writesValues:[],parent:this.toReference()},w=V(P,this.project);w.setParent(this,e),w.initChildren(e),e==null||e.add(w,b.Added),w.addSelfToProject(e),r.push(w),v=w}v.index!==h.index&&(v.metaSync({index:h.index},e),t.push(v))}),l.filter(h=>!o.find(v=>{var E;return((E=h.declaration)==null?void 0:E.id)===v.id})).forEach(h=>{const{updated:p,removed:v}=h.remove({ignoreUpstream:!1},e);t.push(...p),a.push(...v)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],r=[],a=[],d=[];let l=this.body.inputs.find(v=>{var E;return v.name===ae.CURRENT_ITERATION_NUMBER_ARG_NAME||v.id===((E=this.currentIterationNumberArgumentDeclaration)==null?void 0:E.id)});const c=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!l){const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:c==null?void 0:c.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},E=V(v,this.project);E.setParent(this.body,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),l=E}!l.index&&l.index!==0&&(l.metaSync({index:0},e),t.push(l)),(!l.implements||l.implements.id!==c.id)&&(l.setImplements(c,e),t.push(l));let p=l.getDataType(e);if(!p){const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:l.toReference()},E=V(v,this.project);E.setParent(l,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E),p=E}if(!p.entity||p.entity.type!==n.PrimitiveEntity||p.entity.name!==M.Number||p.entity.id!==F["primitive-entity"].number.id){const v=this.project.getBuiltIn(F["primitive-entity"].number.id);p.setEntity(v),t.push(p)}return this.currentIterationNumberArgumentDeclaration=l,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],r=[],a=[],d=[],o=this.body.inputs,l=this.getUniqueReturnDeclarations();return o.filter(h=>h===this.currentIterationNumberArgumentDeclaration||h===this.currentValueArgumentDeclaration?!1:!l.find(v=>G(h,this.project)===ae.fromReturnDeclarationToBodyArgumentDeclarationName(v))).forEach(h=>{const{updated:p,removed:v}=h.remove({ignoreUpstream:!1},e);t.push(...p),a.push(...v)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var h,p,v,E,P;const t=[],r=[],a=[],d=[];switch(this.declaration.id){case K.List:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.List].body.inputs.currentValue.id}),C=this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.List].inputs.list.id});if(!C)break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop][K.List].inputs.list.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U,e),t.push(w));let $=w.getDataType(e);if(!$){const W={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},ee=V(W,this.project);ee.setParent(S,e),ee.initChildren(e),e==null||e.add(ee,b.Added),ee.addSelfToProject(e),r.push(ee),$=ee}const k=C.getDataType(e);$.merge(k,e),$.metaSync({isList:!1},e)}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case K.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case K.Counted:{this.currentValueArgumentDeclaration=null;break}case K.ObjectKeys:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.ObjectKeys].inputs.object.id}))break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop][K.ObjectKeys].inputs.object.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U),t.push(w));let $=w.getDataType(e);if($){const k=this.project.getBuiltIn(F["primitive-entity"].string.id);((h=$.entity)==null?void 0:h.id)!==k.id&&($.setEntity(k),t.push($))}else{const k={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},W=V(k,this.project);W.setParent(S,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),$=W}}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case K.ObjectValues:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.ObjectValues].body.inputs.currentValue.id}),C=this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.ObjectValues].inputs.object.id});if(!C)break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop][K.ObjectValues].inputs.object.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U,e),t.push(w));let $=w.getDataType(e);if($){const k=C.getDataType(e),W=((v=k==null?void 0:k.entity)==null?void 0:v.properties)||[];(E=$.orChildrenGroup)==null||E.forEach(ee=>{const{updated:ce,removed:Te}=ee.remove({ignoreUpstream:!1},e);t.push(...ce),a.push(...Te)}),W.forEach(ee=>{if(!ee.getDataType(e)){const Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Rt.OrDataTypeGroup,parent:$.toReference()},Q=V(Te,this.project);Q.setParent($,e),Q.initChildren(e),e==null||e.add(Q,b.Added),Q.addSelfToProject(e),r.push(Q)}})}else{const k={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},W=V(k,this.project);W.setParent(S,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),$=W;const ee=C.getDataType(e);(((p=ee==null?void 0:ee.entity)==null?void 0:p.properties)||[]).forEach(Te=>{if(!Te.getDataType(e)){const se={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Rt.OrDataTypeGroup,parent:W.toReference()},Ht=V(se,this.project);Ht.setParent(W,e),Ht.initChildren(e),e==null||e.add(Ht,b.Added),Ht.addSelfToProject(e),r.push(Ht)}})}}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}case K.String:{const w=this.body.inputs.find(S=>{var B;return((B=S.implements)==null?void 0:B.id)===F[n.Loop][K.String].body.inputs.currentValue.id});if(!this.inputs.find(S=>{var B;return((B=S.declaration)==null?void 0:B.id)===F[n.Loop][K.String].inputs.string.id}))break;const U=this.getCurrentValueBuiltInValueDescriptor();if(w){this.currentValueArgumentDeclaration=w;const S=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);U&&(!w.implements||w.implements.id!==U.id)&&(w.setImplements(U,e),t.push(w));let $=w.getDataType(e);if($){const k=this.project.getBuiltIn(F["primitive-entity"].string.id);((P=$.entity)==null?void 0:P.id)!==k.id&&($.setEntity(k),t.push($))}else{const k={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:S.toReference()},W=V(k,this.project);W.setParent(S,e),W.initChildren(e),e==null||e.add(W,b.Added),W.addSelfToProject(e),r.push(W),$=W}}else{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:ae.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:U,writesValues:[],dataType:null,parent:this.body.toReference()},B=V(S,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,b.Added),B.addSelfToProject(e),U&&(!B.implements||B.implements.id!==U.id)&&(B.setImplements(U,e),t.push(B)),r.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:l,removed:c}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),r.push(...l),a.push(...c);const{updated:h,added:p,removed:v}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...h),r.push(...p),a.push(...v),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];switch(this.declaration.id){case K.List:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["list-loop"].inputs.list.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["list-loop"].inputs.list.id){const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["list-loop"].inputs.list.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),a.push(o)});break}case K.Counted:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["counted-loop"].inputs.number.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["counted-loop"].inputs.number.id){const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["counted-loop"].inputs.number.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.ObjectKeys:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-keys-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-keys-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-keys-loop"].inputs.object.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.ObjectValues:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["object-values-loop"].inputs.object.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["object-values-loop"].inputs.object.id){const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["object-values-loop"].inputs.object.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}case K.String:{let o=null;if(this.inputs.forEach(l=>{var c;((c=l.declaration)==null?void 0:c.id)===F[n.Loop]["string-loop"].inputs.string.id?o=l:(l.remove({ignoreUpstream:!1},e),a.push(l))}),o){if(o.declaration.id!==F[n.Loop]["string-loop"].inputs.string.id){const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(l),t.push(o)}}else{const l=this.project.get(F[n.Loop]["string-loop"].inputs.string.id),c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:l.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},h=V(c,this.project);h.initChildren(e),h.setParent(this,e),e==null||e.add(h,b.Added),h.addSelfToProject(e),r.push(h)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=F[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=F[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-body"))){var c;const t=[],r=[],a=[],d=[],o=F[n.Loop][this.declaration.id].body.id,l=this.project.getBuiltIn(o);if(this.body)((c=this.body.implements)==null?void 0:c.id)!==l.id&&(this.body.setImplements(l,e),this.body.setParent(this,e),t.push(this.body));else{const h={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:l.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:l.toJSON(),x:0,y:0,parent:this.toReference()},p=V(h,this.project);p.initChildren(e),p.setParent(this,e),e==null||e.add(p,b.Added),p.addSelfToProject(e),r.push(p)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}syncChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-children"))){const t=[],r=[],a=[],d=[],{updated:o,added:l,removed:c}=this.syncBody(e);t.push(...o),r.push(...l),a.push(...c);const{updated:h,added:p,removed:v}=this.syncInputMaps(e);t.push(...h),r.push(...p),a.push(...v);const{updated:E,added:P,removed:w}=this.syncTerminationStatements(e);t.push(...E),r.push(...P),a.push(...w);const{updated:C,added:U,removed:S}=this.syncBodyArgumentsDeclarations(e);t.push(...C),r.push(...U),a.push(...S);const{updated:B,added:$,removed:k}=this.syncBodyInputIndexes(e);t.push(...B),r.push(...$),a.push(...k);const{updated:W,added:ee,removed:ce}=this.syncOutputsDeclarations(e);t.push(...W),r.push(...ee),a.push(...ce);const{updated:Te,added:Q,removed:se}=this.syncOutputMaps(e);return t.push(...Te),r.push(...Q),a.push(...se),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:u(t),added:u(r),removed:u(a),affected:u(d)}}};f(ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(ae,"type",n.Loop),f(ae,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(ae,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),f(ae,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(ae,"CURRENT_VALUE_ARG_NAME","Current value"),f(ae,"MUTABLE_BASE_PROPERTIES",[]),f(ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ae,"BASE_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"MUTABLE_META_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,"x","y"]),f(ae,"INMUTABLE_META_PROPERTIES",[...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"META_PROPERTIES",[...ae.MUTABLE_META_PROPERTIES,...ae.INMUTABLE_META_PROPERTIES]),f(ae,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(ae,"UPSTREAM_PROPERTIES",[...ae.MUTABLE_UPSTREAM_PROPERTIES,...ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ae,"DOWNSTREAM_PROPERTIES",[...ae.MUTABLE_DOWNSTREAM_PROPERTIES,...ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ae,"PROPERTIES",[...ae.META_PROPERTIES,...ae.UPSTREAM_PROPERTIES,...ae.DOWNSTREAM_PROPERTIES]);let Ni=ae;function Q7(i){const s=Z6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(d=>d.validate());const a=[...fi(i)];return Ye(i.errors,a)}var Y1=(i=>(i.Parent="parent",i))(Y1||{});const Fe=class Fe extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const p=g(e.parent);r=t.get(p)}const a=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),d=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),o=e.calledByError.map(p=>{const v=g(p);return t.get(v)});let l;if(e.declaration){const p=g(e.declaration);l=t.get(p)}const c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Condition,declaration:l,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:r},h=V(c,t);return h.setParent(r,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(c=>c.id===e.declaration)||a.push(new O({id:`${e.id}--${I.InvalidImplementsReference}`,code:I.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
|
${Gd(t)}`,issue:null})):a.push(new O({id:`${e.id}--${I.ReferencedEntityNotFound}`,code:I.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
|
${Gd(t)}`,issue:null})):a.push(new O({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.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
|
${Gd(t)}`,issue:null})),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Fe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Fe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=Q7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.inputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-input-map-"+w+"-id",a));return p.inputs=v,e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!0},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>p.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>v.declaration.id===p.id));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1})});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(Fe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Fe,"type",n.Condition),f(Fe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),f(Fe,"MUTABLE_BASE_PROPERTIES",["operator"]),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",["successCalls","errorCalls","inputsDeclarations","inputs"]),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 Li=Fe;function eq(i){var o;const s=C3(),e=i.toJSON();s.safeParse(e).success,(o=i.dataType)==null||o.validate(),i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),i.internalCalls.forEach(l=>l.validate());const a=[...fi(i)];if(i.id==="random-company-employee-test-variable-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}if(i.id==="company-dto-variable-one-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}function tq(i){const s=N3(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),i.internalCalls.forEach(o=>o.validate());const a=[...fi(i)];if(i.id==="exec-sequentially-result-variable-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}var Tp=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i.VarDeclaration="var-declaration",i))(Tp||{});const we=class we extends rt{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);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const E=g(e.parent);r=t.get(E)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(E=>{const P=g(E);return t.get(P)}),l=e.calledBySuccess.map(E=>{const P=g(E);return t.get(P)}),c=e.calledByError.map(E=>{const P=g(E);return t.get(P)});let h=null;if(e.readsValue){const E=g(e.readsValue);h=t.get(E)}const p={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:d.toReference(),calledByEntry:o,calledBySuccess:l,calledByError:c,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:h,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},v=V(p,t);return v.setParent(r,null),v.initChildren(null),v}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${Wt(this.type)} with id '${this.id}' has a parent reference "${d}" which is missing in the project`)}else throw new Error(`${Wt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Fe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Fe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(r=>r.toFlat(e)),...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=Q7(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(E=this.inputs)==null?void 0:E.map((P,w)=>P.clone(e,p,h+"-input-map-"+w+"-id",a));return p.inputs=v,e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!0},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>p.parentRelationType===_.FixedArguments&&!this.inputs.find(v=>v.declaration.id===p.id));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1})});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};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,...r)=>null}),f(Fe,"type",n.Condition),f(Fe,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),f(Fe,"MUTABLE_BASE_PROPERTIES",["operator"]),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",["successCalls","errorCalls","inputsDeclarations","inputs"]),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 Li=Fe;function eq(i){var o;const s=C3(),e=i.toJSON();s.safeParse(e).success,(o=i.dataType)==null||o.validate(),i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),i.internalCalls.forEach(l=>l.validate());const a=[...fi(i)];if(i.id==="random-company-employee-test-variable-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}if(i.id==="company-dto-variable-one-id"){const l=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(l.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}function tq(i){const s=N3(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),i.internalCalls.forEach(o=>o.validate());const a=[...fi(i)];if(i.id==="exec-sequentially-result-variable-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}const d=Vp(i);return a.push(...d),Ye(i.errors,a)}var Tp=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i.VarDeclaration="var-declaration",i))(Tp||{});const we=class we extends rt{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);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const E=g(e.parent);r=t.get(E)}const a=g(e.declaration),d=t.get(a),o=e.calledByEntry.map(E=>{const P=g(E);return t.get(P)}),l=e.calledBySuccess.map(E=>{const P=g(E);return t.get(P)}),c=e.calledByError.map(E=>{const P=g(E);return t.get(P)});let h=null;if(e.readsValue){const E=g(e.readsValue);h=t.get(E)}const p={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:d.toReference(),calledByEntry:o,calledBySuccess:l,calledByError:c,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:h,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},v=V(p,t);return v.setParent(r,null),v.initChildren(null),v}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="var-declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="var-declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new we(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...h);const{added:p,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...p),t.push(...v),a.push(...E),d.push(...P);const{added:w,updated:C,removed:U,affected:S}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...S),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:$,updated:k,removed:W,affected:ee}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...$),t.push(...k),a.push(...W),d.push(...ee)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(r=>!(e.find(o=>o.id===r.id)||e.find(o=>o.declaration===r.declaration)))}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(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=V(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return Ms.initWritesValues(this,this.parent),yi.initReadsValue(this),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.internalCalls=this.initialData.internalCalls.reduce((t,r)=>{if(r.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(r);if(!a)return t;const d=a;return d.setParent(this,null),[...t,d]}else{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(e),[...t,a]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await we.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await we.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...this.successCalls.flatMap(d=>d.toFlat(e)),...this.errorCalls.flatMap(d=>d.toFlat(e)),...this.inputs.flatMap(d=>d.toFlat(e)),...this.outputs.flatMap(d=>d.toFlat(e)),...this.internalCalls.flatMap(d=>d.toFlat(e))])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(a=>a.toFlatIds(e)),...this.successCalls.flatMap(a=>a.toFlatIds(e)),...this.errorCalls.flatMap(a=>a.toFlatIds(e)),...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.outputs.flatMap(a=>a.toFlatIds(e)),...this.internalCalls.flatMap(a=>a.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((r=this.readsValue)==null?void 0:r.toReference())||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),internalCalls:this.internalCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((h=this.readsValue)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(p=>p.toJSONClone({...e,newId:null})),inputs:[],outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(p=>this.calledBy.length||this.readsValue?p.toJSONClone({...e,newId:null}):p.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.declaration)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e)),...this.calledBy.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.declaration)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.readsValue)==null?void 0:d.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=tq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(a=>a.getErrors()),...this.internalCalls.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...((r=this.readsValue)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w,C,U;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[],o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(P=this.defaultValue)==null?void 0:P.clone(e,c,R.UUID.uuid(),a);c.defaultValue=h||null;const p=(w=this.inputs)==null?void 0:w.map(S=>S.clone(e,c,R.UUID.uuid(),a));c.inputs=p;const v=(C=this.outputs)==null?void 0:C.map(S=>S.clone(e,c,R.UUID.uuid(),a));c.outputs=v;const E=(U=this.internalCalls)==null?void 0:U.map(S=>S.clone(e,c,R.UUID.uuid(),a));return c.internalCalls=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(p=>!p.getDataType(e)).forEach(p=>{const v=this.inputs.find(w=>G(w,this.project)===G(p,this.project));if(!v)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);p.setDataType(P),v.setDeclaration(p)}),o.filter(p=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id})).forEach(p=>{const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:p,defaultValue:null,index:p.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(p=>!p.declaration).forEach(p=>{const v=o.find(E=>G(E,this.project)===G(p,this.project));v&&p.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(c=>!this.outputs.find(h=>h.declaration===c)).map(c=>{const h={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:c,index:c.index,writesValues:[]},p=V(h,this.project);return p.setParent(this,e),p.initChildren(e),e==null||e.add(p,b.Added),p.suggestion=!0,this.addOutput(p),p});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(p=>{var E,P,w,C,U;return(((E=p.declaration)==null?void 0:E.id)||((w=(P=p.initialData)==null?void 0:P.declaration)==null?void 0:w.entityId)||((U=(C=p.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===c.id})).map(c=>{const h=c.createInternalCall(this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}getDataType(e=this.project.addChangeSet(new A(this.project,"",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(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(we,"type",n.VariableInstance),f(we,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),f(we,"MUTABLE_BASE_PROPERTIES",[]),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","readsValue"]),f(we,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),f(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Ui=we;var z1=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i))(z1||{});const Ve=class Ve extends rt{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);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const p=g(e.parent);r=t.get(p)}const a=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),d=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),o=e.calledByError.map(p=>{const v=g(p);return t.get(v)});let l=null;if(e.readsValue){const p=g(e.readsValue);l=t.get(p)}const c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:d,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:l,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},h=V(c,t);return h.setParent(r,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData;const o=up(r,t);return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Tp.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="var-declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="var-declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new we(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...h);const{added:p,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...p),t.push(...v),a.push(...E),d.push(...P);const{added:w,updated:C,removed:U,affected:S}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...S),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:$,updated:k,removed:W,affected:ee}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...$),t.push(...k),a.push(...W),d.push(...ee)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(r=>!(e.find(o=>o.id===r.id)||e.find(o=>o.declaration===r.declaration)))}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(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=V(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return Ms.initWritesValues(this,this.parent),yi.initReadsValue(this),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.internalCalls=this.initialData.internalCalls.reduce((t,r)=>{if(r.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(r);if(!a)return t;const d=a;return d.setParent(this,null),[...t,d]}else{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(e),[...t,a]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await we.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await we.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.readsValue)==null?void 0:a.toFlat(e))||[],...this.successCalls.flatMap(d=>d.toFlat(e)),...this.errorCalls.flatMap(d=>d.toFlat(e)),...this.inputs.flatMap(d=>d.toFlat(e)),...this.outputs.flatMap(d=>d.toFlat(e)),...this.internalCalls.flatMap(d=>d.toFlat(e))])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(a=>a.toFlatIds(e)),...this.successCalls.flatMap(a=>a.toFlatIds(e)),...this.errorCalls.flatMap(a=>a.toFlatIds(e)),...this.inputs.flatMap(a=>a.toFlatIds(e)),...this.outputs.flatMap(a=>a.toFlatIds(e)),...this.internalCalls.flatMap(a=>a.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((r=this.readsValue)==null?void 0:r.toReference())||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),internalCalls:this.internalCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((h=this.readsValue)==null?void 0:h.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(p=>p.toJSONClone({...e,newId:null})),inputs:[],outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(p=>this.calledBy.length||this.readsValue?p.toJSONClone({...e,newId:null}):p.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.declaration)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e)),...this.calledBy.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.declaration)==null?void 0:a.toFlatGenerationTarget(e))||[],...((d=this.readsValue)==null?void 0:d.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=tq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(a=>a.getErrors()),...this.internalCalls.flatMap(a=>a.getErrors()),...this.outputs.flatMap(a=>a.getErrors()),...((r=this.readsValue)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w,C,U;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[],o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(P=this.defaultValue)==null?void 0:P.clone(e,c,R.UUID.uuid(),a);c.defaultValue=h||null;const p=(w=this.inputs)==null?void 0:w.map(S=>S.clone(e,c,R.UUID.uuid(),a));c.inputs=p;const v=(C=this.outputs)==null?void 0:C.map(S=>S.clone(e,c,R.UUID.uuid(),a));c.outputs=v;const E=(U=this.internalCalls)==null?void 0:U.map(S=>S.clone(e,c,R.UUID.uuid(),a));return c.internalCalls=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(p=>!p.getDataType(e)).forEach(p=>{const v=this.inputs.find(w=>G(w,this.project)===G(p,this.project));if(!v)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);p.setDataType(P),v.setDeclaration(p)}),o.filter(p=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id})).forEach(p=>{const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:p,defaultValue:null,index:p.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(p=>!p.declaration).forEach(p=>{const v=o.find(E=>G(E,this.project)===G(p,this.project));v&&p.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(c=>!this.outputs.find(h=>h.declaration===c)).map(c=>{const h={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:c,index:c.index,writesValues:[]},p=V(h,this.project);return p.setParent(this,e),p.initChildren(e),e==null||e.add(p,b.Added),p.suggestion=!0,this.addOutput(p),p});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(p=>{var E,P,w,C,U;return(((E=p.declaration)==null?void 0:E.id)||((w=(P=p.initialData)==null?void 0:P.declaration)==null?void 0:w.entityId)||((U=(C=p.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===c.id})).map(c=>{const h=c.createInternalCall(this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}getDataType(e=this.project.addChangeSet(new A(this.project,"",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(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,...r)=>null}),f(we,"type",n.VariableInstance),f(we,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),f(we,"MUTABLE_BASE_PROPERTIES",[]),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","readsValue"]),f(we,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),f(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Ui=we;var z1=(i=>(i.Parent="parent",i.DataTypeEntity="data-type-entity",i))(z1||{});const Ve=class Ve extends rt{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);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static fromGenerationTarget(e,t){let r=t;if(e.parent){const p=g(e.parent);r=t.get(p)}const a=e.calledByEntry.map(p=>{const v=g(p);return t.get(v)}),d=e.calledBySuccess.map(p=>{const v=g(p);return t.get(v)}),o=e.calledByError.map(p=>{const v=g(p);return t.get(v)});let l=null;if(e.readsValue){const p=g(e.readsValue);l=t.get(p)}const c={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:a,calledBySuccess:d,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:l,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:r},h=V(c,t);return h.setParent(r,null),h.initChildren(null),h}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);r=d.modifiedData;const o=up(r,t);return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Tp.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...h);const{added:p,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...p),t.push(...v),a.push(...E),d.push(...P);const{added:w,updated:C,removed:U,affected:S}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...S),!this.dataType||this.dataType.inferred){const{added:B,updated:$,removed:k,affected:W}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...B),t.push(...$),a.push(...k),d.push(...W)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),Ms.initWritesValues(this,this.parent),yi.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(t);if(!a)return;a.setParent(this,null),a.initChildren(e),this.addInternalCall(a);return}const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInternalCall(r),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return u([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>G(a,this.project)===G(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var U,S,B,$;const t=[],r=[],a=[],d=[];if(!this.dataType){const k=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(k),k.setParent(this,e),k.initChildren(e),e==null||e.add(k,b.Added),k.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const k=(U=this.readsValue.getDataType(e))==null?void 0:U.clone(e);if(k){const W=(S=this.dataType)==null?void 0:S.merge(k,e);this.dataType&&(W==null?void 0:W.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),k.id!==((B=W==null?void 0:W.self)==null?void 0:B.id)&&k.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:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}const o=u([...this.inputs,...this.variableInstances.flatMap(k=>k.inputs)]),l=[];if(o.forEach(k=>{l.find(ee=>G(ee,this.project)===G(k,this.project))||l.push(k)}),!l.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};if(($=this.dataType)==null||$.inferFromInputs(l,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};const{updated:c,added:h,removed:p,affected:v}=this.generateUnusedInputs(e);t.push(...h),r.push(...c),a.push(...p),d.push(...v);const{updated:E,added:P,removed:w,affected:C}=this.generateUnusedOutputs(e);return t.push(...P),r.push(...E),a.push(...w),d.push(...C),this.variableInstances.forEach(k=>{const{updated:W,added:ee,removed:ce,affected:Te}=k.generateUnusedInputs(e);t.push(...ee),r.push(...W),a.push(...ce),d.push(...Te);const{updated:Q,added:se,removed:Ht,affected:zr}=k.generateUnusedOutputs(e);t.push(...se),r.push(...Q),a.push(...Ht),d.push(...zr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ve.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ve.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...((d=this.readsValue)==null?void 0:d.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.successCalls.flatMap(d=>d.toFlatIds(e)),...this.errorCalls.flatMap(d=>d.toFlatIds(e)),...this.inputs.flatMap(d=>d.toFlatIds(e)),...this.outputs.flatMap(d=>d.toFlatIds(e)),...this.internalCalls.flatMap(d=>d.toFlatIds(e))])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),inputs:this.inputs.map(d=>d.toJSON(e)),outputs:this.outputs.map(d=>d.toJSON(e)),successCalls:this.successCalls.map(d=>d.toJSON(e)),errorCalls:this.errorCalls.map(d=>d.toJSON(e)),internalCalls:this.internalCalls.map(d=>d.toJSON(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference()),calledByError:this.calledByError.map(d=>d.toReference()),calledByEntry:this.calledByEntry.map(d=>d.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,readsValue:((p=this.readsValue)==null?void 0:p.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.successCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.inputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.outputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(d=>d.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.internalCalls.forEach(r=>r.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=eq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[],...this.inputs.flatMap(d=>d.getErrors()),...this.internalCalls.flatMap(d=>d.getErrors()),...this.outputs.flatMap(d=>d.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C,U,S,B;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[],o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(w=this.dataType)==null?void 0:w.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(C=this.defaultValue)==null?void 0:C.clone(e,c,R.UUID.uuid(),a);c.defaultValue=p||null;const v=(U=this.inputs)==null?void 0:U.map($=>$.clone(e,c,R.UUID.uuid(),a));c.inputs=v;const E=(S=this.outputs)==null?void 0:S.map($=>$.clone(e,c,R.UUID.uuid(),a));c.outputs=E;const P=(B=this.internalCalls)==null?void 0:B.map($=>$.clone(e,c,R.UUID.uuid(),a));return c.internalCalls=P,e==null||e.attemptAutoclose("clone-entity",this.id),c}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t={}){const r={id:t.id||R.UUID.uuid(),version:t.version||"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:t.defaultValue||null,successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],writesValues:t.writesValues||[],internalCalls:t.internalCalls||[],readsValue:t.readsValue||null,calledByEntry:t.calledByEntry||[],calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],declaration:this.toJSON(),x:0,y:0},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addVariableInstance(a),a}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(p=>!p.getDataType(e)).forEach(p=>{const v=this.inputs.find(w=>G(w,this.project)===G(p,this.project));if(!v)return;const E=this.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);p.setDataType(P),v.setDeclaration(p)}),o.filter(p=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id})).forEach(p=>{const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:p,defaultValue:null,index:p.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(p=>!p.declaration).forEach(p=>{const v=o.find(E=>G(E,this.project)===G(p,this.project));v&&p.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(c=>!this.outputs.find(h=>h.declaration===c)).map(c=>{const h={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:c,index:c.index,writesValues:[]},p=V(h,this.project);return p.setParent(this,e),p.initChildren(e),e==null||e.add(p,b.Added),p.suggestion=!0,this.addOutput(p),p});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(p=>{var E,P,w,C,U;return(((E=p.declaration)==null?void 0:E.id)||((w=(P=p.initialData)==null?void 0:P.declaration)==null?void 0:w.entityId)||((U=(C=p.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===c.id})).map(c=>{const h=c.createInternalCall(this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,"",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)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),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 ji=Ve;function rq(i){var d;const s=Y6(),e=i.toJSON();s.safeParse(e).success,i.inputsDeclarations.forEach(o=>o.validate()),i.inputs.forEach(o=>o.validate()),i.outputsDeclarations.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),(d=i.error)==null||d.validate();const a=[...fi(i)];if(i.id==="search-person-by-id-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return Ye(i.errors,a)}var H1=(i=>(i.Parent="parent",i))(H1||{});const Ze=class Ze extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const h=g(e.parent);r=t.get(h)}const a=e.calledByEntry.map(h=>{const p=g(h);return t.get(p)}),d=e.calledBySuccess.map(h=>{const p=g(h);return t.get(p)}),o=e.calledByError.map(h=>{const p=g(h);return t.get(p)}),l={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:r},c=V(l,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(a=(r=(t=this.dataType)==null?void 0:t.entity)==null?void 0:r.subscribeDependents)==null||a.call(r,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{added:o,updated:l,removed:c,affected:h}=this.generateUnusedInputs(e);r.push(...o),t.push(...l),a.push(...c),d.push(...h);const{added:p,updated:v,removed:E,affected:P}=this.generateUnusedOutputs(e);r.push(...p),t.push(...v),a.push(...E),d.push(...P);const{added:w,updated:C,removed:U,affected:S}=this.generateUnusedInternalCalls(e);if(r.push(...w),t.push(...C),a.push(...U),d.push(...S),!this.dataType||this.dataType.inferred){const{added:B,updated:$,removed:k,affected:W}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);r.push(...B),t.push(...$),a.push(...k),d.push(...W)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),Ms.initWritesValues(this,this.parent),yi.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.initialData.inputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInput(r),r}),this.initialData.outputs.forEach(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addOutput(r),r}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedInstanceFromReference(t);if(!a)return;a.setParent(this,null),a.initChildren(e),this.addInternalCall(a);return}const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),this.addInternalCall(r),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return u([...this.inputs,...this.variableInstances.flatMap(a=>a.inputs)]).find(a=>G(a,this.project)===G(e,this.project)&&!!a.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var U,S,B,$;const t=[],r=[],a=[],d=[];if(!this.dataType){const k=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(k),k.setParent(this,e),k.initChildren(e),e==null||e.add(k,b.Added),k.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const k=(U=this.readsValue.getDataType(e))==null?void 0:U.clone(e);if(k){const W=(S=this.dataType)==null?void 0:S.merge(k,e);this.dataType&&(W==null?void 0:W.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),k.id!==((B=W==null?void 0:W.self)==null?void 0:B.id)&&k.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:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}const o=u([...this.inputs,...this.variableInstances.flatMap(k=>k.inputs)]),l=[];if(o.forEach(k=>{l.find(ee=>G(ee,this.project)===G(k,this.project))||l.push(k)}),!l.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};if(($=this.dataType)==null||$.inferFromInputs(l,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this};const{updated:c,added:h,removed:p,affected:v}=this.generateUnusedInputs(e);t.push(...h),r.push(...c),a.push(...p),d.push(...v);const{updated:E,added:P,removed:w,affected:C}=this.generateUnusedOutputs(e);return t.push(...P),r.push(...E),a.push(...w),d.push(...C),this.variableInstances.forEach(k=>{const{updated:W,added:ee,removed:ce,affected:Te}=k.generateUnusedInputs(e);t.push(...ee),r.push(...W),a.push(...ce),d.push(...Te);const{updated:Q,added:se,removed:Ht,affected:zr}=k.generateUnusedOutputs(e);t.push(...se),r.push(...Q),a.push(...Ht),d.push(...zr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:u(r),added:u(t),removed:u(a),affected:u(d),self:this}}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,this.constant=e.constant!==void 0?e.constant:this.constant,this.required=e.required!==void 0?e.required:this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ve.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.internalCalls.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.dataType){const{updated:l,removed:c}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.internalCalls.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a,d;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...((d=this.readsValue)==null?void 0:d.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.successCalls.flatMap(d=>d.toFlatIds(e)),...this.errorCalls.flatMap(d=>d.toFlatIds(e)),...this.inputs.flatMap(d=>d.toFlatIds(e)),...this.outputs.flatMap(d=>d.toFlatIds(e)),...this.internalCalls.flatMap(d=>d.toFlatIds(e))])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),inputs:this.inputs.map(d=>d.toJSON(e)),outputs:this.outputs.map(d=>d.toJSON(e)),successCalls:this.successCalls.map(d=>d.toJSON(e)),errorCalls:this.errorCalls.map(d=>d.toJSON(e)),internalCalls:this.internalCalls.map(d=>d.toJSON(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference()),calledByError:this.calledByError.map(d=>d.toReference()),calledByEntry:this.calledByEntry.map(d=>d.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,readsValue:((p=this.readsValue)==null?void 0:p.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),inputs:this.inputs.map(v=>v.toJSONClone({...e,newId:null})),outputs:this.outputs.map(v=>v.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(v=>v.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(v=>v.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(v=>this.calledBy.length||this.readsValue?v.toJSONClone({...e,newId:null}):v.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(v=>v.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),inputs:this.inputs.map(l=>l.toReference(e)),outputs:this.outputs.map(l=>l.toReference(e)),successCalls:this.successCalls.map(l=>l.toReference(e)),errorCalls:this.errorCalls.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),internalCalls:this.internalCalls.map(l=>l.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.successCalls.flatMap(d=>d.toFlatJSON(e)),...this.errorCalls.flatMap(d=>d.toFlatJSON(e)),...this.inputs.flatMap(d=>d.toFlatJSON(e)),...this.outputs.flatMap(d=>d.toFlatJSON(e)),...this.internalCalls.flatMap(d=>d.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.successCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(d=>d.toFlatGenerationTarget(e)),...this.inputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.outputs.flatMap(d=>d.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(d=>d.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),this.internalCalls.forEach(r=>r.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=eq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r,a;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[],...this.inputs.flatMap(d=>d.getErrors()),...this.internalCalls.flatMap(d=>d.getErrors()),...this.outputs.flatMap(d=>d.getErrors()),...((a=this.readsValue)==null?void 0:a.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C,U,S,B;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[],o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(w=this.dataType)==null?void 0:w.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(C=this.defaultValue)==null?void 0:C.clone(e,c,R.UUID.uuid(),a);c.defaultValue=p||null;const v=(U=this.inputs)==null?void 0:U.map($=>$.clone(e,c,R.UUID.uuid(),a));c.inputs=v;const E=(S=this.outputs)==null?void 0:S.map($=>$.clone(e,c,R.UUID.uuid(),a));c.outputs=E;const P=(B=this.internalCalls)==null?void 0:B.map($=>$.clone(e,c,R.UUID.uuid(),a));return c.internalCalls=P,e==null||e.attemptAutoclose("clone-entity",this.id),c}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t={}){const r={id:t.id||R.UUID.uuid(),version:t.version||"1",createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:t.defaultValue||null,successCalls:t.successCalls||[],errorCalls:t.errorCalls||[],inputs:t.inputs||[],outputs:t.outputs||[],writesValues:t.writesValues||[],internalCalls:t.internalCalls||[],readsValue:t.readsValue||null,calledByEntry:t.calledByEntry||[],calledBySuccess:t.calledBySuccess||[],calledByError:t.calledByError||[],declaration:this.toJSON(),x:0,y:0},a=V(r,this.project);return a.setParent(e,null),a.initChildren(null),e===this.project&&this.project.addVariableInstance(a),a}generateUnusedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(p=>!p.getDataType(e)).forEach(p=>{const v=this.inputs.find(w=>G(w,this.project)===G(p,this.project));if(!v)return;const E=this.getMasterInputWithValueWritterFromAllInstances(v);if(!E)return;const P=xr(E);p.setDataType(P),v.setDeclaration(p)}),o.filter(p=>!this.inputs.find(v=>{var E;return((E=v.declaration)==null?void 0:E.id)===p.id})).forEach(p=>{const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:p,defaultValue:null,index:p.index,readsValue:null},E=V(v,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.suggestion=!0,this.addInput(E),E}),this.inputs.filter(p=>!p.declaration).forEach(p=>{const v=o.find(E=>G(E,this.project)===G(p,this.project));v&&p.setDeclaration(v)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(c=>!this.outputs.find(h=>h.declaration===c)).map(c=>{const h={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:c,index:c.index,writesValues:[]},p=V(h,this.project);return p.setParent(this,e),p.initChildren(e),e==null||e.add(p,b.Added),p.suggestion=!0,this.addOutput(p),p});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],r=[],a=[],d=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(c=>!this.internalCalls.find(p=>{var E,P,w,C,U;return(((E=p.declaration)==null?void 0:E.id)||((w=(P=p.initialData)==null?void 0:P.declaration)==null?void 0:w.entityId)||((U=(C=p.initialData)==null?void 0:C.declaration)==null?void 0:U.id))===c.id})).map(c=>{const h=c.createInternalCall(this);return e==null||e.add(h,b.Added),h.suggestion=!0,this.addInternalCall(h),h});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new A(this.project,"",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,...r)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),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 ji=Ve;function rq(i){var d;const s=Y6(),e=i.toJSON();s.safeParse(e).success,i.inputsDeclarations.forEach(o=>o.validate()),i.inputs.forEach(o=>o.validate()),i.outputsDeclarations.forEach(o=>o.validate()),i.outputs.forEach(o=>o.validate()),(d=i.error)==null||d.validate();const a=[...fi(i)];if(i.id==="search-person-by-id-id"){const o=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});a.push(o.error)}return Ye(i.errors,a)}var H1=(i=>(i.Parent="parent",i))(H1||{});const Ze=class Ze extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const h=g(e.parent);r=t.get(h)}const a=e.calledByEntry.map(h=>{const p=g(h);return t.get(p)}),d=e.calledBySuccess.map(h=>{const p=g(h);return t.get(p)}),o=e.calledByError.map(h=>{const p=g(h);return t.get(p)}),l={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:a,calledBySuccess:d,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:r},c=V(l,t);return c.setParent(r,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...mt,n.Project],optional:!0}},t);return r=d.modifiedData,a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncInputMaps(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(a=>a.id===e.id);t>-1&&this.inputs.splice(t,1);const r=this.inputsDeclarations.findIndex(a=>{var d;return a.id===((d=e.declaration)==null?void 0:d.id)});return r>-1&&this.inputsDeclarations.splice(r,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.inputsDeclarations.splice(t,1),this}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,this.name=e.name||this.name,this.description=e.description||this.description,e.query!==void 0&&(this.query=e.query),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ze.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ze.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.inputsDeclarations.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputsDeclarations.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.inputsDeclarations.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(r=>r.toJSON()),errorCalls:this.errorCalls.map(r=>r.toJSON()),calledBySuccess:this.calledBySuccess.map(r=>r.toReference()),calledByError:this.calledByError.map(r=>r.toReference()),calledByEntry:this.calledByEntry.map(r=>r.toReference()),inputsDeclarations:this.inputsDeclarations.map(r=>r.toJSON()),inputs:this.inputs.map(r=>r.toJSON()),outputsDeclarations:this.outputsDeclarations.map(r=>r.toJSON()),outputs:this.outputs.map(r=>r.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(h=>h.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(h=>h.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(h=>h.toJSONClone({...e,newId:null})),inputs:this.inputs.map(h=>h.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(h=>h.toJSONClone({...e,newId:null})),outputs:this.outputs.map(h=>h.toJSONClone({...e,newId:null})),error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(a=>a.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=rq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var C,U,S,B;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(C=this.inputsDeclarations)==null?void 0:C.map(($,k)=>$.clone(e,this,h+"-input-declaration-"+k+"-id",a));p.inputsDeclarations=v;const E=(U=this.outputsDeclarations)==null?void 0:U.map(($,k)=>$.clone(e,this,h+"-output-declaration-"+k+"-id",a));p.outputsDeclarations=E;const P=(S=this.inputs)==null?void 0:S.map(($,k)=>$.clone(e,p,h+"-input-map-"+k+"-id",a));p.inputs=P;const w=(B=this.outputs)==null?void 0:B.map(($,k)=>$.clone(e,p,h+"-output-map-"+k+"-id",a));return p.outputs=w,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(c=>{var h;return((h=c.declaration)==null?void 0:h.id)===o.id})){const c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},h=V(c,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,b.Added),h.addSelfToProject(e),t.push(this),r.push(h)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const{updated:c,removed:h}=o.remove({ignoreUpstream:!1},e);c.push(...c),a.push(...h)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ze,"type",n.Search),f(Ze,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",[...Ze.MUTABLE_BASE_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",["calledBySuccess","calledByError","calledByEntry"]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...rr.META_PROPERTIES,...rr.UPSTREAM_PROPERTIES,...rr.DOWNSTREAM_PROPERTIES]);let $i=Ze;function iq(i){const s=G3(),e=i.toJSON();s.safeParse(e).success,i.functions.forEach(a=>a.validate()),i.events.forEach(a=>a.validate());const r=[];return Ye(i.errors,r)}const xe=class xe extends rt{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 fromGenerationTarget(e,t){const r=t,a={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:R.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:R.UUID.uuid()},x:0,y:0,parent:r},d=V(a,t);return d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await xe.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await xe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.functions.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...h)}),this.events.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...h)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(c=>c.toJSONClone({...e,newId:null})),events:this.events.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=iq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.functions=[],o.events=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t&&p.setParent(t,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.functions)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-exported-function-declaration-"+U+"-id",a));p.functions=v;const E=(w=this.events)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-exported-event-"+U+"-id",a));return p.events=E,e==null||e.attemptAutoclose("clone-entity",this.id),p}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(xe,"type",n.InstalledProject),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","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",[]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),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 Gi=xe;function nq(i){var o;const s=X6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate();const r=fi(i),a=aq(i),d=[...r,...a];return Ye(i.errors,d)}function aq(i){const s=[],e=Pd(i.parent,null),t=e==null?void 0:e.entity;if(!t)s.push(ye({id:`${i.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,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) its id "${i.declaration}".`,issue:null,entity:i}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))s.push(ye({id:`${i.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
|
|
111
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncInputMaps(e);return t.push(...o),r.push(...l),a.push(...c),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(a=>a.id===e.id);t>-1&&this.inputs.splice(t,1);const r=this.inputsDeclarations.findIndex(a=>{var d;return a.id===((d=e.declaration)==null?void 0:d.id)});return r>-1&&this.inputsDeclarations.splice(r,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addInputDeclaration(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e){const t=this.inputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.inputsDeclarations.splice(t,1),this}addOutputDeclaration(e){return this.outputsDeclarations.includes(e)?this:(this.outputsDeclarations.push(e),this)}removeOutputDeclaration(e){const t=this.outputsDeclarations.findIndex(r=>r.id===e.id);return t>-1&&this.outputsDeclarations.splice(t,1),this}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,this.name=e.name||this.name,this.description=e.description||this.description,e.query!==void 0&&(this.query=e.query),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ze.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.inputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.inputsDeclarations.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputs.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.outputsDeclarations.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.error){const{updated:l,removed:c}=this.error.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.successCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),this.errorCalls.forEach(l=>{r.push(l),l.removeCaller(this)}),e||this.calledBy.forEach(l=>{r.push(l),l.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputsDeclarations.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.inputsDeclarations.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.outputsDeclarations.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(r=>r.toJSON()),errorCalls:this.errorCalls.map(r=>r.toJSON()),calledBySuccess:this.calledBySuccess.map(r=>r.toReference()),calledByError:this.calledByError.map(r=>r.toReference()),calledByEntry:this.calledByEntry.map(r=>r.toReference()),inputsDeclarations:this.inputsDeclarations.map(r=>r.toJSON()),inputs:this.inputs.map(r=>r.toJSON()),outputsDeclarations:this.outputsDeclarations.map(r=>r.toJSON()),outputs:this.outputs.map(r=>r.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(h=>h.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(h=>h.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(h=>h.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(h=>h.toJSONClone({...e,newId:null})),inputs:this.inputs.map(h=>h.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(h=>h.toJSONClone({...e,newId:null})),outputs:this.outputs.map(h=>h.toJSONClone({...e,newId:null})),error:((c=this.error)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(a=>a.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(a=>a.toReference(e)),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=rq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var C,U,S,B;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(C=this.inputsDeclarations)==null?void 0:C.map(($,k)=>$.clone(e,this,h+"-input-declaration-"+k+"-id",a));p.inputsDeclarations=v;const E=(U=this.outputsDeclarations)==null?void 0:U.map(($,k)=>$.clone(e,this,h+"-output-declaration-"+k+"-id",a));p.outputsDeclarations=E;const P=(S=this.inputs)==null?void 0:S.map(($,k)=>$.clone(e,p,h+"-input-map-"+k+"-id",a));p.inputs=P;const w=(B=this.outputs)==null?void 0:B.map(($,k)=>$.clone(e,p,h+"-output-map-"+k+"-id",a));return p.outputs=w,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}syncInputMaps(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-input-maps"))){const t=[],r=[],a=[],d=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(c=>{var h;return((h=c.declaration)==null?void 0:h.id)===o.id})){const c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},h=V(c,this.project);h.setParent(this,e),h.initChildren(e),e==null||e.add(h,b.Added),h.addSelfToProject(e),t.push(this),r.push(h)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const{updated:c,removed:h}=o.remove({ignoreUpstream:!1},e);c.push(...c),a.push(...h)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};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,...r)=>null}),f(Ze,"type",n.Search),f(Ze,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",[...Ze.MUTABLE_BASE_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",["calledBySuccess","calledByError","calledByEntry"]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...rr.META_PROPERTIES,...rr.UPSTREAM_PROPERTIES,...rr.DOWNSTREAM_PROPERTIES]);let $i=Ze;function iq(i){const s=G3(),e=i.toJSON();s.safeParse(e).success,i.functions.forEach(a=>a.validate()),i.events.forEach(a=>a.validate());const r=[];return Ye(i.errors,r)}const xe=class xe extends rt{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 fromGenerationTarget(e,t){const r=t,a={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:R.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:R.UUID.uuid()},x:0,y:0,parent:r},d=V(a,t);return d.setParent(r,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await xe.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.functions.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...h)}),this.events.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!1},t);r.push(...c),a.push(...h)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(c=>c.toJSONClone({...e,newId:null})),events:this.events.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=iq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.functions=[],o.events=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t&&p.setParent(t,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.functions)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-exported-function-declaration-"+U+"-id",a));p.functions=v;const E=(w=this.events)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-exported-event-"+U+"-id",a));return p.events=E,e==null||e.attemptAutoclose("clone-entity",this.id),p}};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,...r)=>null}),f(xe,"type",n.InstalledProject),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","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",[]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),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 Gi=xe;function nq(i){var o;const s=X6(),e=i.toJSON();s.safeParse(e).success,i.inputs.forEach(l=>l.validate()),i.outputs.forEach(l=>l.validate()),(o=i.error)==null||o.validate();const r=fi(i),a=aq(i),d=[...r,...a];return Ye(i.errors,d)}function aq(i){const s=[],e=Pd(i.parent,null),t=e==null?void 0:e.entity;if(!t)s.push(ye({id:`${i.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,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) its id "${i.declaration}".`,issue:null,entity:i}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))s.push(ye({id:`${i.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
|
|
112
112
|
This variable's data-type has an 'entity' field that references an entity with id '${t.id}' and of type '${t.type}'.`,issue:null,entity:i}).error);else{const r=Fp(t),a=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&a.push(...t.getAllInteractiveMethods());let d="";r?t.methods.length?d=`
|
|
113
113
|
All 'function-declaration' entities attached as methods to the parent data-type 'entity' field, available to be called as 'internal-calls' in this variable are:
|
|
114
114
|
- ${t.methods.map(c=>c.id).join(`
|
|
@@ -137,7 +137,7 @@ ${Zi}`);const E=r.declaration;if(!t.get(E))a.push(new O({id:`${r.id}--${I.Refere
|
|
|
137
137
|
The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${v}`,issue:null})):a.push(new O({id:`${r.id}--${j.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:j.InternalCallDeclarationNotFoundInParentDatatypeEntity,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) with id "${r.declaration}".${v}`,issue:null}))}}(l.inputs.length||l.outputs.length||l.internalCalls.length)&&a.push(new O({id:`${r.id}--${I.InvalidInternalCallParentRelation}`,code:I.InvalidInternalCallParentRelation,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
|
|
138
138
|
If you need a new variable-instance for this, consider using the 'implement_variable_instance' generation action to create one and give it a caller.
|
|
139
139
|
The you can attach the new internal-call to it.`,issue:null}))}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:h,added:p,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...h),r.push(...l,...p),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=V(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const r=this.calledBy.find(a=>!!a.parent&&mt.includes(a.parent.type));if(r){const a=V(r.parent,this.project);this.parent.setParent(a,null)}else if(!r&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ce.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ce.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.process){const{updated:c,removed:h}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.outputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.error){const{updated:c,removed:h}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),error:(h=this.error)==null?void 0:h.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=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=nq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>!this.inputs.find(v=>v.declaration.id===p.id));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1},e)});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=V(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(U=>{U.index>=v.index&&U.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,w={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=V(w,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:h,removed:p}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...h),a.push(...p),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ce,"type",n.InternalCall),f(Ce,"USER_MANAGED_PARENT_TYPES",[...Qe]),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,"index"]),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"]),f(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),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 gn=Ce;function sq(i){const s=r3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-argument-map-id"){const a=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var X1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(X1||{});const ge=class ge extends rt{constructor(e,t){super(e);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);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.declaration){const h=g(e.declaration);d=t.get(h)}let o=null;if(e.readsValue){const h=g(e.readsValue);o=t.get(h)}const l={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(a.inputs||[]).length,description:e.description||null,declaration:d,readsValue:o,defaultValue:null,parent:a},c=V(l,t);return c.setParent(a,null),c.initChildren(null),c}static validateGenerationTarget(e,t){var h;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...nt,n.InputMap]}},t);r=d.modifiedData;const o=t.get(r.parent),l=r.declaration&&(t.get(r.declaration)||t.getBuiltIn(r.declaration)),c=((o==null?void 0:o.inputs)||[]).find(p=>{var v;return r.declaration&&((v=p.declaration)==null?void 0:v.id)===r.declaration});if(r.declaration?l?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(l.type)?o&&l.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?a.push(new O({id:`${r.id}--${I.InvalidInputMapDeclaration}`,code:I.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${r.declaration}'.
|
|
140
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:h,added:p,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...h),r.push(...l,...p),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=V(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const r=this.calledBy.find(a=>!!a.parent&&mt.includes(a.parent.type));if(r){const a=V(r.parent,this.project);this.parent.setParent(a,null)}else if(!r&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.outputs=this.initialData.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ce.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.process){const{updated:c,removed:h}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.outputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.error){const{updated:c,removed:h}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.calledBy.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e)),...this.calledBy.flatMap(r=>r.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),error:(h=this.error)==null?void 0:h.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=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.calledBy.flatMap(r=>r.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=nq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>!this.inputs.find(v=>v.declaration.id===p.id));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1},e)});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=V(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(U=>{U.index>=v.index&&U.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,w={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=V(w,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:h,removed:p}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...h),a.push(...p),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};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,...r)=>null}),f(Ce,"type",n.InternalCall),f(Ce,"USER_MANAGED_PARENT_TYPES",[...Qe]),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,"index"]),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"]),f(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),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 gn=Ce;function sq(i){const s=r3(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-argument-map-id"){const a=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var X1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(X1||{});const ge=class ge extends rt{constructor(e,t){super(e);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);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null;if(e.declaration){const h=g(e.declaration);d=t.get(h)}let o=null;if(e.readsValue){const h=g(e.readsValue);o=t.get(h)}const l={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(a.inputs||[]).length,description:e.description||null,declaration:d,readsValue:o,defaultValue:null,parent:a},c=V(l,t);return c.setParent(a,null),c.initChildren(null),c}static validateGenerationTarget(e,t){var h;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[...nt,n.InputMap]}},t);r=d.modifiedData;const o=t.get(r.parent),l=r.declaration&&(t.get(r.declaration)||t.getBuiltIn(r.declaration)),c=((o==null?void 0:o.inputs)||[]).find(p=>{var v;return r.declaration&&((v=p.declaration)==null?void 0:v.id)===r.declaration});if(r.declaration?l?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(l.type)?o&&l.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?a.push(new O({id:`${r.id}--${I.InvalidInputMapDeclaration}`,code:I.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${r.declaration}'.
|
|
141
141
|
The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
|
|
142
142
|
Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`,issue:null})):o&&l.type===n.Property&&!Qe.includes(o.type)?a.push(new O({id:`${r.id}--${I.InvalidInputMapDeclaration}`,code:I.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' has a 'declaration' property pointing to an entity with type '${n.Property}' with id '${r.declaration}'.
|
|
143
143
|
The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
|
|
@@ -155,7 +155,7 @@ Input maps can only be added to variables which hold an entity with properties.`
|
|
|
155
155
|
The entity of the data-type has the following properties that can be reads as input maps, ids: '${ie(P.properties.map(C=>C.id),"', '","' and '")}'`,issue:null})))}else if(nt.filter(p=>Qe.includes(p)).includes(o.type)){const v=Up(o),E=v.find(w=>w.id===r.declaration),P=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${ie(v.map(w=>w.id),"', '","' and '")}'`;E||a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent entity does not have an 'argument-declaration' with id '${r.declaration}'.
|
|
156
156
|
You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
|
|
157
157
|
${P}`,issue:null}))}}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];let r=JSON.parse(JSON.stringify(e));const a=ws(r,this);return r=a.modifiedData,t.push(...a.errors),r.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
158
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];if(this.parent.addInput(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),Qe.includes(this.parent.type)&&((l=this.parent.getDataType(e))!=null&&l.inferred)){const c=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:h,added:p,removed:v,affected:E}=c.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...h),r.push(...p),a.push(...v),d.push(...E),t.push(c,...c.variableInstances)}return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration&&(this.declaration=V(this.initialData.declaration,this.project)),yi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ge.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),e||(r.push(this.parent),this.parent.removeInput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.restore({},e)),r.push(this.parent),this.parent.addInput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v,E,P;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:(h=this.declaration)!=null&&h.id&&this.project.getBuiltIn((p=this.declaration)==null?void 0:p.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,readsValue:((P=this.readsValue)==null?void 0:P.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=sq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var p;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.defaultValue=null,o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(p=this.defaultValue)==null?void 0:p.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=h||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){var r;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this,e).self;if(Qe.includes(this.parent.type)){const a=Pn(this.parent),d=a.getDataType(e);(!d||d.inferred)&&a.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(r=this.declaration)==null?void 0:r.getDataType(e);if(!t){const a=xr(this,e);if(a)return a}return t||null}};f(ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(ge,"type",n.InputMap),f(ge,"USER_MANAGED_PARENT_TYPES",[...nt]),f(ge,"PARENT_TYPES",[...ge.USER_MANAGED_PARENT_TYPES]),f(ge,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ge,"BASE_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"MUTABLE_META_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,"index"]),f(ge,"INMUTABLE_META_PROPERTIES",[...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"META_PROPERTIES",[...ge.MUTABLE_META_PROPERTIES,...ge.INMUTABLE_META_PROPERTIES]),f(ge,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(ge,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(ge,"UPSTREAM_PROPERTIES",[...ge.MUTABLE_UPSTREAM_PROPERTIES,...ge.INMUTABLE_UPSTREAM_PROPERTIES]),f(ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),f(ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ge,"DOWNSTREAM_PROPERTIES",[...ge.MUTABLE_DOWNSTREAM_PROPERTIES,...ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ge,"PROPERTIES",[...ge.META_PROPERTIES,...ge.UPSTREAM_PROPERTIES,...ge.DOWNSTREAM_PROPERTIES]);let kr=ge;class oq extends kr{constructor(e,t){super(e,t);f(this,"declaration",null);f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class dq extends kr{constructor(e,t){super(e,t);f(this,"name",null);f(this,"description",null);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function lq(i){const s=L6(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-return-map-id"){const a=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var Q1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(Q1||{});const Be=class Be extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.OutputMap);f(this,"parentRelationType");f(this,"defaultValue",null);f(this,"declaration");f(this,"writesValues",[]);f(this,"dataType");f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d;if(e.declaration){const c=g(e.declaration);d=t.get(c)}const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,index:(a.outputs||[]).length,defaultValue:null,declaration:d,writesValues:[],parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:nt.filter(c=>c!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);r=d.modifiedData;const o=t.get(r.parent);if(o&&nt.filter(c=>c!==n.Condition).includes(o.type)){const c=o.outputs.find(h=>h.declaration.id===(r.declaration?g(r.declaration):null));if(c)a.push(new O({id:`${r.id}--${I.OutputOverwrite}`,code:I.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${c.id}' that points to the same base 'return-declaration'.
|
|
158
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:r}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ge(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ge(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.readsValue){const d=g(this.initialData.readsValue),o=this.project.get(d);o&&(this.setValueWriter(o),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return yi.hydrateReadsValue(this),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];if(this.parent.addInput(this),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this),this.readsValue&&t.push(this.readsValue),Qe.includes(this.parent.type)&&((l=this.parent.getDataType(e))!=null&&l.inferred)){const c=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:h,added:p,removed:v,affected:E}=c.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...h),r.push(...p),a.push(...v),d.push(...E),t.push(c,...c.variableInstances)}return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration&&(this.declaration=V(this.initialData.declaration,this.project)),yi.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e){return this.readsValue=e,this}removeValueWriter(){return this.readsValue=null,this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ge.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ge.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ge.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.removeValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),e||(r.push(this.parent),this.parent.removeInput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.readsValue&&(r.push(this.readsValue),this.readsValue.addValueReader(this)),this.defaultValue&&(r.push(this.defaultValue),this.defaultValue.restore({},e)),r.push(this.parent),this.parent.addInput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,readsValue:((a=this.readsValue)==null?void 0:a.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v,E,P;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,declaration:(h=this.declaration)!=null&&h.id&&this.project.getBuiltIn((p=this.declaration)==null?void 0:p.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,readsValue:((P=this.readsValue)==null?void 0:P.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:((d=this.declaration)==null?void 0:d.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=sq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var p;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.defaultValue=null,o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(p=this.defaultValue)==null?void 0:p.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=h||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){var r;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this,e).self;if(Qe.includes(this.parent.type)){const a=Pn(this.parent),d=a.getDataType(e);(!d||d.inferred)&&a.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(r=this.declaration)==null?void 0:r.getDataType(e);if(!t){const a=xr(this,e);if(a)return a}return t||null}};f(ge,"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,...r)=>null}),f(ge,"type",n.InputMap),f(ge,"USER_MANAGED_PARENT_TYPES",[...nt]),f(ge,"PARENT_TYPES",[...ge.USER_MANAGED_PARENT_TYPES]),f(ge,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ge,"BASE_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"MUTABLE_META_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,"index"]),f(ge,"INMUTABLE_META_PROPERTIES",[...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"META_PROPERTIES",[...ge.MUTABLE_META_PROPERTIES,...ge.INMUTABLE_META_PROPERTIES]),f(ge,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(ge,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(ge,"UPSTREAM_PROPERTIES",[...ge.MUTABLE_UPSTREAM_PROPERTIES,...ge.INMUTABLE_UPSTREAM_PROPERTIES]),f(ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),f(ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ge,"DOWNSTREAM_PROPERTIES",[...ge.MUTABLE_DOWNSTREAM_PROPERTIES,...ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ge,"PROPERTIES",[...ge.META_PROPERTIES,...ge.UPSTREAM_PROPERTIES,...ge.DOWNSTREAM_PROPERTIES]);let kr=ge;class oq extends kr{constructor(e,t){super(e,t);f(this,"declaration",null);f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class dq extends kr{constructor(e,t){super(e,t);f(this,"name",null);f(this,"description",null);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function lq(i){const s=L6(),e=i.toJSON();s.safeParse(e).success;const r=[];if(i.id==="exec-sequentially-return-map-id"){const a=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(a.error)}return Ye(i.errors,r)}var Q1=(i=>(i.Declaration="declaration",i.DataTypeEntity="data-type-entity",i))(Q1||{});const Be=class Be extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.OutputMap);f(this,"parentRelationType");f(this,"defaultValue",null);f(this,"declaration");f(this,"writesValues",[]);f(this,"dataType");f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d;if(e.declaration){const c=g(e.declaration);d=t.get(c)}const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,index:(a.outputs||[]).length,defaultValue:null,declaration:d,writesValues:[],parent:a},l=V(o,t);return l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){var l;let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:nt.filter(c=>c!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);r=d.modifiedData;const o=t.get(r.parent);if(o&&nt.filter(c=>c!==n.Condition).includes(o.type)){const c=o.outputs.find(h=>h.declaration.id===(r.declaration?g(r.declaration):null));if(c)a.push(new O({id:`${r.id}--${I.OutputOverwrite}`,code:I.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${c.id}' that points to the same base 'return-declaration'.
|
|
159
159
|
Any value reads can be done with that output-map instead.
|
|
160
160
|
You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}));else{const h=r.declaration?t.get(r.declaration):null;if(h&&Qe.includes(o.type)){const p=Pn(o),v=p.dataType,E=(l=p.dataType)==null?void 0:l.entity;v?E?E.type===n.ActionDescriptor?a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The data type of the 'variable-declaration' is a 'action-descriptor' entity.
|
|
161
161
|
This means it can hold a function-call or operation as its value, to be executed programatically.
|
|
@@ -165,16 +165,16 @@ ${Ap}`,issue:null})):a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSign
|
|
|
165
165
|
${Ap}`,issue:null}))}else if(h){const p=o.outputs.find(v=>v.declaration.id===r.declaration);p&&a.push(new O({id:`${r.id}--${I.OutputOverwrite}`,code:I.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${r.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${p.id}' that points to the same declaration.
|
|
166
166
|
Any value reads can be done with that output-map instead.
|
|
167
167
|
You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}))}}}return a.push(...d.errors,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
168
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parentRelationType===Un.Error?Qe.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===F["value-descriptor"][Gs.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this),this.writesValues.forEach(l=>{l.setValueWriter(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),Ms.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=V(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Be.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parentRelationType===Un.Error?Qe.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parentRelationType===Un.Error?Qe.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v,E;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(P=>P.toJSONClone({...e,newId:null})),declaration:(h=this.declaration)!=null&&h.id&&this.project.getBuiltIn((p=this.declaration)==null?void 0:p.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:(d=this.declaration)==null?void 0:d.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.declaration?this.declaration.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=lq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var v,E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.id=l;const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(v=this.dataType)==null?void 0:v.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(E=this.defaultValue)==null?void 0:E.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=p||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){var r;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this,e).self:((r=this.declaration)==null?void 0:r.getDataType(e))||null}};f(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Be,"type",n.OutputMap),f(Be,"USER_MANAGED_PARENT_TYPES",[...zp]),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",[]),f(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),f(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),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 Zr=Be;class uq extends Zr{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class cq extends Zr{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function pq(i){var a;const s=h5(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="company-dto-func-declaration-argument-dcl-id"){const d=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}if(i.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const d=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var eO=(i=>(i.DataTypeEntity="data-type-entity",i.Implements="implements",i))(eO||{});const _e=class _e extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"type",n.ArgumentDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:a.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:a},o=V(d,t);return o.setParent(a,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);r=d.modifiedData;const o=pp(r,t);if(r.parent){const l=t.get(g(r.parent));if(l&&at.includes(l.type)){const c=l.implements;if(c){const h=c.inputs.find(C=>C.name===r.name),p=c.inputs.filter(C=>!l.inputs.find(S=>S.type===n.ArgumentDeclaration&&S.name===C.name)),v=l.inputs.filter(C=>C.type===n.ArgumentDeclaration),E=v.find(C=>C.name===r.name),P=v.length?`The parent entity already implements the following arguments: ${ie(v.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",w=p.length?`The parent entity is still missing the following arguments in the implementation: ${ie(p.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";h?E&&a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${l.type}' with id '${l.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
|
|
168
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parentRelationType===Un.Error?Qe.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===F["value-descriptor"][Gs.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this),this.writesValues.forEach(l=>{l.setValueWriter(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),Ms.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=V(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Be.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}return this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parentRelationType===Un.Error?Qe.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}return this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parentRelationType===Un.Error?Qe.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...((a=this.dataType)==null?void 0:a.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(a=>a.toJSON(e)),declaration:((r=this.declaration)==null?void 0:r.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p,v,E;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(P=>P.toJSONClone({...e,newId:null})),declaration:(h=this.declaration)!=null&&h.id&&this.project.getBuiltIn((p=this.declaration)==null?void 0:p.id)?(v=this.declaration)==null?void 0:v.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,declaration:(d=this.declaration)==null?void 0:d.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...this.declaration?this.declaration.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=lq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var v,E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.id=l;const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(v=this.dataType)==null?void 0:v.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(E=this.defaultValue)==null?void 0:E.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=p||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){var r;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this,e).self:((r=this.declaration)==null?void 0:r.getDataType(e))||null}};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,...r)=>null}),f(Be,"type",n.OutputMap),f(Be,"USER_MANAGED_PARENT_TYPES",[...zp]),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",[]),f(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),f(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),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 Zr=Be;class uq extends Zr{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class cq extends Zr{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function pq(i){var a;const s=h5(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];if(i.id==="company-dto-func-declaration-argument-dcl-id"){const d=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}if(i.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const d=ye({id:`${i.id}--${q.PropertyImplementsNonAbstact}`,message:`Property "${G(i,i.project)}" with id "${i.id}" implements a non-abstract property "${G(i,i.project)}" with id "${i.id}".`,issue:null,severity:D.Error,code:q.PropertyImplementsNonAbstact,entity:i});r.push(d.error)}return Ye(i.errors,r)}var eO=(i=>(i.DataTypeEntity="data-type-entity",i.Implements="implements",i))(eO||{});const _e=class _e extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"type",n.ArgumentDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r),d={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:a.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:a},o=V(d,t);return o.setParent(a,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);r=d.modifiedData;const o=pp(r,t);if(r.parent){const l=t.get(g(r.parent));if(l&&at.includes(l.type)){const c=l.implements;if(c){const h=c.inputs.find(C=>C.name===r.name),p=c.inputs.filter(C=>!l.inputs.find(S=>S.type===n.ArgumentDeclaration&&S.name===C.name)),v=l.inputs.filter(C=>C.type===n.ArgumentDeclaration),E=v.find(C=>C.name===r.name),P=v.length?`The parent entity already implements the following arguments: ${ie(v.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",w=p.length?`The parent entity is still missing the following arguments in the implementation: ${ie(p.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";h?E&&a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${l.type}' with id '${l.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
|
|
169
169
|
Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
|
|
170
170
|
${P}
|
|
171
171
|
${w}`,issue:null})):a.push(new O({id:`${r.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${r.id}' should not exist in a parent entity of type '${l.type}' with id '${l.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
|
|
172
172
|
Adding a new argument would make the implementation invalid. There are no arguments in the descriptor with the same name.
|
|
173
173
|
${P}
|
|
174
174
|
${w}`,issue:null}))}}}return a.push(...d.errors,...o,...ot(r)),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
175
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.implements=this.implements,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.writesValues=this.writesValues,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.implements=o.implements,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.writesValues=o.writesValues,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addInputDeclaration(this,e),t.push(this.parent),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return Ms.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await _e.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await _e.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parent.removeInputDeclaration(this)),this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parent.addInputDeclaration(this,e),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.dataType)==null?void 0:a.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a;return e instanceof Set?e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),parent:this.parent.toReference()}):(console.error("ArgumentDeclarationState.toJSON was called without a valid Set of seenEntities.",`
|
|
175
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(null,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&(this.setImplements(e,r),a.push(this)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r,a,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(d=(a=(r=this.dataType)==null?void 0:r.entity)==null?void 0:a.subscribeDependents)==null||d.call(a,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.implements=this.implements,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.writesValues=this.writesValues,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.implements=o.implements,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.writesValues=o.writesValues,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.implements){const d=g(this.initialData.implements),o=this.project.get(d);o&&(this.setImplements(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];return this.parent.addInputDeclaration(this,e),t.push(this.parent),this.writesValues.forEach(o=>{o.setValueWriter(this),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addValueReader(e){return this.writesValues.includes(e)?this:(this.writesValues.push(e),this)}removeValueReader(e){return this.writesValues=this.writesValues.filter(t=>t.id!==e.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-implements"))){var r;return((r=this.implements)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=V(this.initialData.implements,this.project);this.setImplements(t,null)}return Ms.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.index=e.index||(e.index!==0?this.index:0),this.name=e.name||this.name,this.description=e.description||this.description,this.required=e.required||this.required,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await _e.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.defaultValue){const{updated:l,removed:c}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...l),a.push(...c)}if(this.writesValues.forEach(l=>{r.push(l),l.readsValue=null}),e||(r.push(this.parent),this.parent.removeInputDeclaration(this)),this.dataType){const l=this.dataType.remove({ignoreUpstream:!0},t);r.push(...l.updated),a.push(...l.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);r.push(...o)}if(this.writesValues.forEach(o=>{r.push(o),o.setValueWriter(this)}),r.push(this.parent),this.parent.addInputDeclaration(this,e),this.dataType){const{updated:o}=this.dataType.restore({},e);r.push(...o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.writesValues.flatMap(d=>d.toFlat(e)),...((a=this.dataType)==null?void 0:a.toFlat(e))||[]])}toFlatIds(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.writesValues.flatMap(d=>d.toFlatIds(e)),...((a=this.dataType)==null?void 0:a.toFlatIds(e))||[]])}toJSON(e=new Set){var t,r,a;return e instanceof Set?e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,implements:((a=this.implements)==null?void 0:a.toJSON(e))||null,writesValues:this.writesValues.map(d=>d.toJSON(e)),parent:this.parent.toReference()}):(console.error("ArgumentDeclarationState.toJSON was called without a valid Set of seenEntities.",`
|
|
176
176
|
Received type: ${typeof e}
|
|
177
|
-
`,e),{})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:((p=this.implements)==null?void 0:p.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),implements:((d=this.implements)==null?void 0:d.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=pq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var v,E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.dataType=null,o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(v=this.dataType)==null?void 0:v.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(E=this.defaultValue)==null?void 0:E.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=p||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};f(_e,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>
|
|
177
|
+
`,e),{})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,implements:((p=this.implements)==null?void 0:p.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(v=>v.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,writesValues:this.writesValues.map(l=>l.toReference(e)),implements:((d=this.implements)==null?void 0:d.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...this.writesValues.flatMap(d=>d.toFlatJSON(e)),...((a=this.dataType)==null?void 0:a.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var r,a;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((r=this.defaultValue)==null?void 0:r.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(d=>d.toFlatGenerationTarget(e)),...((a=this.dataType)==null?void 0:a.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=pq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,r;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((r=this.dataType)==null?void 0:r.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var v,E;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.dataType=null,o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);t?c.setParent(t,null):c.setParent(this.parent,null),a&&c.subscribe(),c.initChildren(e),e==null||e.add(c,b.Added);const h=(v=this.dataType)==null?void 0:v.clone(e,c,R.UUID.uuid(),a);c.dataType=h||null;const p=(E=this.defaultValue)==null?void 0:E.clone(e,c,R.UUID.uuid(),a);return c.defaultValue=p||null,e==null||e.attemptAutoclose("clone-entity",this.id),c}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};f(_e,"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,...r)=>null}),f(_e,"type",n.ArgumentDeclaration),f(_e,"USER_MANAGED_PARENT_TYPES",[...at]),f(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),f(_e,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),f(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),f(_e,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),f(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),f(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Si=_e;function fq(i){const s=Ic(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}function yq(i,s){var t,r;const e=[];if(i.parent)if(i.parent){const a=s.get(i.parent);a?[n.InputMap,n.DataType].includes(a.type)?a.type===n.DataType&&a.entity?e.push(new O({id:`${i.id}--${i.parent}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a 'parent' of type 'data-type' which already has an existing default value entity with id "${a.entity.id}".
|
|
178
178
|
Data types can only have one 'literal-value' entity as 'entity'.
|
|
179
179
|
You can update the existing 'literal-value' with the 'update' action, for example, like so:
|
|
180
180
|
\`\`\`json
|
|
@@ -199,12 +199,12 @@ You can update the existing 'literal-value' with the 'update' action, for exampl
|
|
|
199
199
|
}
|
|
200
200
|
}\`\`\`
|
|
201
201
|
Or 'delete' and then 'post' actions to replace it.`,issue:null})):e.push(new O({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'input-map' or 'data-type'.`,issue:null})):e.push(new O({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new O({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null}));else return e.push(new O({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null})),e;if(i.valueAsTypeSingle){const a=[],d=[],o=i.valueAsTypeSingle;Array.isArray(o)?o.forEach(l=>{typeof l=="string"?d.push(l):a.push(l)}):typeof o=="string"?d.push(o):a.push(o),a.forEach(l=>{const c=Md(l);e.push(...c),c.length===0&&d.push(l.entityId)}),d.forEach(l=>{const c=s.get(l);c?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(c.type)||e.push(new O({id:`${i.id}--${l}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'valueAsTypeSingle' reference that isn't pointing to an entity of type 'definition-entity', 'function-declaration' or 'operation'.`,issue:null})):e.push(new O({id:`${i.id}--${l}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${l}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))})}return e}var tO=(i=>(i.ValueAsTypeSingle="value-as-type-single",i.ValueAsTypeList="value-as-type-list",i))(tO||{});const Me=class Me extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"type",n.LiteralValue);f(this,"id");f(this,"name");f(this,"autogeneration",null);f(this,"value",null);f(this,"valueAsTypeSingle",null);f(this,"valueAsTypeList",null);f(this,"errors",[]);f(this,"parent");f(this,"standaloneParent");f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"standalone",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.autogeneration=e.autogeneration,this.value=e.value}static fromGenerationTarget(e,t){const r=g(e.parent),a=t.get(r);let d=null,o=null;e.valueAsTypeList?Array.isArray(e.valueAsTypeList)&&(o=e.valueAsTypeList.map(h=>t.get(h)||t.getBuiltIn(h))):e.valueAsTypeSingle&&(d=t.get(e.valueAsTypeSingle)||t.getBuiltIn(e.valueAsTypeSingle));const l={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:e.name,autogeneration:e.autogeneration,valueAsTypeSingle:d,valueAsTypeList:o,value:e.value||null,parent:a},c=V(l,t);return c.setParent(a,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=yq(r,t);return a.push(...d,...ot(r)),{errors:a,modifiedData:r}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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.
|
|
202
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(c=>c.id!==e.id),r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(d=>{const o=g(d),l=this.project.get(o);l&&this.valueAsTypeList.push(l)});else if(this.initialData.valueAsTypeSingle){const d=g(this.initialData.valueAsTypeSingle),o=this.project.get(d);o&&(this.valueAsTypeSingle=o)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(l=this.parent)==null||l.setDefaultValue(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsType(e){return e?(Array.isArray(e)?this.valueAsTypeList=e:this.valueAsTypeSingle=e,this):(this.valueAsTypeSingle=null,this.valueAsTypeList=null,this)}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=r,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=g(this.initialData.valueAsTypeSingle),a=r?this.project.get(r):null;if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=a,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.autogeneration=e.autogeneration||this.autogeneration,e.value!==void 0&&(this.value=e.value),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Me.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Me.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlat(e)):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlatIds(e)):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(a=>a.toJSON(e)):null,parent:(r=this.parent)==null?void 0:r.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(h=>this.project.getBuiltIn(h.id)?h.toJSON():h.toJSONClone({...e,newId:null})):null,parent:(c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(d=this.parent)==null?void 0:d.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(r=>r.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=fq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);return c.initChildren(e),t&&c.setParent(t,null),e==null||e.add(c,b.Added),a&&c.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),c}merge(e){const t=[],r=[],a=[],d=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle),t.push(this)),this.value!==e.value&&(this.value=e.value,t.push(this)),this.autogeneration!==e.autogeneration&&(this.autogeneration=e.autogeneration,t.push(this)),this.name!==e.name&&(this.name=e.name,t.push(this)),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(Me,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Me,"type",n.LiteralValue),f(Me,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),f(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),f(Me,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),f(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES]),f(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),f(Me,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),f(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),f(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let Bn=Me;function hq(i){var a;const s=z9(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];return Ye(i.errors,r)}var rO=(i=>(i.DataTypeEntity="data-type-entity",i))(rO||{});const Ne=class Ne extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"parentRelationType");f(this,"type",n.ValueDescriptor);f(this,"defaultValue",null);f(this,"dataType",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);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=e.parent?g(e.parent):null,a=r?t.get(r):null,d=e.parentRelationType===_.FixedArguments?a==null?void 0:a.inputs.length:a==null?void 0:a.outputs.length,o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:d||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:a},l=V(o,t);return a&&l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.ActionDescriptor]}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=r.parent&&t.get(r.parent),l=o&&Yi(o);return l&&l.type===n.ActionDescriptor&&a.push(new O({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:D.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${l.name}" of type '${l.type}' with id '${l.id}'.
|
|
202
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(c=>c.id!==e.id),r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,r==null||r.add(this,b.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],r==null||r.add(this,b.Updated)),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(d=>{const o=g(d),l=this.project.get(o);l&&this.valueAsTypeList.push(l)});else if(this.initialData.valueAsTypeSingle){const d=g(this.initialData.valueAsTypeSingle),o=this.project.get(d);o&&(this.valueAsTypeSingle=o)}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l;const t=[this],r=[],a=[],d=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(l=this.parent)==null||l.setDefaultValue(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsType(e){return e?(Array.isArray(e)?this.valueAsTypeList=e:this.valueAsTypeSingle=e,this):(this.valueAsTypeSingle=null,this.valueAsTypeList=null,this)}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=r,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const a=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return a}const r=this.project.get(t.id);if(!r)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return r});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const r=g(this.initialData.valueAsTypeSingle),a=r?this.project.get(r):null;if(!a)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=a,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.autogeneration=e.autogeneration||this.autogeneration,e.value!==void 0&&(this.value=e.value),t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Me.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this})}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlat(e)):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlatIds(e)):[]])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(a=>a.toJSON(e)):null,parent:(r=this.parent)==null?void 0:r.toReference()})}toJSONClone(e=Z){var r,a,d,o,l,c;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(h=>this.project.getBuiltIn(h.id)?h.toJSON():h.toJSONClone({...e,newId:null})):null,parent:(c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((a=this.valueAsTypeSingle)==null?void 0:a.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(d=this.parent)==null?void 0:d.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(r=>r.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(r=>r.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=fq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.id=l,o.version=R.UUID.uuid();const c=lt(o,d);return c.initChildren(e),t&&c.setParent(t,null),e==null||e.add(c,b.Added),a&&c.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),c}merge(e){const t=[],r=[],a=[],d=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle),t.push(this)),this.value!==e.value&&(this.value=e.value,t.push(this)),this.autogeneration!==e.autogeneration&&(this.autogeneration=e.autogeneration,t.push(this)),this.name!==e.name&&(this.name=e.name,t.push(this)),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(Me,"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,...r)=>null}),f(Me,"type",n.LiteralValue),f(Me,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),f(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),f(Me,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),f(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES]),f(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),f(Me,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),f(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),f(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let Bn=Me;function hq(i){var a;const s=z9(),e=i.toJSON();s.safeParse(e).success,(a=i.dataType)==null||a.validate();const r=[];return Ye(i.errors,r)}var rO=(i=>(i.DataTypeEntity="data-type-entity",i))(rO||{});const Ne=class Ne extends rt{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"parentRelationType");f(this,"type",n.ValueDescriptor);f(this,"defaultValue",null);f(this,"dataType",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);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,this.parentRelationType=e.parentRelationType}static fromGenerationTarget(e,t){const r=e.parent?g(e.parent):null,a=r?t.get(r):null,d=e.parentRelationType===_.FixedArguments?a==null?void 0:a.inputs.length:a==null?void 0:a.outputs.length,o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:d||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:a},l=V(o,t);return a&&l.setParent(a,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=Et(r,{parent:{list:!1,types:[n.ActionDescriptor]}},t);r=d.modifiedData,a.push(...d.errors,...ot(r));const o=r.parent&&t.get(r.parent),l=o&&Yi(o);return l&&l.type===n.ActionDescriptor&&a.push(new O({id:`${e.id}--${I.BuiltInEntityParent}`,code:I.BuiltInEntityParent,severity:D.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${l.name}" of type '${l.type}' with id '${l.id}'.
|
|
203
203
|
You can't modify system entities that are built-in.`,issue:null})),o&&o.type===n.ActionDescriptor&&(!r.parentRelationType||!(r.parentRelationType===_.FixedArguments||r.parentRelationType===_.FixedReturns||r.parentRelationType===_.ReturnedError||r.parentRelationType===_.DynamicArgument||r.parentRelationType===_.DynamicReturn)?a.push(new O({id:`${e.id}--${I.InvalidParentRelationType}`,code:I.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either '${_.FixedArguments}', '${_.FixedReturns}', or '${_.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`,issue:null})):r.parentRelationType===_.ReturnedError&&o.error&&a.push(new O({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', is being added as an error value-descriptor to an entity of type 'action-descriptor' with id '${o.id}', which already has an error value descriptor with id '${o.error.id}'.
|
|
204
204
|
An action descriptor can only have one error value descriptor child.
|
|
205
205
|
Either remove the existing error value descriptor or update it with the 'update' action.
|
|
206
206
|
You can use the 'describe_entity' action to get more information about the existing error value descriptor like so:
|
|
207
|
-
${qr({describe_entity:o.error.id})}`,issue:null}))),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r;return(r=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||r.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l,c,h,p,v,E,P;const t=[this],r=[],a=[],d=[];return this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((l=this.parent)==null?void 0:l.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((h=(c=this.parent)==null?void 0:c.addInput)==null||h.call(c,this),t.push(this.parent)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?((p=this.parent)==null?void 0:p.type)===n.Search||((v=this.parent)==null?void 0:v.type)===n.Loop?(this.parent.addOutputDeclaration(this),t.push(this.parent)):((P=(E=this.parent)==null?void 0:E.addOutput)==null||P.call(E,this),t.push(this.parent)):this.parentRelationType===_.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.index=e.index||(e.index!==0?this.index:0),this.required=e.required||this.required,this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ne.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ne.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l,c,h,p,v,E,P;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(w=>{const{updated:C,removed:U,added:S}=w.entity.onDetachedDependencyRemoved(this,w.field,t);r.push(...C),a.push(...U),d.push(...S)}),this.defaultValue){const{updated:w,removed:C}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...w),a.push(...C)}if(this.dataType){const{updated:w,removed:C}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...w),a.push(...C)}return e||(((l=this.parent)==null?void 0:l.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(c=this.parent)==null||c.removeOutputDeclaration(this):this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?(h=this.parent)==null||h.removeInputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):((p=this.parent)==null?void 0:p.type)===n.Loop?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.removeOutputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(E=this.parent)==null||E.removeOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){var o,l,c,h,p,v,E;const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:P}=this.defaultValue.restore({},e);r.push(...P)}if(this.dataType){const{updated:P}=this.dataType.restore({},e);r.push(...P)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(l=this.parent)==null||l.addOutputDeclaration(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((c=this.parent)==null||c.addInputDeclaration(this,e)):((h=this.parent)==null?void 0:h.type)===n.Loop?(this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn)&&((p=this.parent)==null||p.addOutputDeclaration(this)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.addOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((E=this.parent)==null||E.addInput(this)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,parent:((a=this.parent)==null?void 0:a.toReference())||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,parent:((p=this.parent)==null?void 0:p.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=hq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,P;if(Array.from(new Set([...Wr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const l=r||R.UUID.uuid(),c=this.toJSON();c.id=l,c.version=R.UUID.uuid();const h=lt(c,o);t&&h.setParent(t,null),e==null||e.add(h,b.Added),a&&h.subscribe();const p=((E=this.dataType)==null?void 0:E.clone(e,h,R.UUID.uuid(),a))||null;p&&h.setDataType(p);const v=(P=this.defaultValue)==null?void 0:P.clone(e,h,R.UUID.uuid(),a);return h.defaultValue=v||null,e==null||e.attemptAutoclose("clone-entity",this.id),h}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}};f(Ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Ne,"type",n.ValueDescriptor),f(Ne,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),f(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),f(Ne,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ne,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),f(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),f(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),f(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Fi=Ne;function mq(i,s){if(!i.type&&!i.id)return{errors:[new O({id:`last-generated-entity-payload--${I.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:D.Error,code:I.MissingTypeProperty,issue:null}),new O({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:D.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null};if(i.type){if(!i.id)return{errors:[new O({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:`Last generated entity, with type "${i.type}" is missing an 'id' property.`,severity:D.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new O({id:`${i.id}--${I.MissingTypeProperty}`,message:`Entity with id "${i.id}" is missing a 'type' property.`,severity:D.Error,code:I.MissingTypeProperty,issue:null})],modifiedData:null};if(i.type===n.GenericReference)return{errors:[new O({id:`${i.id}--${I.RootReference}`,message:`Generic reference entity with id "${i.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:D.Error,code:I.RootReference,issue:null})],modifiedData:null};const e=i,t=s.instances[e.id],r=s.builtInInstances[e.id];if(t&&!r&&e.type!==n.GenericReference){let a=`A previously generated entity with id "${e.id}" already exists in the project state.
|
|
207
|
+
${qr({describe_entity:o.error.id})}`,issue:null}))),{errors:a,modifiedData:r}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e,t,r;return(r=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||r.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o,l,c,h,p,v,E,P;const t=[this],r=[],a=[],d=[];return this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((l=this.parent)==null?void 0:l.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((h=(c=this.parent)==null?void 0:c.addInput)==null||h.call(c,this),t.push(this.parent)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?((p=this.parent)==null?void 0:p.type)===n.Search||((v=this.parent)==null?void 0:v.type)===n.Loop?(this.parent.addOutputDeclaration(this),t.push(this.parent)):((P=(E=this.parent)==null?void 0:E.addOutput)==null||P.call(E,this),t.push(this.parent)):this.parentRelationType===_.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.index=e.index||(e.index!==0?this.index:0),this.required=e.required||this.required,this.parentRelationType=e.parentRelationType||this.parentRelationType,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Ne.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Ne.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l,c,h,p,v,E,P;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(w=>{const{updated:C,removed:U,added:S}=w.entity.onDetachedDependencyRemoved(this,w.field,t);r.push(...C),a.push(...U),d.push(...S)}),this.defaultValue){const{updated:w,removed:C}=this.defaultValue.remove({ignoreUpstream:!0},t);r.push(...w),a.push(...C)}if(this.dataType){const{updated:w,removed:C}=this.dataType.remove({ignoreUpstream:!0},t);r.push(...w),a.push(...C)}return e||(((l=this.parent)==null?void 0:l.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(c=this.parent)==null||c.removeOutputDeclaration(this):this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument?(h=this.parent)==null||h.removeInputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):((p=this.parent)==null?void 0:p.type)===n.Loop?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.removeOutputDeclaration(this):this.parentRelationType===_.ReturnedError&&(this.parent.error=null):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(E=this.parent)==null||E.removeOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){var o,l,c,h,p,v,E;const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:P}=this.defaultValue.restore({},e);r.push(...P)}if(this.dataType){const{updated:P}=this.dataType.restore({},e);r.push(...P)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(l=this.parent)==null||l.addOutputDeclaration(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((c=this.parent)==null||c.addInputDeclaration(this,e)):((h=this.parent)==null?void 0:h.type)===n.Loop?(this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn)&&((p=this.parent)==null||p.addOutputDeclaration(this)):this.parentRelationType===_.FixedReturns||this.parentRelationType===_.DynamicReturn?(v=this.parent)==null||v.addOutput(this):(this.parentRelationType===_.FixedArguments||this.parentRelationType===_.DynamicArgument)&&((E=this.parent)==null||E.addInput(this)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this,...((r=this.defaultValue)==null?void 0:r.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((r=this.defaultValue)==null?void 0:r.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toJSON(e=new Set){var t,r,a;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((r=this.dataType)==null?void 0:r.toJSON(e))||null,parent:((a=this.parent)==null?void 0:a.toReference())||null})}toJSONClone(e=Z){var r,a,d,o,l,c,h,p;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((c=this.defaultValue)==null?void 0:c.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((h=this.dataType)==null?void 0:h.toJSONClone({...e,newId:null}))||null,parent:((p=this.parent)==null?void 0:p.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r,a,d,o;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((a=this.defaultValue)==null?void 0:a.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var r;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((r=this.defaultValue)==null?void 0:r.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=hq(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var E,P;if(Array.from(new Set([...Wr(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=ft(t,this);const l=r||R.UUID.uuid(),c=this.toJSON();c.id=l,c.version=R.UUID.uuid();const h=lt(c,o);t&&h.setParent(t,null),e==null||e.add(h,b.Added),a&&h.subscribe();const p=((E=this.dataType)==null?void 0:E.clone(e,h,R.UUID.uuid(),a))||null;p&&h.setDataType(p);const v=(P=this.defaultValue)==null?void 0:P.clone(e,h,R.UUID.uuid(),a);return h.defaultValue=v||null,e==null||e.attemptAutoclose("clone-entity",this.id),h}getDataType(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-data-type"))){return this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}};f(Ne,"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,...r)=>null}),f(Ne,"type",n.ValueDescriptor),f(Ne,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),f(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),f(Ne,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ne,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),f(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),f(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),f(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Fi=Ne;function mq(i,s){if(!i.type&&!i.id)return{errors:[new O({id:`last-generated-entity-payload--${I.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:D.Error,code:I.MissingTypeProperty,issue:null}),new O({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:D.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null};if(i.type){if(!i.id)return{errors:[new O({id:`last-generated-entity-payload--${I.MissingIdProperty}`,message:`Last generated entity, with type "${i.type}" is missing an 'id' property.`,severity:D.Error,code:I.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new O({id:`${i.id}--${I.MissingTypeProperty}`,message:`Entity with id "${i.id}" is missing a 'type' property.`,severity:D.Error,code:I.MissingTypeProperty,issue:null})],modifiedData:null};if(i.type===n.GenericReference)return{errors:[new O({id:`${i.id}--${I.RootReference}`,message:`Generic reference entity with id "${i.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:D.Error,code:I.RootReference,issue:null})],modifiedData:null};const e=i,t=s.instances[e.id],r=s.builtInInstances[e.id];if(t&&!r&&e.type!==n.GenericReference){let a=`A previously generated entity with id "${e.id}" already exists in the project state.
|
|
208
208
|
Are you trying to update that entity?
|
|
209
209
|
If so, you should use the 'update' action for core mutable metadata properties, or 'delete' and then 'post' again to replace it.
|
|
210
210
|
If you are trying to create a new entity, please use a different id, for example: "${yp(e,s)}".`;return{errors:[new O({id:`duplicate--${e.id}--${I.EntityIdNotUnique}`,message:a,severity:D.Error,code:I.EntityIdNotUnique,issue:null})],modifiedData:i}}else if(t&&e.type!==n.GenericReference)return{errors:[new O({id:`${e.id}--${I.EntityIdNotUnique}`,message:`A built in entity with id "${e.id}" already exists. You cannot modify built in entities. If you are trying to create a new entity, please use a different id, for example: "${yp(e,s)}".`,severity:D.Error,code:I.EntityIdNotUnique,issue:null})],modifiedData:i};switch(e.type){case n.Project:return R.validateGenerationTarget(e,s);case n.DefinitionEntity:return zi.validateGenerationTarget(e,s);case n.Property:return gi.validateGenerationTarget(e,s);case n.FunctionDeclaration:return _i.validateGenerationTarget(e,s);case n.DataType:return wn.validateGenerationTarget(e,s);case n.Operation:return Mi.validateGenerationTarget(e,s);case n.FunctionCall:return qi.validateGenerationTarget(e,s);case n.VariableDeclaration:return ji.validateGenerationTarget(e,s);case n.VariableInstance:return Ui.validateGenerationTarget(e,s);case n.GlobalEvent:return Vn.validateGenerationTarget(e,s);case n.InputMap:return kr.validateGenerationTarget(e,s);case n.OutputMap:return Zr.validateGenerationTarget(e,s);case n.ArgumentDeclaration:return Si.validateGenerationTarget(e,s);case n.ReturnDeclaration:return rr.validateGenerationTarget(e,s);case n.Loop:return Ni.validateGenerationTarget(e,s);case n.Condition:return Li.validateGenerationTarget(e,s);case n.Search:return $i.validateGenerationTarget(e,s);case n.InstalledProject:return Gi.validateGenerationTarget(e,s);case n.InternalCall:return gn.validateGenerationTarget(e,s);case n.LiteralValue:return Bn.validateGenerationTarget(e,s);case n.ReturnStatement:return Bi.validateGenerationTarget(e,s);case n.BreakStatement:return Cn.validateGenerationTarget(e,s);case n.ContinueStatement:return $t.validateGenerationTarget(e,s);case n.ActionDescriptor:return qe.validateGenerationTarget(e,s);case n.ValueDescriptor:return Fi.validateGenerationTarget(e,s);case n.BuiltInBaseEntity:case n.PrimitiveEntity:{const a="Did you mean to generate a",o={[n.BuiltInBaseEntity]:`${a} '${n.DefinitionEntity}' instead?`,[n.PrimitiveEntity]:`${a} '${n.DefinitionEntity}' instead?`}[e.type]||"";return{errors:[new O({id:`${e.id}--${I.BuiltInEntityGenerated}`,message:`Entity with id "${e.id} is of "${e.type}" type and should not be generated. Built in entities can only be referenced by user created entities.
|
|
@@ -402,7 +402,7 @@ All global 'function-declaration' entity ids are:
|
|
|
402
402
|
The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;a.push(new O({id:`${r.id}--${I.InvalidReference}`,code:I.InvalidReference,severity:D.Error,message:`Entity of type "${n.FunctionCall}" with id "${r.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
|
|
403
403
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${l}`,issue:null}))}return{errors:a,modifiedData:r}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:h,added:p,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...h),r.push(...l,...p),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=V(this.initialData.declaration,this.project);this.declaration=t}else{const t=g(this.initialData.declaration),r=this.project.get(t);this.declaration=r}return this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ke.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ke.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.process){const{updated:c,removed:h}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.outputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.error){const{updated:c,removed:h}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),error:(h=this.error)==null?void 0:h.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Vq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>!this.inputs.find(v=>v.declaration.id===p.id));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1},e)});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=V(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(U=>{U.index>=v.index&&U.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,w={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=V(w,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:h,removed:p}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...h),a.push(...p),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}};f(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(ke,"type",n.FunctionCall),f(ke,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),f(ke,"MUTABLE_BASE_PROPERTIES",[]),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"]),f(ke,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),f(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),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 qi=ke;function Cp(i){return i&&typeof i.then=="function"}class gp{constructor(s){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",Wr());f(this,"onGoingVisits",{});this.flatten(s),this.orderEntities()}flatten(s){const e=new Set(Wr()),t=u(N(s,e,{ignoreBuiltInBaseEntities:!0})),r=new Set;for(const a of t)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}moveEntityAfterDependencies(s){const{upstream:e}=qd(s,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const r=this.order.indexOf(t),a=this.order.indexOf(s.id);if(r>a)return this.order.splice(a,1),this.order.splice(r,0,s.id),!0}return!1}orderEntities(){let s=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],r=this.flatRecord[t];if(this.moveEntityAfterDependencies(r)){s=!0;break}}s&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(s,e){const{upstream:t}=qd(this.flatRecord[s],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),r={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([a,d])=>{Object.keys(t).includes(a)&&(r[a]=d)}),r}getDownstreamOngoingDependenciesVisits(s,e){const t=Object.keys(this.onGoingVisits[e]||{}),r=new Set(t.flatMap(d=>Object.keys(qd(this.flatRecord[d],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),a={};return Array.from(r).forEach(d=>{d===s&&(a[d]=this.onGoingVisits[e][d])}),a}async settlePromises(s,e){const t=Object.values(s);t.length&&await Promise.all(t),Object.keys(s).forEach(r=>{delete this.onGoingVisits[e][r]})}visit(s){const e=this.order;for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}reverseVisit(s){const e=this.order.slice().reverse();for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}async visitAsync(s){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getUpstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);Cp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(s){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getDownstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);Cp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function mO(i,s){switch(i.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=i.project.entities.filter(l=>!!l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(l=>!!l.properties.find(c=>{var h;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((h=c.getDefaultValue())==null?void 0:h.value)===!0}))){const c=e[0].properties.find(p=>p.implements&&p.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),h=c==null?void 0:c.defaultValue;if(h)h.value=!0;else if(c!=null&&c.dataType){const p=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:c==null?void 0:c.dataType.toReference()},i.project);return p.setParent(c==null?void 0:c.dataType,s),p.initChildren(s),p.addSelfToProject(s),{newEntities:[p]}}return{newEntities:[]}}const r=i.project.get(F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),a=Sd(r,"Main database",s);if(a.errors.length>0)return{newEntities:[]};const d=a.implemented.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=d==null?void 0:d.defaultValue;if(o)o.value=!0;else if(d!=null&&d.dataType){const l=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s)}return{newEntities:[a.implemented]}}}return{newEntities:[]}}function vO(i,s){return i.implements.filter(t=>t.type===n.BuiltInBaseEntity).map(t=>{switch(t.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const a=i.project.entities.filter(l=>l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(l=>!!l.properties.find(c=>{var h;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((h=c.getDefaultValue())==null?void 0:h.value)===!0}));if(!a)return{newEntities:[]};const d=i.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),o=d==null?void 0:d.defaultValue;if(d&&(d!=null&&d.dataType)&&!o){const l=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:a,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);return l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s),{newEntities:[l]}}return{newEntities:[]}}}}),{newEntities:[]}}function Sd(i,s,e,t){const r=t||R.UUID.uuid(),a={id:r,version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:s,type:n.DefinitionEntity,description:null,static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[i],x:0,y:0,parent:i.project},d=gd(a,i.project);if(d.length>0)return{errors:d,implemented:null,entitiesChanges:{new:[],updated:[],deleted:[]}};const o=mO(i,e),l=V(a,i.project);l.setParent(i.project,e),l.initChildren(e);const c=i.properties.map(v=>{const E=R.UUID.uuid(),P=v.clone(e,l,E);return P.abstract=!1,P.implements=v,P.setParent(l,e),l.addProperty(P),P}),h=i.abstractMethods.map(v=>{const E=R.UUID.uuid(),P=v.implementAsFunctionDeclaration(E),w={id:E+"-parent-ref-id",type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.DefinitionEntity},C={...P,implements:v,parent:w},U=V(C,i.project);return l.addMethod(U),U.setParent(l,e),U.initChildren(e),U.implements=v,U});a.properties=c,a.methods=h;const p=vO(l,e);return{implemented:l,errors:[],entitiesChanges:{new:[l,...o.newEntities,...p.newEntities],updated:[l],deleted:[]}}}function Bp(i,s){return s.entities.find(r=>{const a=r.properties,d=a.map(p=>p.name),o=i.every(p=>d.includes(p)),l=d.filter(p=>!i.includes(p)),c=a.every(p=>!l.includes(p.name)||!p.required);return o&&c})||null}function TO(i,s,e,t=Rt.OrDataTypeGroup){const r=[],a=[],d=[],o=[],c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:i.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:s.toReference()},h=V(c,i.project);return a.push(h),h.setParent(s,e),h.initChildren(e),h.setEntity(i),h.addSelfToProject(e),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:h}}function _p(i,s,e,t,r){var c,h,p,v,E,P,w,C;const a=[],d=[],o=[],l=[];switch(typeof i){case"string":let U=!1;const S=new Date(i);if(S instanceof Date&&!isNaN(S.valueOf())&&(U=!0),U){const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.Date].id);s.setEntity(B);break}else{const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id);s.setEntity(B);break}case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":if(i===null){s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else if(Array.isArray(i))if(s.metaSync({isList:!0},t),i.length>0){const B=i.slice(0,5).filter(k=>k!==void 0);if(B.every(k=>typeof k==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else{const k=[];let W=!1;B.forEach(ce=>{var Te,Q,se,Ht;if(Array.isArray(ce)&&(W=!0),typeof ce=="object"&&!Array.isArray(ce)&&ce!==null){const zr=Fd(ce,s.project,{...e,id:R.UUID.uuid()},t,r);zr.hasCreated&&k.push((Te=zr.changeSet)==null?void 0:Te.self),a.push(...(Q=zr.changeSet)==null?void 0:Q.updated),d.push(...(se=zr.changeSet)==null?void 0:se.added),o.push(...(Ht=zr.changeSet)==null?void 0:Ht.removed)}});const ee=u(k);if(!ee.length&&!W){B.forEach(ce=>{const Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Rt.OrDataTypeGroup,parent:s.toReference()},Q=V(Te,s.project);switch(Q.setParent(s,t),Q.initChildren(t),Q.addSelfToProject(t),typeof ce){case"string":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}});break}else ee.length===1&&!W?s.setEntity(ee[0]):B.forEach(ce=>{if(typeof ce=="object"&&!Array.isArray(ce)&&ce!==null){const Te=Bp(Object.keys(ce),s.project);if(Te){const Q=TO(Te||ee[0],s,t,Rt.OrDataTypeGroup);a.push(...Q.updated),d.push(...Q.added),o.push(...Q.removed)}}else{const Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:Array.isArray(ce),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Rt.OrDataTypeGroup,parent:s.toReference()},Q=V(Te,s.project);Q.setParent(s,t),Q.initChildren(t),Q.addSelfToProject(t);const se=_p(ce,Q,{...e,id:R.UUID.uuid()},t,r);a.push(...se.updated),d.push(...se.added),o.push(...se.removed)}})}}else{const B=Fd(i[0],s.project,{...e},t,r);s.setEntity((c=B.changeSet)==null?void 0:c.self),a.push(...(h=B.changeSet)==null?void 0:h.updated),d.push(...(p=B.changeSet)==null?void 0:p.added),o.push(...(v=B.changeSet)==null?void 0:v.removed);break}else{const B=Fd(i,s.project,{...e},t,r);s.setEntity((E=B.changeSet)==null?void 0:E.self),a.push(...(P=B.changeSet)==null?void 0:P.updated),d.push(...(w=B.changeSet)==null?void 0:w.added),o.push(...(C=B.changeSet)==null?void 0:C.removed);break}}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:s}}function Fd(i,s,e,t,r){const a=[],d=[],o=[],l=[],c=Object.keys(i),h=Bp(c,s);if(h)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:h}};const p=r?e.name+" of "+r.name:e.name,E={id:e.id||R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:p,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:s.toReference()},P=V(E,s);return P.setParent(s,t),P.initChildren(t),P.addSelfToProject(t),d.push(P),c.forEach((w,C)=>{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:w,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:C,hidden:!1,private:!1,required:!0,parent:P.toReference()},B=V(S,s);B.setParent(P,t),B.initChildren(t),B.addSelfToProject(t),d.push(B);const $=i[w],W={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},ee=V(W,s);ee.setParent(B,t),ee.initChildren(t),ee.addSelfToProject(t),d.push(ee);const ce=_p($,ee,{...e,name:w,id:R.UUID.uuid()},t,r||P);a.push(...ce.updated),d.push(...ce.added),o.push(...ce.removed)}),{hasCreated:!0,changeSet:{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:P}}}function xd(i,s){const e=_n(i);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(a=>{if(a===s)return t=a,[a];const d=xd(a,s);return d.last&&(t=d.last),[a,...d.list]}),last:t}}function EO(i,s,e=new Set){const t=Ji(i),r=Ji(s),a=t.filter(l=>!r.includes(l)),d=t.filter(l=>r.includes(l)),o=a.reduce((l,c)=>e.has(c.id)?l:(e.add(c.id),u([...l,...EO(c,s,e)])),[]);return u([...d,...o])}function Vs(i,s){const e=xd(i,s);return e.last===s&&e.list.length>0&&e.list[0]!==s}function Cq(i,s){return!!xd(i,s).last}function gq(i){if(at.includes(i.type))return i;if([...Vr,n.VariableDeclaration].includes(i.type)){const s=i.parent;return at.includes(s.type)?s:null}return null}function Mp(i,s){if(!i||!s)throw new Error("Both entities must be defined to find a common ancestor");if(i===s)return i;const e=i.parent;if(e){if(e===s)return s;if(e.type===n.Project)return null}else return null;const t=s.parent;if(t){if(t===i)return i;if(t.type===n.Project)return null}else return null;return Mp(e,t)}function wt(i){if($s.includes(i.type)){if(i.type===n.FunctionDeclaration){const s=i.parent;if(s.type===n.DefinitionEntity)return s;if(s.type===n.Loop)return s}return i}else{const s=i.parent;return s?wt(s):null}}function kd(i,s){const e=Cs(i,s);if(!e)return null;if($s.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Cs(e.parent,s);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Cs(e.parent,s):null;return t?kd(t,s):null}}function IO(i){if(!i)return null;if(Vr.includes(i.type))return i;const s=i.parent;return s?IO(s):null}function bO(i){if(!i)return null;if(nt.includes(i.type))return i;const s=i.parent;return s?bO(s):null}function RO(i){if(!i)return null;if(Cr.includes(i.type))return i;const s=i.parent;return s?RO(s):null}function Bq(i){return i.type===n.VariableDeclaration?[i]:nt.includes(i.type)?[...i.inputs,...i.outputs||[]]:st.includes(i.type)?i.outputs:jn.includes(i.type)||i.type===n.FunctionDeclaration?i.inputs:[]}function _q(i){const s=Ji(i),e=[],t=[];Hp.includes(i.type)&&e.push(...Np(i));const r=s.filter(a=>{const d=e.includes(a);return d?!1:Vr.includes(a.type)&&!d?(t.push(a),!1):!0});return e.sort((a,d)=>Vs(d,a)?-1:0),t.sort((a,d)=>Vs(d,a)?-1:0),[...e,...t,...r]}function AO(i){return[...i].sort((s,e)=>Vs(e,s)?-1:0)}function Mq(i){const s=AO(i),e=[];return s.forEach(t=>{const r=e[e.length-1];if(r){const a=r[r.length-1];Vs(t,a)?e.push([t]):r.push(t)}else e.push([t])}),e}function Yt(i){const s=i.map(e=>wt(e));return u(s)}function Np(i){return nt.includes(i.type)?[...Yt(i.successCalls),...Yt(i.errorCalls)]:at.includes(i.type)?Yt(i.calls):[]}function Nq(i,s){return Np(i).includes(s)}function Lp(i){return i.writesValues||[]}function Lq(i,s){return Lp(i).includes(s)}function DO(i){var s;return Qe.includes((s=i==null?void 0:i.readsValue)==null?void 0:s.type)?i.readsValue:null}function Uq(i){return i.writesValues}function OO(i=[]){return i.map(DO).filter(s=>!!s)}function Zd(i=[]){return i.map(s=>s.writesValues).flat().filter(s=>Qe.includes(s.type))}function PO(i=[]){return i.map(s=>s.readsValue).filter(s=>!!s&&Qe.includes(s.type))}function wO(i){return Qe.includes(i.type)?i:null}function VO(i){return i.writesValues.map(wO).filter(s=>!!s)}function CO(i=[]){return i.reduce((s,e)=>e.type===n.OutputMap?[...s,...VO(e)]:s,[])}function it(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function jq(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function gO(i,s=new Set){return i.writesValues.filter(t=>Qe.includes(t.type)&&!s.has(t.id)).reduce((t,r)=>s.has(r.id)?t:[...t,...We(r,s)],[])}function BO(i,s=new Set){var t;return(((t=i.readsValue)==null?void 0:t.writesValues)||[]).filter(r=>Qe.includes(r.type)&&!s.has(r.id)).reduce((r,a)=>s.has(a.id)?r:[...r,...We(a,s)],[])}function We(i,s=new Set){if(s.has(i.id))return[];if(i.type===n.ReturnStatement)return PO(i.outputs).reduce((t,r)=>[...t,...We(r,s)],[]);if(i.type===n.FunctionCall||i.type===n.Operation||i.type===n.Condition)return[...it(i).reduce((a,d)=>{const o=wt(d);return[...a,...We(o||d,s)]},[]),...OO(i.inputs),...CO(i.outputs)].reduce((a,d)=>[...a,...We(d,s)],[]);if(jn.includes(i.type)){const e=Zd(i.inputs),r=it(i).reduce((a,d)=>{const o=wt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d,s)],[])}if(i.type===n.FunctionDeclaration){const e=[...Zd(i.inputs)],r=it(i).reduce((a,d)=>{const o=wt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d)],[])}if(Qe.includes(i.type)){s.add(i.id);const t=it(i).reduce((r,a)=>{const d=wt(a);return[...r,...We(d||a,s)]},[]);return[i,...t,...BO(i,s),...gO(i,s)]}return[]}function ir(i,s=new Set){return s.has(i.id)?[]:(s.add(i.id),[...Ji(i).reduce((r,a)=>[...r,a,...ir(a,s)],[])])}function Jr(i){return i.reduce((s,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...s,e]:[...s,e,...it(e)],[])}function _O(i){const s=i.entities||[],e=[...s,...i.functions||[],...i.events||[],...i.projects||[]],t=s.reduce((l,c)=>[...l,...c.properties],[]),r=s.reduce((l,c)=>[...l,...c.methods],[]),a=r.reduce((l,c)=>[...l,...Zd(c.inputs),...Jr(Yt(c.calls)),...c.returnStatements],[]),d=i.functions.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]),o=i.events.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]);return[...e,...t,...r,...a,...d,...o]}function MO(i,s){return s.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(r=>r.id===i.id)!==void 0||t.outputs.find(r=>r.id===i.id)!==void 0;case n.Condition:return t.successCalls.find(r=>r.id===i.id)!==void 0||t.errorCalls.find(r=>r.id===i.id)!==void 0||t.inputs.find(r=>r.id===i.id)!==void 0;case n.Operation:return t.outputs.find(r=>r.id===i.id)!==void 0;case n.VariableDeclaration:return nt.includes(i.type)?oP(i).find(a=>{var d;return((d=a.readsValue)==null?void 0:d.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(r=>r.id===i.id)!==void 0||t.methods.find(r=>r.id===i.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(r=>r.id===i.id)!==void 0||(t.returnStatements.map(r=>r.outputs).flat()||[]).find(r=>r.id===i.id)!==void 0;default:return!1}})}function $q(i){const s=_O(i.project);return MO(i,s)}function Cs(i,s){return i?typeof i=="string"?s[i]:i.type===n.GenericReference?s[i.entityId]:s[i.id]?s[i.id]:null:null}function qd(i,s={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||(e.allBuiltInEntityIds||[]).includes(i.id)))return{upstream:{},downstream:{}};const t=i,r=i,a=i,d=i,o=i,l=i,c=i,h=i,p=i,v=i,E=i,P=i,w=i,C=[...w.readsValue?[w.readsValue]:[],...w.declaration?[w.declaration]:[],...(P.calledByEntry||[]).flatMap($=>$),...(P.calledBySuccess||[]).flatMap($=>$),...(P.calledByError||[]).flatMap($=>$),...(a.extends||[]).flatMap($=>$),...v.parent?[v.parent]:[]];Array.isArray(a.implements)?C.push(...a.implements.flatMap($=>$)):p.implements&&C.push(p.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&C.push(...o.valueAsTypeList.flatMap($=>$)),o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const U=[...(t.inputs||[]).flatMap($=>$),...(E.inputsDeclarations||[]).flatMap($=>$),...(t.outputs||[]).flatMap($=>$),...(E.outputsDeclarations||[]).flatMap($=>$),...(w.internalCalls||[]).flatMap($=>$),...w.writesValues||[],...P.dataType?[P.dataType]:[],...l.body?[l.body]:[],...P.defaultValue?[P.defaultValue]:[],...(P.successCalls||[]).flatMap($=>$),...(P.errorCalls||[]).flatMap($=>$),...(a.properties||[]).flatMap($=>$),...(a.methods||[]).flatMap($=>$),...(a.abstractMethods||[]).flatMap($=>$),...c.error?[c.error]:[],...c.process?[c.process]:[],...v.throws?[v.throws]:[],...(r.andChildrenGroup||[]).flatMap($=>$),...(r.orChildrenGroup||[]).flatMap($=>$),...(h.entities||[]).flatMap($=>$),...(h.functions||[]).flatMap($=>$),...(h.functionCalls||[]).flatMap($=>$),...(h.events||[]).flatMap($=>$),...(h.conditions||[]).flatMap($=>$),...(h.operations||[]).flatMap($=>$),...(h.loops||[]).flatMap($=>$),...(h.variableDeclarations||[]).flatMap($=>$),...(h.variableInstances||[]).flatMap($=>$),...(h.searches||[]).flatMap($=>$),...(h.projects||[]).flatMap($=>$),...(d.calls||[]).flatMap($=>$)];i.type===n.DataType&&(r.entity&&s[g(r.entity)]&&s[g(r.entity)].parent&&g(s[g(r.entity)].parent)===i.id?U.push(r.entity):r.entity&&C.push(r.entity));const S={},B={};return C.forEach($=>{const k=g($);if(k&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(k)))return;const W=$.version;k&&(S[k]=W)}),U.forEach($=>{const k=g($);if(k&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(k)))return;const W=$.version;k&&(B[k]=W)}),{upstream:S,downstream:B}}function Gq(i,s){const e=[];if(Vr.includes(i.type)){pr(i).forEach(a=>{const d=kd(a,s);d&&e.push(d)});const r=[...i.inputs||[],...i.outputs||[]].map(a=>{const d=Cs(a,s);return d?lP(d,s):null}).filter(a=>a!==null);e.push(...u(r))}if(Qe.includes(i.type)){const t=Jd(i);t&&e.push(t)}return u(e)}function _n(i){const s=[];if(Vr.includes(i.type)){i.calledBy.forEach(r=>{const a=wt(r);a&&s.push(a)});const t=[...i.inputs||[],...i.outputs||[]].map(r=>Jd(r)).filter(r=>r!==null);s.push(...u(t))}if(Qe.includes(i.type)){const e=Jd(i);e&&s.push(e)}return u(s)}function pr(i){return[...i.calledByEntry||[],...i.calledByError||[],...i.calledBySuccess||[]].filter(s=>s.type!==n.GenericReference)}function NO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[i,...i.inputs.flatMap(t=>N(t,s,e)),...i.outputs.flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.parent?N(i.parent,s,e):[]]}function LO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s):[],...i.writesValues.flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function UO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function jO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...(i.extends||[]).flatMap(t=>N(t,s,e))]}function $O(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function GO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function SO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[i,...(i.extends||[]).flatMap(t=>N(t,s,e)),...(i.implements||[]).flatMap(t=>N(t,s,e)),...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function FO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[i,...(i.andChildrenGroup||[]).flatMap(t=>N(t,s,e)),...(i.orChildrenGroup||[]).flatMap(t=>N(t,s,e)),...i.entity?N(i.entity,s,e):[],...i.parent?N(i.parent,s,e):[]]}function xO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function kO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function ZO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function qO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function JO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[i,...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function WO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.parent?N(i.parent,s,e):[]]}function YO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[i,...i.valueAsTypeSingle?N(i.valueAsTypeSingle,s,e):[],...i.valueAsTypeList&&Array.isArray(i.valueAsTypeList)?i.valueAsTypeList.flatMap(t=>N(t,s,e)):[],...i.parent?N(i.parent,s,e):[]]}function zO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.body?N(i.body,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function HO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function KO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[i,...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function XO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e))]}function QO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[i,...(i.entities||[]).flatMap(t=>N(t,s,e)),...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.variableDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.variableInstances||[]).flatMap(t=>N(t,s,e)),...(i.operations||[]).flatMap(t=>N(t,s,e)),...(i.conditions||[]).flatMap(t=>N(t,s,e)),...(i.functionCalls||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.loops||[]).flatMap(t=>N(t,s,e)),...(i.searches||[]).flatMap(t=>N(t,s,e))]}function eP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function tP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function rP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[i,...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function iP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function nP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function aP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function sP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.parent?N(i.parent,s,e):[]]}function Wr(){const i=new Set;return YE.flatMap(e=>N(e,i)).map(e=>e.id)}function N(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!i)throw new Error("Entity must be defined to be flattened");if(i.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||Wr().includes(i.id)))return[];if(s.has(i.id))return[];switch(i.type){case n.FunctionCall:return xO(i,s,e);case n.Operation:return HO(i,s,e);case n.Condition:return $O(i,s,e);case n.Loop:return zO(i,s,e);case n.Search:return iP(i,s,e);case n.GlobalEvent:return ZO(i,s,e);case n.ReturnStatement:return rP(i,s,e);case n.ContinueStatement:return GO(i,s,e);case n.BreakStatement:return UO(i,s,e);case n.VariableDeclaration:return aP(i,s,e);case n.DefinitionEntity:return SO(i,s,e);case n.FunctionDeclaration:return kO(i,s,e);case n.Project:return QO(i,s,e);case n.ActionDescriptor:return NO(i,s,e);case n.ArgumentDeclaration:return LO(i,s,e);case n.ReturnDeclaration:return tP(i,s,e);case n.ValueDescriptor:return nP(i,s,e);case n.InputMap:return qO(i,s,e);case n.OutputMap:return KO(i,s,e);case n.DataType:return FO(i,s,e);case n.InstalledProject:return JO(i,s,e);case n.InternalCall:return WO(i,s,e);case n.LiteralValue:return YO(i,s,e);case n.Property:return eP(i,s,e);case n.VariableInstance:return sP(i,s,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:jO(i,s,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:XO(i,s,e)}return[]}function Up(i){return i.type===n.FunctionCall||i.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.inputs:i.type===n.FunctionDeclaration||jn.includes(i.type)?i.inputs:i.type===n.Search?i.inputsDeclarations:[]}function Sq(i,s){return s.type===n.Condition?s.inputs.find(e=>e.declaration.id===i.id):s.type===n.FunctionCall||s.type===n.Operation?s.inputs.find(e=>e.declaration.id===i.id):null}function oP(i){return nt.includes(i.type)?i.inputs:[]}function dP(i){var s;return i.type===n.FunctionCall?((s=i.declaration.returnStatements[0])==null?void 0:s.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.outputs:i.type===n.Search?i.outputsDeclarations:st.includes(i.type)?i.outputs:[]}function Fq(i,s){return s.type===n.Condition?null:s.type===n.FunctionCall||s.type===n.Operation?s.outputs.find(e=>e.declaration.id===i.id):null}function xq(i){return i.type===n.Condition?[]:nt.includes(i.type)?i.outputs:[]}function Jd(i){const s=i.readsValue;return s?wt(s):null}function lP(i,s){const e=i.readsValue;return e?kd(e,s):null}function uP(i){const s=i.internalCalls||[];return u(Yt(u(s.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Ra(i){const s=Lp(i),e=[];return s.forEach(t=>{if(Qe.includes(t.type))e.push(t);else if(hi.includes(t.type)){const r=t.parent;e.push(r)}}),e}function u(i){const s=new Set;return i.filter(e=>!e||s.has(e.id)?!1:(s.add(e.id),!0))}function Ji(i,s=!1){const e=[];if(i.type===n.Project&&e.push(...(i==null?void 0:i.entities)||[],...(i==null?void 0:i.functions)||[],...(i==null?void 0:i.variableDeclarations)||[],...(i==null?void 0:i.variableInstances)||[],...(i==null?void 0:i.searches)||[],...(i==null?void 0:i.loops)||[],...(i==null?void 0:i.operations)||[],...(i==null?void 0:i.conditions)||[],...(i==null?void 0:i.functionCalls)||[],...(i==null?void 0:i.events)||[],...(i==null?void 0:i.projects)||[]),mt.includes(i.type)&&e.push(...(i==null?void 0:i.detachedChildren)||[]),i.type===n.DefinitionEntity){const t=[...i.suggestedMethods,...i.methods].flatMap(r=>r.collapsed&&s?[]:Ji(r));e.push(...t)}if(i.type===n.Condition){const t=i.successCalls.map(a=>wt(a)),r=i.errorCalls.map(a=>wt(a));e.push(...t,...r)}if(jn.includes(i.type)){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>wt(a));e.push(...u(t),...r)}if(nt.includes(i.type)&&i.type!==n.Condition&&i.type!==n.Loop){const t=i==null?void 0:i.outputs.map(d=>Ra(d)).flat(),r=i.successCalls.map(d=>wt(d)),a=i.errorCalls.map(d=>wt(d));e.push(...u(t),...r,...a)}if(Qe.includes(i.type)){const t=Ra(i),r=uP(i);e.push(...t,...r)}if(i.type===n.Loop){const t=i.outputs.map(d=>Ra(d)).flat();if(i.body){const d=Ji(i.body,s);e.push(...d)}const r=i.errorCalls.map(d=>wt(d)),a=i.successCalls.map(d=>wt(d));e.push(...u(t),...a,...r)}if(i.type===n.FunctionDeclaration){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>wt(a));e.push(...u(t),...r)}return u(e)}function cP(i,s=!1){const e=Ji(i,s),t=[...e,...e.reduce((r,a)=>[...r,...cP(a,s)],[])];return u(t)}function pP(i){const s=_n(i),e=[...s,...s.reduce((t,r)=>[...t,...pP(r)],[])];return u(e)}function Wd(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Wd(e),...Yd(e)]:[...s,e.name],[])}function Yd(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Yd(e),...Wd(e)]:[...s,e.name],[])}function jp(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...jp(e),...$p(e)]:[...s,e],[])}function $p(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...$p(e),...jp(e)]:[...s,e],[])}function Gp(i){return[...Yd(i),...Wd(i)].filter((e,t,r)=>r.indexOf(e)===t)}function fP(i){return i.implements.length===0&&i.extends.length===0?null:i.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===z.PERSISTED_ENTITY)?i:[...i.implements,...i.extends].reduce((t,r)=>{if(r.type===n.DefinitionEntity){const a=fP(r);if(a)return a}return t},null)}function kq(i){const s=i.extends.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function Zq(i){const s=i.implements.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function Sp(i){const s=i.extends.find(e=>e.type===n.DefinitionEntity);return s&&s.type===n.DefinitionEntity?s:null}function Wi(i){const s=[...i.implements,...i.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...Wi(t)]:e,[]);return u(s)}function Fp(i){return i.type===n.PrimitiveEntity?!0:i.type===n.BuiltInBaseEntity?i.interactive:!Wi(i).find(t=>!t.interactive)}function qq(i){return i.parent===i.project&&i.project.variableDeclarations.includes(i)}function xp(i){return i.parent!==i.project?!1:n.VariableDeclaration===i.type?i.project.variableDeclarations.includes(i):n.VariableInstance===i.type?i.project.variableInstances.includes(i):n.FunctionCall===i.type?i.project.functionCalls.includes(i):n.Condition===i.type?i.project.conditions.includes(i):n.Operation===i.type?i.project.operations.includes(i):n.Loop===i.type?i.project.loops.includes(i):n.Search===i.type?i.project.searches.includes(i):!1}function yP(i){if([...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||xp(i))return!1;const s=_n(i);return s.length===0?!0:s.some(e=>yP(e))}function kp(i){return[...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||xp(i)?!1:_n(i).length===0}function hP(i,s=0){if(kp(i)){const e=_n(i);return e.length===0?i:e.map(r=>hP(r,s+1)).reduce((r,a)=>r?a&&a.x<r.x?a:r:a,null)}return null}function mP(i){const s=[];if(kp(i))s.push(i);else return[];return _n(i).forEach(t=>{s.push(...mP(t))}),s}function vP(i){return i.type===n.FunctionDeclaration&&i.parent!==i.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(i.parent.type)}function Jq(i,s){const e=new Map;return i.forEach(t=>{e.set(t.id,t)}),s.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function gs(i){switch(i){case n.DefinitionEntity:return zi;case n.FunctionDeclaration:return _i;case n.VariableDeclaration:return ji;case n.VariableInstance:return Ui;case n.FunctionCall:return qi;case n.Operation:return Mi;case n.Condition:return Li;case n.ReturnStatement:return Bi;case n.Loop:return Ni;case n.Search:return $i;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.ArgumentDeclaration:return Si;case n.ReturnDeclaration:return rr;case n.Property:return gi;case n.InstalledProject:return Gi;case n.Project:return R;case n.BuiltInBaseEntity:return Yr;default:return null}}function zt(i,s){if(mt.includes(i.type))return i;if(hr.includes(i.type))return null;const e=i.parent;if(!e)return null;if(e.type===n.GenericReference){const t=g(e);if(!t)return null;const r=s.get(t);return r?zt(r,s):null}else return e===s?s:zt(e,s)}function Zp(i,s){if(hr.includes(i.type)||s.getBuiltIn(i.id))return null;const e=nr(i.parent,s);return e?e===s?mt.includes(i.type)?i:null:e.type===n.DefinitionEntity?i:Zp(e,s):null}function zd(i,s,e){if(i===s||s===e||i===e)return!1;const t=zt(s.parent,e);return t===i?!0:zd(t,s,e)}var Hd=(i=>(i.SameBothLocal="same-both-local",i.AInB="a-in-b",i.BInA="b-in-a",i.ParallelInCommonParent="parallel-in-common-parent",i.ParallelInProject="parallel-in-project",i.AIsGlobalBIsNot="a-is-global-b-is-not",i.BIsGlobalAIsNot="b-is-global-a-is-not",i.SameBothGlobal="same-both-global",i))(Hd||{});function Bs(i,s,e){const t=zt(i,e),r=zt(s,e);if(!t)throw new Error("Could not find scope owner for the entity: "+i.id);if(!r)throw new Error("Could not find scope owner for the entity: "+s.id);if(t===r&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===r&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&r.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&r.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:r};if(zd(t,r,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(zd(r,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:r};const o=Mp(t,r);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:zt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function TP(i,s,e){const t=Bs(i,s,e);if(!t.compatible||t.type!=="same-both-local")return null;if(i===s)return i;let r=zt(i.parent,e);if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;for(;r;){if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;r=zt(r.parent,e)}let a=zt(s.parent,e);if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;for(;a;){if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;a=zt(a.parent,e)}return null}function EP(i){return i.length===0?null:i.length===1?i[0]:i.reduce((e,t)=>{const r=TP(e,t,t.project);return!r||r===t?e:t},i[0])}function nr(i,s){if(!i)return null;let e;return typeof i=="string"?e=i:i.type===n.GenericReference?e=g(i):e=i.id,e===s.id?s:s.get(e)}function Yi(i){if(!i)return null;if(hr.includes(i.type))return i;if(i.type===n.Project)return null;if(i.project.getBuiltIn(i.id))return i;const s=i.parent;return!s||s.type===n.Project?null:Yi(s)}function Wq(i,s){var e;if(i.readsValue){const t=nr(i.readsValue,s.project);s.setValueWriter(t),t.addValueReader(s)}else i.readsValue===null&&((e=s.readsValue)==null||e.removeValueReader(s),s.readsValue=null);return s}function _s(i){const s=[];function e(a,d){return s.some(o=>o.blockedByCaller===a&&o.blockedByCalling===d)}function t(a,d){e(a,d)||s.push({blockedByCaller:a,blockedByCalling:d})}const r=Zp(i,i.project);return i.calledBySuccess.forEach(a=>{[...a.successCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(p=>p===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=_s(o);l.reachable||it(i).find(p=>p===a)||l.blocks.forEach(p=>{t(a,p.blockedByCalling)})}}),i.calledByError.forEach(a=>{[...a.errorCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(p=>p===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=_s(o);l.reachable||it(i).find(p=>p===a)||l.blocks.forEach(p=>{t(a,p.blockedByCalling)})}}),i.calledByEntry.forEach(a=>{if([...a.calls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(p=>p===l)||t(a,l))}),a===r)return;let o;if(a.type===n.FunctionDeclaration){const l=wt(a);if(l.type===n.DefinitionEntity)return;l.type===n.Loop&&(o=l)}if(o){const l=_s(o);l.reachable||l.blocks.forEach(c=>{t(a,c.blockedByCalling)})}}),{reachable:s.length===0,entryPoint:r,blocks:s}}function Yq(i){return $s.includes(i.type)?i.type===n.FunctionDeclaration?!vP(i):!0:!1}function zq(i){if(n.ActionDescriptor===i.type){if(i.project.operationDeclarations.find(a=>a.id===i.id))return n.Operation;if(i.project.globalEventActionDescriptors.find(a=>a.id===i.id))return n.GlobalEvent;if(i.project.loopDeclarations.find(a=>a.id===i.id))return n.Loop;if(i.project.conditionDeclarations.find(a=>a.id===i.id))return n.Condition}return i.type}function Aa(i,s){if(i.type!==n.DefinitionEntity||i.abstract)return!1;const e=Sp(i)||i;return!!Gp(e).includes(s)}function Hq(i){const s=[];return i.entities.forEach(e=>{if(Aa(e,z.PERSISTED_ENTITY)){s.push(e);return}}),u(s)}function Kq(i){const s=[];return i.entities.forEach(e=>{if(Aa(e,z.RELATIONAL_DATABASE)){s.push(e);return}}),u(s)}function Xq(i){return i.type!==n.DefinitionEntity||i.abstract||!Aa(i,z.PERSISTED_ENTITY)?null:(i==null?void 0:i.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===F[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function Qq(i){if(i.type!==n.DefinitionEntity)return[];if(i.abstract)return[];if(!Aa(i,z.PERSISTED_ENTITY))return[];const s=[],e=i.properties.filter(t=>{var r;return((r=t.implements)==null?void 0:r.id)!==F[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return s.push(...e),s}function eJ(i){var e;if(!i||i.type!==n.DefinitionEntity||!Aa(i,z.PERSISTED_ENTITY))return null;const s=i.properties.find(t=>{var r;return((r=t.implements)==null?void 0:r.id)===F[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id});return(e=s==null?void 0:s.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function ft(i,s){var t;if(!Xp.includes(s.type)||!i)return s.project||null;let e=s.project;return i.type===n.Project?e=i:((t=s.project)==null?void 0:t.id)!==i.project.id&&(e=i.project),e}function tJ(i){switch(i){case n.Project:return R;case n.InstalledProject:return Gi;case n.DefinitionEntity:return zi;case n.FunctionDeclaration:return _i;case n.GlobalEvent:return Vn;case n.VariableInstance:return Ui;case n.VariableDeclaration:return ji;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.Condition:return Li;case n.Operation:return Mi;case n.FunctionCall:return qi;case n.ReturnDeclaration:return rr;case n.ArgumentDeclaration:return Si;case n.PrimitiveEntity:return fr;case n.DataType:return wn;case n.Property:return gi;case n.ActionDescriptor:return qe;case n.ReturnStatement:return Bi;case n.ContinueStatement:return $t;case n.BreakStatement:return Cn;case n.Loop:return Ni;case n.Search:return $i;case n.ValueDescriptor:return Fi;case n.InternalCall:return gn;case n.LiteralValue:return Bn}return null}function rJ(i){const s={added:{},updated:{},removed:[],affected:[],seenEntities:[],self:i==null?void 0:i.self};return i==null||i.added.forEach(e=>{s.added[e.id]=e}),i==null||i.updated.forEach(e=>{s.updated[e.id]=e}),s.removed=Array.from(new Set(i==null?void 0:i.removed.map(e=>e.id))),s}function dt(i,s){const e=gs(i.type);return e?!e.MUTABLE_META_PROPERTIES.every(r=>{const a=i[r],d=s[r];return d===void 0||a===d?!0:Array.isArray(a)&&Array.isArray(d)?a.length!==d.length?!1:a.every((o,l)=>o===d[l]):!1}):!1}function Kd(i,s={}){if(i.type===n.Project)return[];if(!i.parent)return[];const e=g(i.parent);if(!e)return[];const t=s[e];return t?[t.id,...Kd(t,s)]:[]}function iJ(i,s){const e=[];if(i.parent)if(i.id===i.parent)e.push(new O({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=s.get(i.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new O({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new O({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return i.implements&&Array.isArray(i.implements)?i.implements.forEach(t=>{if(i.id===t){e.push(new O({id:`${i.id}--${t}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract||e.push(new O({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new O({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' property that isn't an array.`,issue:null})),i.extends&&Array.isArray(i.extends)&&i.extends.forEach(t=>{const r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract&&e.push(new O({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var IP=(i=>(i.Extends="extends",i.Implements="implements",i))(IP||{});const Le=class Le extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const c=g(e.parent);r=t.get(c)}const a=[];e.implements&&e.implements.forEach(c=>{a.push(t.get(c)||t.getBuiltIn(c))});const d=[];e.extends&&e.extends.forEach(c=>{d.push(t.get(c)||t.getBuiltIn(c))});const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:d,implements:a,x:0,y:0,parent:r},l=V(o,t);return l.setParent(r,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=iJ(r,t),o=gd(r,t);a.push(...d,...o,...ot(r));const l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DataType){const c=l;c.entity&&a.push(new O({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.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 '${c.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
405
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="parent"){const{updated:c,added:h,removed:p}=this.remove({ignoreUpstream:!1},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];if(t==="declaration"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}if(t==="parent"){const{updated:c,added:h,removed:p}=this.restore({},r);a.push(...c),d.push(...h),o.push(...p)}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}if(this.initialData.declaration){const d=g(this.initialData.declaration),o=this.project.get(d);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addEntryCaller(l,null),e.push(l))}),this.initialData.calledBySuccess.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addSuccessCaller(l,null),e.push(l))}),this.initialData.calledByError.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addErrorCaller(l,null),e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c}=this.syncMissingFixedInputs(e),{updated:h,added:p,removed:v}=this.syncMissingFixedOutputs(e);return t.push(...o,...h),r.push(...l,...p),a.push(...c,...v),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],r=[],a=[],d=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(l=>{l.setValueWriter(this.process),t.push(l)}),this.successCalls.forEach(l=>{l.addSuccessCaller(this,e),t.push(l)}),this.errorCalls.forEach(l=>{l.addErrorCaller(this,e),t.push(l)}),this.calledBySuccess.forEach(l=>{l.addSuccessCall(this),t.push(l)}),this.calledByError.forEach(l=>{l.addErrorCall(this),t.push(l)}),this.calledByEntry.forEach(l=>{l.addCall(this),t.push(l)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e){const t=this.inputs.findIndex(r=>r.id===e.id);return t>-1&&this.inputs.splice(t,1),this}addInput(e){return this.inputs.includes(e)?this:(this.inputs.push(e),this)}addOutput(e){return this.outputs.includes(e)?this:(this.outputs.push(e),this)}removeOutput(e){const t=this.outputs.findIndex(r=>r.id===e.id);return t>-1&&this.outputs.splice(t,1),this}addValueReader(e){var t;return(t=this.process)==null||t.addValueReader(e),this}removeValueReader(e){var t;return(t=this.process)==null||t.removeValueReader(e),this}addSuccessCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-success-caller"))){return this.calledBySuccess.find(r=>r.id===e.id)||(this.calledBySuccess.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-success-caller",this.id)),this}addErrorCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-error-caller"))){return this.calledByError.find(r=>r.id===e.id)||(this.calledByError.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-entry-caller"))){return this.calledByEntry.find(r=>r.id===e.id)||(this.calledByEntry.push(e),t&&(t==null||t.add(this,b.Updated),t==null||t.add(e,b.Affected)),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e){return this.errorCalls.find(t=>t.id===e.id)||this.errorCalls.push(e),this}addSuccessCall(e){return this.successCalls.find(t=>t.id===e.id)||this.successCalls.push(e),this}removeCall(e){const t=this.successCalls.findIndex(a=>a.id===e.id);t>-1&&this.successCalls.splice(t,1);const r=this.errorCalls.findIndex(a=>a.id===e.id);return r>-1&&this.errorCalls.splice(r,1),this}removeCaller(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-caller"))){return this.calledBySuccess=this.calledBySuccess.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByError=this.calledByError.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(r=>r.id!==e.id?(t&&(t==null||t.add(this,b.Updated),t==null||t.add(r,b.Affected)),!0):!1),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=V(this.initialData.declaration,this.project);this.declaration=t}else{const t=g(this.initialData.declaration),r=this.project.get(t);this.declaration=r}return this.successCalls=this.initialData.successCalls.map(t=>{const r=V(t,this.project);return r.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.errorCalls=this.initialData.errorCalls.map(t=>{const r=V(t,this.project);return r.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(r.type)?(r.setParent(this.parent.parent,null),r.initChildren(e)):r.type!==n.InternalCall&&(r.setParent(this.parent,null),r.initChildren(e)),r}),this.inputs=this.initialData.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await ke.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){var l;const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(c=>{const{updated:h,removed:p,added:v}=c.entity.onDetachedDependencyRemoved(this,c.field,t);r.push(...h),a.push(...p),d.push(...v)}),this.process){const{updated:c,removed:h}=(l=this.process)==null?void 0:l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}if(this.inputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.outputs.forEach(c=>{const{updated:h,removed:p}=c.remove({ignoreUpstream:!0},t);r.push(...h),a.push(...p)}),this.error){const{updated:c,removed:h}=this.error.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}return this.successCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),this.errorCalls.forEach(c=>{r.push(c),c.removeCaller(this)}),e||this.calledBy.forEach(c=>{r.push(c),c.removeCall(this)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);r.push(...o)}return this.inputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.outputs.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.successCalls.forEach(o=>{r.push(o),o.addSuccessCaller(this)}),this.errorCalls.forEach(o=>{r.push(o),o.addErrorCaller(this)}),this.calledBySuccess.forEach(o=>{r.push(o),o.addSuccessCall(this)}),this.calledByError.forEach(o=>{r.push(o),o.addErrorCall(this)}),this.calledByEntry.forEach(o=>{r.push(o),o.addCall(this)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(r=>r.toFlat(e)),...this.errorCalls.flatMap(r=>r.toFlat(e)),...this.inputs.flatMap(r=>r.toFlat(e)),...this.outputs.flatMap(r=>r.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(r=>r.toFlatIds(e)),...this.errorCalls.flatMap(r=>r.toFlatIds(e)),...this.inputs.flatMap(r=>r.toFlatIds(e)),...this.outputs.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){var t,r;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(a=>a.toJSON(e)),errorCalls:this.errorCalls.map(a=>a.toJSON(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference()),calledByError:this.calledByError.map(a=>a.toReference()),calledByEntry:this.calledByEntry.map(a=>a.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(a=>a.toJSON(e)),outputs:this.outputs.map(a=>a.toJSON(e)),parent:this.parent.toReference(),error:(r=this.error)==null?void 0:r.toJSON(e)})}toJSONClone(e=Z){var r,a,d,o,l,c,h;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(p=>p.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(p=>p.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(p=>p.toReference({seenEntityMaps:e.seenEntityMaps})),process:(c=this.process)==null?void 0:c.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(p=>p.toJSONClone({...e,newId:null})),outputs:this.outputs.map(p=>p.toJSONClone({...e,newId:null})),error:(h=this.error)==null?void 0:h.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(a=>a.toReference(e)),outputs:this.outputs.map(a=>a.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(a=>a.toReference(e)),errorCalls:this.errorCalls.map(a=>a.toReference(e)),calledBySuccess:this.calledBySuccess.map(a=>a.toReference(e)),calledByError:this.calledByError.map(a=>a.toReference(e)),calledByEntry:this.calledByEntry.map(a=>a.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(r=>r.toFlatJSON(e)),...this.errorCalls.flatMap(r=>r.toFlatJSON(e)),...this.inputs.flatMap(r=>r.toFlatJSON(e)),...this.outputs.flatMap(r=>r.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.inputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.outputs.flatMap(r=>r.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(r=>r.clearErrors()),this.outputs.forEach(r=>r.clearErrors()),this.successCalls.forEach(r=>r.clearErrors()),this.errorCalls.forEach(r=>r.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Vq(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var P,w;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.inputs=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t?p.setParent(t,null):p.setParent(this.parent,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(P=this.inputs)==null?void 0:P.map((C,U)=>C.clone(e,p,h+"-input-map-"+U+"-id",a));p.inputs=v;const E=(w=this.outputs)==null?void 0:w.map((C,U)=>C.clone(e,p,h+"-output-map-"+U+"-id",a));return p.outputs=E,this.error&&(p.error=this.error.clone(e,p,h+"-error-map-id",a)),this.process&&(p.process=this.process.clone(e,p,h+"-process-id",a)),e==null||e.attemptAutoclose("clone-entity",this.id),p}removeUnrecognizedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],r=[],a=[],d=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],r=[],a=[],d=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(c=>{var h;return c.id===((h=o.declaration)==null?void 0:h.id)})){const c=o.remove({ignoreUpstream:!1},e);a.push(...c.removed),t.push(...c.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],r=[],a=[],d=[],o=this.declaration.inputs.filter(p=>!this.inputs.find(v=>v.declaration.id===p.id));this.inputs.sort((p,v)=>p.index-v.index),o.forEach(p=>{this.inputs.forEach(P=>{P.index>=p.index&&P.metaSync({index:P.index+1},e)});const v={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.InputMap,declaration:p.toJSON(),readsValue:null,defaultValue:null,index:p.index,name:null,description:null,parent:this.toReference()},E=V(v,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,b.Added),E.addSelfToProject(e),r.push(E)}),this.inputs.sort((p,v)=>p.index-v.index);const{updated:l,added:c,removed:h}=this.removeUnrecognizedInputs(e);return t.push(...l),r.push(...c),a.push(...h),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],r=[],a=[],d=[],o=[];this.outputs=this.initialData.outputs.map(v=>{const E=V(v,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const l=this.declaration.getUniqueReturnDeclarations().filter(v=>!this.outputs.find(E=>E.declaration.id===v.id));this.outputs.sort((v,E)=>v.index-E.index),l.forEach((v,E)=>{this.outputs.forEach(U=>{U.index>=v.index&&U.index++});const P=o.includes(v.index)?this.outputs.length-1+E:v.index,w={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.OutputMap,declaration:v.toJSON(),defaultValue:null,writesValues:[],index:P,parent:this.toReference()},C=V(w,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,b.Added),C.addSelfToProject(e)}),this.outputs.sort((v,E)=>v.index-E.index);const{updated:c,added:h,removed:p}=this.removeUnrecognizedOutputs(e);return t.push(...c),r.push(...h),a.push(...p),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),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,...r)=>null}),f(ke,"type",n.FunctionCall),f(ke,"USER_MANAGED_PARENT_TYPES",[...mt,n.Project]),f(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),f(ke,"MUTABLE_BASE_PROPERTIES",[]),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"]),f(ke,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),f(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),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 qi=ke;function Cp(i){return i&&typeof i.then=="function"}class gp{constructor(s){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",Wr());f(this,"onGoingVisits",{});this.flatten(s),this.orderEntities()}flatten(s){const e=new Set(Wr()),t=u(N(s,e,{ignoreBuiltInBaseEntities:!0})),r=new Set;for(const a of t)this.flatRecord[a.id]=a,r.add(a.id);this.order=Array.from(r)}moveEntityAfterDependencies(s){const{upstream:e}=qd(s,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const r=this.order.indexOf(t),a=this.order.indexOf(s.id);if(r>a)return this.order.splice(a,1),this.order.splice(r,0,s.id),!0}return!1}orderEntities(){let s=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],r=this.flatRecord[t];if(this.moveEntityAfterDependencies(r)){s=!0;break}}s&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(s,e){const{upstream:t}=qd(this.flatRecord[s],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),r={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([a,d])=>{Object.keys(t).includes(a)&&(r[a]=d)}),r}getDownstreamOngoingDependenciesVisits(s,e){const t=Object.keys(this.onGoingVisits[e]||{}),r=new Set(t.flatMap(d=>Object.keys(qd(this.flatRecord[d],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),a={};return Array.from(r).forEach(d=>{d===s&&(a[d]=this.onGoingVisits[e][d])}),a}async settlePromises(s,e){const t=Object.values(s);t.length&&await Promise.all(t),Object.keys(s).forEach(r=>{delete this.onGoingVisits[e][r]})}visit(s){const e=this.order;for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}reverseVisit(s){const e=this.order.slice().reverse();for(const t of e)s(this.flatRecord[t],this.flatRecord);return this}async visitAsync(s){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getUpstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);Cp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(s){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const r of e){const a=this.getDownstreamOngoingDependenciesVisits(r,t);Object.keys(a).length&&await this.settlePromises(a,t);const d=s(this.flatRecord[r],this.flatRecord);Cp(d)&&(this.onGoingVisits[t][r]=d)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function mO(i,s){switch(i.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=i.project.entities.filter(l=>!!l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(l=>!!l.properties.find(c=>{var h;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((h=c.getDefaultValue())==null?void 0:h.value)===!0}))){const c=e[0].properties.find(p=>p.implements&&p.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),h=c==null?void 0:c.defaultValue;if(h)h.value=!0;else if(c!=null&&c.dataType){const p=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:c==null?void 0:c.dataType.toReference()},i.project);return p.setParent(c==null?void 0:c.dataType,s),p.initChildren(s),p.addSelfToProject(s),{newEntities:[p]}}return{newEntities:[]}}const r=i.project.get(F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),a=Sd(r,"Main database",s);if(a.errors.length>0)return{newEntities:[]};const d=a.implemented.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=d==null?void 0:d.defaultValue;if(o)o.value=!0;else if(d!=null&&d.dataType){const l=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s)}return{newEntities:[a.implemented]}}}return{newEntities:[]}}function vO(i,s){return i.implements.filter(t=>t.type===n.BuiltInBaseEntity).map(t=>{switch(t.id){case F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const a=i.project.entities.filter(l=>l.implements.find(c=>c.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(l=>!!l.properties.find(c=>{var h;return c.implements&&c.implements.id===F["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((h=c.getDefaultValue())==null?void 0:h.value)===!0}));if(!a)return{newEntities:[]};const d=i.properties.find(l=>l.implements&&l.implements.id===F["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),o=d==null?void 0:d.defaultValue;if(d&&(d!=null&&d.dataType)&&!o){const l=V({id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.LiteralValue,name:M.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:a,valueAsTypeList:null,parent:d==null?void 0:d.dataType.toReference()},i.project);return l.setParent(d==null?void 0:d.dataType,s),l.initChildren(s),l.addSelfToProject(s),{newEntities:[l]}}return{newEntities:[]}}}}),{newEntities:[]}}function Sd(i,s,e,t){const r=t||R.UUID.uuid(),a={id:r,version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:s,type:n.DefinitionEntity,description:null,static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[i],x:0,y:0,parent:i.project},d=gd(a,i.project);if(d.length>0)return{errors:d,implemented:null,entitiesChanges:{new:[],updated:[],deleted:[]}};const o=mO(i,e),l=V(a,i.project);l.setParent(i.project,e),l.initChildren(e);const c=i.properties.map(v=>{const E=R.UUID.uuid(),P=v.clone(e,l,E);return P.abstract=!1,P.implements=v,P.setParent(l,e),l.addProperty(P),P}),h=i.abstractMethods.map(v=>{const E=R.UUID.uuid(),P=v.implementAsFunctionDeclaration(E),w={id:E+"-parent-ref-id",type:n.GenericReference,entityId:r,version:R.UUID.uuid(),entityType:n.DefinitionEntity},C={...P,implements:v,parent:w},U=V(C,i.project);return l.addMethod(U),U.setParent(l,e),U.initChildren(e),U.implements=v,U});a.properties=c,a.methods=h;const p=vO(l,e);return{implemented:l,errors:[],entitiesChanges:{new:[l,...o.newEntities,...p.newEntities],updated:[l],deleted:[]}}}function Bp(i,s){return s.entities.find(r=>{const a=r.properties,d=a.map(p=>p.name),o=i.every(p=>d.includes(p)),l=d.filter(p=>!i.includes(p)),c=a.every(p=>!l.includes(p.name)||!p.required);return o&&c})||null}function TO(i,s,e,t=Rt.OrDataTypeGroup){const r=[],a=[],d=[],o=[],c={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:i.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:s.toReference()},h=V(c,i.project);return a.push(h),h.setParent(s,e),h.initChildren(e),h.setEntity(i),h.addSelfToProject(e),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:h}}function _p(i,s,e,t,r){var c,h,p,v,E,P,w,C;const a=[],d=[],o=[],l=[];switch(typeof i){case"string":let U=!1;const S=new Date(i);if(S instanceof Date&&!isNaN(S.valueOf())&&(U=!0),U){const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.Date].id);s.setEntity(B);break}else{const B=s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id);s.setEntity(B);break}case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":if(i===null){s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else if(Array.isArray(i))if(s.metaSync({isList:!0},t),i.length>0){const B=i.slice(0,5).filter(k=>k!==void 0);if(B.every(k=>typeof k==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":s.setEntity(s.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}else{const k=[];let W=!1;B.forEach(ce=>{var Te,Q,se,Ht;if(Array.isArray(ce)&&(W=!0),typeof ce=="object"&&!Array.isArray(ce)&&ce!==null){const zr=Fd(ce,s.project,{...e,id:R.UUID.uuid()},t,r);zr.hasCreated&&k.push((Te=zr.changeSet)==null?void 0:Te.self),a.push(...(Q=zr.changeSet)==null?void 0:Q.updated),d.push(...(se=zr.changeSet)==null?void 0:se.added),o.push(...(Ht=zr.changeSet)==null?void 0:Ht.removed)}});const ee=u(k);if(!ee.length&&!W){B.forEach(ce=>{const Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Rt.OrDataTypeGroup,parent:s.toReference()},Q=V(Te,s.project);switch(Q.setParent(s,t),Q.initChildren(t),Q.addSelfToProject(t),typeof ce){case"string":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.String].id));break;case"number":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.Number].id));break;case"boolean":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.Boolean].id));break;case"object":Q.setEntity(Q.project.getBuiltIn(F[n.PrimitiveEntity][M.Null].id));break}});break}else ee.length===1&&!W?s.setEntity(ee[0]):B.forEach(ce=>{if(typeof ce=="object"&&!Array.isArray(ce)&&ce!==null){const Te=Bp(Object.keys(ce),s.project);if(Te){const Q=TO(Te||ee[0],s,t,Rt.OrDataTypeGroup);a.push(...Q.updated),d.push(...Q.added),o.push(...Q.removed)}}else{const Te={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:Array.isArray(ce),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Rt.OrDataTypeGroup,parent:s.toReference()},Q=V(Te,s.project);Q.setParent(s,t),Q.initChildren(t),Q.addSelfToProject(t);const se=_p(ce,Q,{...e,id:R.UUID.uuid()},t,r);a.push(...se.updated),d.push(...se.added),o.push(...se.removed)}})}}else{const B=Fd(i[0],s.project,{...e},t,r);s.setEntity((c=B.changeSet)==null?void 0:c.self),a.push(...(h=B.changeSet)==null?void 0:h.updated),d.push(...(p=B.changeSet)==null?void 0:p.added),o.push(...(v=B.changeSet)==null?void 0:v.removed);break}else{const B=Fd(i,s.project,{...e},t,r);s.setEntity((E=B.changeSet)==null?void 0:E.self),a.push(...(P=B.changeSet)==null?void 0:P.updated),d.push(...(w=B.changeSet)==null?void 0:w.added),o.push(...(C=B.changeSet)==null?void 0:C.removed);break}}return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:s}}function Fd(i,s,e,t,r){const a=[],d=[],o=[],l=[],c=Object.keys(i),h=Bp(c,s);if(h)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:h}};const p=r?e.name+" of "+r.name:e.name,E={id:e.id||R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:p,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:s.toReference()},P=V(E,s);return P.setParent(s,t),P.initChildren(t),P.addSelfToProject(t),d.push(P),c.forEach((w,C)=>{const S={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:w,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:C,hidden:!1,private:!1,required:!0,parent:P.toReference()},B=V(S,s);B.setParent(P,t),B.initChildren(t),B.addSelfToProject(t),d.push(B);const $=i[w],W={id:R.UUID.uuid(),version:R.UUID.uuid(),createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},ee=V(W,s);ee.setParent(B,t),ee.initChildren(t),ee.addSelfToProject(t),d.push(ee);const ce=_p($,ee,{...e,name:w,id:R.UUID.uuid()},t,r||P);a.push(...ce.updated),d.push(...ce.added),o.push(...ce.removed)}),{hasCreated:!0,changeSet:{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:P}}}function xd(i,s){const e=_n(i);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(a=>{if(a===s)return t=a,[a];const d=xd(a,s);return d.last&&(t=d.last),[a,...d.list]}),last:t}}function EO(i,s,e=new Set){const t=Ji(i),r=Ji(s),a=t.filter(l=>!r.includes(l)),d=t.filter(l=>r.includes(l)),o=a.reduce((l,c)=>e.has(c.id)?l:(e.add(c.id),u([...l,...EO(c,s,e)])),[]);return u([...d,...o])}function Vs(i,s){const e=xd(i,s);return e.last===s&&e.list.length>0&&e.list[0]!==s}function Cq(i,s){return!!xd(i,s).last}function gq(i){if(at.includes(i.type))return i;if([...Vr,n.VariableDeclaration].includes(i.type)){const s=i.parent;return at.includes(s.type)?s:null}return null}function Mp(i,s){if(!i||!s)throw new Error("Both entities must be defined to find a common ancestor");if(i===s)return i;const e=i.parent;if(e){if(e===s)return s;if(e.type===n.Project)return null}else return null;const t=s.parent;if(t){if(t===i)return i;if(t.type===n.Project)return null}else return null;return Mp(e,t)}function wt(i){if($s.includes(i.type)){if(i.type===n.FunctionDeclaration){const s=i.parent;if(s.type===n.DefinitionEntity)return s;if(s.type===n.Loop)return s}return i}else{const s=i.parent;return s?wt(s):null}}function kd(i,s){const e=Cs(i,s);if(!e)return null;if($s.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Cs(e.parent,s);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Cs(e.parent,s):null;return t?kd(t,s):null}}function IO(i){if(!i)return null;if(Vr.includes(i.type))return i;const s=i.parent;return s?IO(s):null}function bO(i){if(!i)return null;if(nt.includes(i.type))return i;const s=i.parent;return s?bO(s):null}function RO(i){if(!i)return null;if(Cr.includes(i.type))return i;const s=i.parent;return s?RO(s):null}function Bq(i){return i.type===n.VariableDeclaration?[i]:nt.includes(i.type)?[...i.inputs,...i.outputs||[]]:st.includes(i.type)?i.outputs:jn.includes(i.type)||i.type===n.FunctionDeclaration?i.inputs:[]}function _q(i){const s=Ji(i),e=[],t=[];Hp.includes(i.type)&&e.push(...Np(i));const r=s.filter(a=>{const d=e.includes(a);return d?!1:Vr.includes(a.type)&&!d?(t.push(a),!1):!0});return e.sort((a,d)=>Vs(d,a)?-1:0),t.sort((a,d)=>Vs(d,a)?-1:0),[...e,...t,...r]}function AO(i){return[...i].sort((s,e)=>Vs(e,s)?-1:0)}function Mq(i){const s=AO(i),e=[];return s.forEach(t=>{const r=e[e.length-1];if(r){const a=r[r.length-1];Vs(t,a)?e.push([t]):r.push(t)}else e.push([t])}),e}function Yt(i){const s=i.map(e=>wt(e));return u(s)}function Np(i){return nt.includes(i.type)?[...Yt(i.successCalls),...Yt(i.errorCalls)]:at.includes(i.type)?Yt(i.calls):[]}function Nq(i,s){return Np(i).includes(s)}function Lp(i){return i.writesValues||[]}function Lq(i,s){return Lp(i).includes(s)}function DO(i){var s;return Qe.includes((s=i==null?void 0:i.readsValue)==null?void 0:s.type)?i.readsValue:null}function Uq(i){return i.writesValues}function OO(i=[]){return i.map(DO).filter(s=>!!s)}function Zd(i=[]){return i.map(s=>s.writesValues).flat().filter(s=>Qe.includes(s.type))}function PO(i=[]){return i.map(s=>s.readsValue).filter(s=>!!s&&Qe.includes(s.type))}function wO(i){return Qe.includes(i.type)?i:null}function VO(i){return i.writesValues.map(wO).filter(s=>!!s)}function CO(i=[]){return i.reduce((s,e)=>e.type===n.OutputMap?[...s,...VO(e)]:s,[])}function it(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function jq(i){return nt.includes(i.type)?[...Jr(Yt(i.successCalls)),...Jr(Yt(i.errorCalls))]:at.includes(i.type)?Jr(Yt(i.calls)):[]}function gO(i,s=new Set){return i.writesValues.filter(t=>Qe.includes(t.type)&&!s.has(t.id)).reduce((t,r)=>s.has(r.id)?t:[...t,...We(r,s)],[])}function BO(i,s=new Set){var t;return(((t=i.readsValue)==null?void 0:t.writesValues)||[]).filter(r=>Qe.includes(r.type)&&!s.has(r.id)).reduce((r,a)=>s.has(a.id)?r:[...r,...We(a,s)],[])}function We(i,s=new Set){if(s.has(i.id))return[];if(i.type===n.ReturnStatement)return PO(i.outputs).reduce((t,r)=>[...t,...We(r,s)],[]);if(i.type===n.FunctionCall||i.type===n.Operation||i.type===n.Condition)return[...it(i).reduce((a,d)=>{const o=wt(d);return[...a,...We(o||d,s)]},[]),...OO(i.inputs),...CO(i.outputs)].reduce((a,d)=>[...a,...We(d,s)],[]);if(jn.includes(i.type)){const e=Zd(i.inputs),r=it(i).reduce((a,d)=>{const o=wt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d,s)],[])}if(i.type===n.FunctionDeclaration){const e=[...Zd(i.inputs)],r=it(i).reduce((a,d)=>{const o=wt(d);return[...a,...We(o||d,s)]},[]);return e.push(...r),e.reduce((a,d)=>[...a,...We(d)],[])}if(Qe.includes(i.type)){s.add(i.id);const t=it(i).reduce((r,a)=>{const d=wt(a);return[...r,...We(d||a,s)]},[]);return[i,...t,...BO(i,s),...gO(i,s)]}return[]}function ir(i,s=new Set){return s.has(i.id)?[]:(s.add(i.id),[...Ji(i).reduce((r,a)=>[...r,a,...ir(a,s)],[])])}function Jr(i){return i.reduce((s,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...s,e]:[...s,e,...it(e)],[])}function _O(i){const s=i.entities||[],e=[...s,...i.functions||[],...i.events||[],...i.projects||[]],t=s.reduce((l,c)=>[...l,...c.properties],[]),r=s.reduce((l,c)=>[...l,...c.methods],[]),a=r.reduce((l,c)=>[...l,...Zd(c.inputs),...Jr(Yt(c.calls)),...c.returnStatements],[]),d=i.functions.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]),o=i.events.reduce((l,c)=>[...l,...Jr(Yt(c.calls)),...c.returnStatements],[]);return[...e,...t,...r,...a,...d,...o]}function MO(i,s){return s.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(r=>r.id===i.id)!==void 0||t.outputs.find(r=>r.id===i.id)!==void 0;case n.Condition:return t.successCalls.find(r=>r.id===i.id)!==void 0||t.errorCalls.find(r=>r.id===i.id)!==void 0||t.inputs.find(r=>r.id===i.id)!==void 0;case n.Operation:return t.outputs.find(r=>r.id===i.id)!==void 0;case n.VariableDeclaration:return nt.includes(i.type)?oP(i).find(a=>{var d;return((d=a.readsValue)==null?void 0:d.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(r=>r.id===i.id)!==void 0||t.methods.find(r=>r.id===i.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(r=>r.id===i.id)!==void 0||(t.returnStatements.map(r=>r.outputs).flat()||[]).find(r=>r.id===i.id)!==void 0;default:return!1}})}function $q(i){const s=_O(i.project);return MO(i,s)}function Cs(i,s){return i?typeof i=="string"?s[i]:i.type===n.GenericReference?s[i.entityId]:s[i.id]?s[i.id]:null:null}function qd(i,s={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||(e.allBuiltInEntityIds||[]).includes(i.id)))return{upstream:{},downstream:{}};const t=i,r=i,a=i,d=i,o=i,l=i,c=i,h=i,p=i,v=i,E=i,P=i,w=i,C=[...w.readsValue?[w.readsValue]:[],...w.declaration?[w.declaration]:[],...(P.calledByEntry||[]).flatMap($=>$),...(P.calledBySuccess||[]).flatMap($=>$),...(P.calledByError||[]).flatMap($=>$),...(a.extends||[]).flatMap($=>$),...v.parent?[v.parent]:[]];Array.isArray(a.implements)?C.push(...a.implements.flatMap($=>$)):p.implements&&C.push(p.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&C.push(...o.valueAsTypeList.flatMap($=>$)),o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const U=[...(t.inputs||[]).flatMap($=>$),...(E.inputsDeclarations||[]).flatMap($=>$),...(t.outputs||[]).flatMap($=>$),...(E.outputsDeclarations||[]).flatMap($=>$),...(w.internalCalls||[]).flatMap($=>$),...w.writesValues||[],...P.dataType?[P.dataType]:[],...l.body?[l.body]:[],...P.defaultValue?[P.defaultValue]:[],...(P.successCalls||[]).flatMap($=>$),...(P.errorCalls||[]).flatMap($=>$),...(a.properties||[]).flatMap($=>$),...(a.methods||[]).flatMap($=>$),...(a.abstractMethods||[]).flatMap($=>$),...c.error?[c.error]:[],...c.process?[c.process]:[],...v.throws?[v.throws]:[],...(r.andChildrenGroup||[]).flatMap($=>$),...(r.orChildrenGroup||[]).flatMap($=>$),...(h.entities||[]).flatMap($=>$),...(h.functions||[]).flatMap($=>$),...(h.functionCalls||[]).flatMap($=>$),...(h.events||[]).flatMap($=>$),...(h.conditions||[]).flatMap($=>$),...(h.operations||[]).flatMap($=>$),...(h.loops||[]).flatMap($=>$),...(h.variableDeclarations||[]).flatMap($=>$),...(h.variableInstances||[]).flatMap($=>$),...(h.searches||[]).flatMap($=>$),...(h.projects||[]).flatMap($=>$),...(d.calls||[]).flatMap($=>$)];i.type===n.DataType&&(r.entity&&s[g(r.entity)]&&s[g(r.entity)].parent&&g(s[g(r.entity)].parent)===i.id?U.push(r.entity):r.entity&&C.push(r.entity));const S={},B={};return C.forEach($=>{const k=g($);if(k&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(k)))return;const W=$.version;k&&(S[k]=W)}),U.forEach($=>{const k=g($);if(k&&e.ignoreBuiltInBaseEntities&&(hr.includes($.type)||(e.allBuiltInEntityIds||[]).includes(k)))return;const W=$.version;k&&(B[k]=W)}),{upstream:S,downstream:B}}function Gq(i,s){const e=[];if(Vr.includes(i.type)){pr(i).forEach(a=>{const d=kd(a,s);d&&e.push(d)});const r=[...i.inputs||[],...i.outputs||[]].map(a=>{const d=Cs(a,s);return d?lP(d,s):null}).filter(a=>a!==null);e.push(...u(r))}if(Qe.includes(i.type)){const t=Jd(i);t&&e.push(t)}return u(e)}function _n(i){const s=[];if(Vr.includes(i.type)){i.calledBy.forEach(r=>{const a=wt(r);a&&s.push(a)});const t=[...i.inputs||[],...i.outputs||[]].map(r=>Jd(r)).filter(r=>r!==null);s.push(...u(t))}if(Qe.includes(i.type)){const e=Jd(i);e&&s.push(e)}return u(s)}function pr(i){return[...i.calledByEntry||[],...i.calledByError||[],...i.calledBySuccess||[]].filter(s=>s.type!==n.GenericReference)}function NO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[i,...i.inputs.flatMap(t=>N(t,s,e)),...i.outputs.flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.parent?N(i.parent,s,e):[]]}function LO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s):[],...i.writesValues.flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function UO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function jO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...(i.extends||[]).flatMap(t=>N(t,s,e))]}function $O(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function GO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[i,...i.outputs.flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function SO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[i,...(i.extends||[]).flatMap(t=>N(t,s,e)),...(i.implements||[]).flatMap(t=>N(t,s,e)),...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function FO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[i,...(i.andChildrenGroup||[]).flatMap(t=>N(t,s,e)),...(i.orChildrenGroup||[]).flatMap(t=>N(t,s,e)),...i.entity?N(i.entity,s,e):[],...i.parent?N(i.parent,s,e):[]]}function xO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function kO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function ZO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.calls||[]).flatMap(t=>N(t,s,e)),...i.implements?N(i.implements,s,e):[],...i.parent?N(i.parent,s,e):[]]}function qO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function JO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[i,...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function WO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.parent?N(i.parent,s,e):[]]}function YO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[i,...i.valueAsTypeSingle?N(i.valueAsTypeSingle,s,e):[],...i.valueAsTypeList&&Array.isArray(i.valueAsTypeList)?i.valueAsTypeList.flatMap(t=>N(t,s,e)):[],...i.parent?N(i.parent,s,e):[]]}function zO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[i,...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...i.body?N(i.body,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function HO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...i.process?N(i.process,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function KO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[i,...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.parent?N(i.parent,s,e):[]]}function XO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[i,...(i.properties||[]).flatMap(t=>N(t,s,e)),...(i.methods||[]).flatMap(t=>N(t,s,e)),...(i.abstractMethods||[]).flatMap(t=>N(t,s,e))]}function QO(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[i,...(i.entities||[]).flatMap(t=>N(t,s,e)),...(i.functions||[]).flatMap(t=>N(t,s,e)),...(i.events||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.variableDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.variableInstances||[]).flatMap(t=>N(t,s,e)),...(i.operations||[]).flatMap(t=>N(t,s,e)),...(i.conditions||[]).flatMap(t=>N(t,s,e)),...(i.functionCalls||[]).flatMap(t=>N(t,s,e)),...(i.projects||[]).flatMap(t=>N(t,s,e)),...(i.loops||[]).flatMap(t=>N(t,s,e)),...(i.searches||[]).flatMap(t=>N(t,s,e))]}function eP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function tP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[i,...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function rP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[i,...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.throws?N(i.throws,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function iP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputsDeclarations||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...i.error?N(i.error,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.parent?N(i.parent,s,e):[]]}function nP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[i,...i.defaultValue?N(i.defaultValue,s,e):[],...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function aP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.dataType?N(i.dataType,s,e):[],...i.parent?N(i.parent,s,e):[]]}function sP(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(s.has(i.id))return[];if(s.add(i.id),i.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[i,...(i.successCalls||[]).flatMap(t=>N(t,s,e)),...(i.errorCalls||[]).flatMap(t=>N(t,s,e)),...(i.inputs||[]).flatMap(t=>N(t,s,e)),...(i.outputs||[]).flatMap(t=>N(t,s,e)),...(i.internalCalls||[]).flatMap(t=>N(t,s,e)),...(i.writesValues||[]).flatMap(t=>N(t,s,e)),...i.readsValue?N(i.readsValue,s,e):[],...i.defaultValue?N(i.defaultValue,s,e):[],...(pr(i)||[]).flatMap(t=>N(t,s,e)),...i.declaration?N(i.declaration,s,e):[],...i.parent?N(i.parent,s,e):[]]}function Wr(){const i=new Set;return YE.flatMap(e=>N(e,i)).map(e=>e.id)}function N(i,s=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!i)throw new Error("Entity must be defined to be flattened");if(i.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(hr.includes(i.type)||Wr().includes(i.id)))return[];if(s.has(i.id))return[];switch(i.type){case n.FunctionCall:return xO(i,s,e);case n.Operation:return HO(i,s,e);case n.Condition:return $O(i,s,e);case n.Loop:return zO(i,s,e);case n.Search:return iP(i,s,e);case n.GlobalEvent:return ZO(i,s,e);case n.ReturnStatement:return rP(i,s,e);case n.ContinueStatement:return GO(i,s,e);case n.BreakStatement:return UO(i,s,e);case n.VariableDeclaration:return aP(i,s,e);case n.DefinitionEntity:return SO(i,s,e);case n.FunctionDeclaration:return kO(i,s,e);case n.Project:return QO(i,s,e);case n.ActionDescriptor:return NO(i,s,e);case n.ArgumentDeclaration:return LO(i,s,e);case n.ReturnDeclaration:return tP(i,s,e);case n.ValueDescriptor:return nP(i,s,e);case n.InputMap:return qO(i,s,e);case n.OutputMap:return KO(i,s,e);case n.DataType:return FO(i,s,e);case n.InstalledProject:return JO(i,s,e);case n.InternalCall:return WO(i,s,e);case n.LiteralValue:return YO(i,s,e);case n.Property:return eP(i,s,e);case n.VariableInstance:return sP(i,s,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:jO(i,s,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:XO(i,s,e)}return[]}function Up(i){return i.type===n.FunctionCall||i.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.inputs:i.type===n.FunctionDeclaration||jn.includes(i.type)?i.inputs:i.type===n.Search?i.inputsDeclarations:[]}function Sq(i,s){return s.type===n.Condition?s.inputs.find(e=>e.declaration.id===i.id):s.type===n.FunctionCall||s.type===n.Operation?s.inputs.find(e=>e.declaration.id===i.id):null}function oP(i){return nt.includes(i.type)?i.inputs:[]}function dP(i){var s;return i.type===n.FunctionCall?((s=i.declaration.returnStatements[0])==null?void 0:s.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(i.type)?i.declaration.outputs:i.type===n.Search?i.outputsDeclarations:st.includes(i.type)?i.outputs:[]}function Fq(i,s){return s.type===n.Condition?null:s.type===n.FunctionCall||s.type===n.Operation?s.outputs.find(e=>e.declaration.id===i.id):null}function xq(i){return i.type===n.Condition?[]:nt.includes(i.type)?i.outputs:[]}function Jd(i){const s=i.readsValue;return s?wt(s):null}function lP(i,s){const e=i.readsValue;return e?kd(e,s):null}function uP(i){const s=i.internalCalls||[];return u(Yt(u(s.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Ra(i){const s=Lp(i),e=[];return s.forEach(t=>{if(Qe.includes(t.type))e.push(t);else if(hi.includes(t.type)){const r=t.parent;e.push(r)}}),e}function u(i){const s=new Set;return i.filter(e=>!e||s.has(e.id)?!1:(s.add(e.id),!0))}function Ji(i,s=!1){const e=[];if(i.type===n.Project&&e.push(...(i==null?void 0:i.entities)||[],...(i==null?void 0:i.functions)||[],...(i==null?void 0:i.variableDeclarations)||[],...(i==null?void 0:i.variableInstances)||[],...(i==null?void 0:i.searches)||[],...(i==null?void 0:i.loops)||[],...(i==null?void 0:i.operations)||[],...(i==null?void 0:i.conditions)||[],...(i==null?void 0:i.functionCalls)||[],...(i==null?void 0:i.events)||[],...(i==null?void 0:i.projects)||[]),mt.includes(i.type)&&e.push(...(i==null?void 0:i.detachedChildren)||[]),i.type===n.DefinitionEntity){const t=[...i.suggestedMethods,...i.methods].flatMap(r=>r.collapsed&&s?[]:Ji(r));e.push(...t)}if(i.type===n.Condition){const t=i.successCalls.map(a=>wt(a)),r=i.errorCalls.map(a=>wt(a));e.push(...t,...r)}if(jn.includes(i.type)){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>wt(a));e.push(...u(t),...r)}if(nt.includes(i.type)&&i.type!==n.Condition&&i.type!==n.Loop){const t=i==null?void 0:i.outputs.map(d=>Ra(d)).flat(),r=i.successCalls.map(d=>wt(d)),a=i.errorCalls.map(d=>wt(d));e.push(...u(t),...r,...a)}if(Qe.includes(i.type)){const t=Ra(i),r=uP(i);e.push(...t,...r)}if(i.type===n.Loop){const t=i.outputs.map(d=>Ra(d)).flat();if(i.body){const d=Ji(i.body,s);e.push(...d)}const r=i.errorCalls.map(d=>wt(d)),a=i.successCalls.map(d=>wt(d));e.push(...u(t),...a,...r)}if(i.type===n.FunctionDeclaration){if(i.collapsed&&s)return[];const t=i.inputs.map(a=>Ra(a)).flat(),r=i.calls.map(a=>wt(a));e.push(...u(t),...r)}return u(e)}function cP(i,s=!1){const e=Ji(i,s),t=[...e,...e.reduce((r,a)=>[...r,...cP(a,s)],[])];return u(t)}function pP(i){const s=_n(i),e=[...s,...s.reduce((t,r)=>[...t,...pP(r)],[])];return u(e)}function Wd(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Wd(e),...Yd(e)]:[...s,e.name],[])}function Yd(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,n.DefinitionEntity,...Yd(e),...Wd(e)]:[...s,e.name],[])}function jp(i){return i.extends.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...jp(e),...$p(e)]:[...s,e],[])}function $p(i){return i.implements.reduce((s,e)=>e.type===n.DefinitionEntity?[...s,e,...$p(e),...jp(e)]:[...s,e],[])}function Gp(i){return[...Yd(i),...Wd(i)].filter((e,t,r)=>r.indexOf(e)===t)}function fP(i){return i.implements.length===0&&i.extends.length===0?null:i.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===z.PERSISTED_ENTITY)?i:[...i.implements,...i.extends].reduce((t,r)=>{if(r.type===n.DefinitionEntity){const a=fP(r);if(a)return a}return t},null)}function kq(i){const s=i.extends.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function Zq(i){const s=i.implements.find(e=>e.type===n.BuiltInBaseEntity);return s&&s.type===n.BuiltInBaseEntity?s:null}function Sp(i){const s=i.extends.find(e=>e.type===n.DefinitionEntity);return s&&s.type===n.DefinitionEntity?s:null}function Wi(i){const s=[...i.implements,...i.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...Wi(t)]:e,[]);return u(s)}function Fp(i){return i.type===n.PrimitiveEntity?!0:i.type===n.BuiltInBaseEntity?i.interactive:!Wi(i).find(t=>!t.interactive)}function qq(i){return i.parent===i.project&&i.project.variableDeclarations.includes(i)}function xp(i){return i.parent!==i.project?!1:n.VariableDeclaration===i.type?i.project.variableDeclarations.includes(i):n.VariableInstance===i.type?i.project.variableInstances.includes(i):n.FunctionCall===i.type?i.project.functionCalls.includes(i):n.Condition===i.type?i.project.conditions.includes(i):n.Operation===i.type?i.project.operations.includes(i):n.Loop===i.type?i.project.loops.includes(i):n.Search===i.type?i.project.searches.includes(i):!1}function yP(i){if([...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||xp(i))return!1;const s=_n(i);return s.length===0?!0:s.some(e=>yP(e))}function kp(i){return[...at,n.DefinitionEntity,n.InstalledProject,n.Project].includes(i.type)||xp(i)?!1:_n(i).length===0}function hP(i,s=0){if(kp(i)){const e=_n(i);return e.length===0?i:e.map(r=>hP(r,s+1)).reduce((r,a)=>r?a&&a.x<r.x?a:r:a,null)}return null}function mP(i){const s=[];if(kp(i))s.push(i);else return[];return _n(i).forEach(t=>{s.push(...mP(t))}),s}function vP(i){return i.type===n.FunctionDeclaration&&i.parent!==i.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(i.parent.type)}function Jq(i,s){const e=new Map;return i.forEach(t=>{e.set(t.id,t)}),s.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function gs(i){switch(i){case n.DefinitionEntity:return zi;case n.FunctionDeclaration:return _i;case n.VariableDeclaration:return ji;case n.VariableInstance:return Ui;case n.FunctionCall:return qi;case n.Operation:return Mi;case n.Condition:return Li;case n.ReturnStatement:return Bi;case n.Loop:return Ni;case n.Search:return $i;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.ArgumentDeclaration:return Si;case n.ReturnDeclaration:return rr;case n.Property:return gi;case n.InstalledProject:return Gi;case n.Project:return R;case n.BuiltInBaseEntity:return Yr;default:return null}}function zt(i,s){if(mt.includes(i.type))return i;if(hr.includes(i.type))return null;const e=i.parent;if(!e)return null;if(e.type===n.GenericReference){const t=g(e);if(!t)return null;const r=s.get(t);return r?zt(r,s):null}else return e===s?s:zt(e,s)}function Zp(i,s){if(hr.includes(i.type)||s.getBuiltIn(i.id))return null;const e=nr(i.parent,s);return e?e===s?mt.includes(i.type)?i:null:e.type===n.DefinitionEntity?i:Zp(e,s):null}function zd(i,s,e){if(i===s||s===e||i===e)return!1;const t=zt(s.parent,e);return t===i?!0:zd(t,s,e)}var Hd=(i=>(i.SameBothLocal="same-both-local",i.AInB="a-in-b",i.BInA="b-in-a",i.ParallelInCommonParent="parallel-in-common-parent",i.ParallelInProject="parallel-in-project",i.AIsGlobalBIsNot="a-is-global-b-is-not",i.BIsGlobalAIsNot="b-is-global-a-is-not",i.SameBothGlobal="same-both-global",i))(Hd||{});function Bs(i,s,e){const t=zt(i,e),r=zt(s,e);if(!t)throw new Error("Could not find scope owner for the entity: "+i.id);if(!r)throw new Error("Could not find scope owner for the entity: "+s.id);if(t===r&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===r&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&r.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&r.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:r};if(zd(t,r,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(zd(r,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:r};const o=Mp(t,r);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:zt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function TP(i,s,e){const t=Bs(i,s,e);if(!t.compatible||t.type!=="same-both-local")return null;if(i===s)return i;let r=zt(i.parent,e);if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;for(;r;){if(r){if(r===s)return s;if(r.type===n.Project)return i}else return i;r=zt(r.parent,e)}let a=zt(s.parent,e);if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;for(;a;){if(a){if(a===i)return i;if(a.type===n.Project)return s}else return s;a=zt(a.parent,e)}return null}function EP(i){return i.length===0?null:i.length===1?i[0]:i.reduce((e,t)=>{const r=TP(e,t,t.project);return!r||r===t?e:t},i[0])}function nr(i,s){if(!i)return null;let e;return typeof i=="string"?e=i:i.type===n.GenericReference?e=g(i):e=i.id,e===s.id?s:s.get(e)}function Yi(i){if(!i)return null;if(hr.includes(i.type))return i;if(i.type===n.Project)return null;if(i.project.getBuiltIn(i.id))return i;const s=i.parent;return!s||s.type===n.Project?null:Yi(s)}function Wq(i,s){var e;if(i.readsValue){const t=nr(i.readsValue,s.project);s.setValueWriter(t),t.addValueReader(s)}else i.readsValue===null&&((e=s.readsValue)==null||e.removeValueReader(s),s.readsValue=null);return s}function _s(i){const s=[];function e(a,d){return s.some(o=>o.blockedByCaller===a&&o.blockedByCalling===d)}function t(a,d){e(a,d)||s.push({blockedByCaller:a,blockedByCalling:d})}const r=Zp(i,i.project);return i.calledBySuccess.forEach(a=>{[...a.successCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(p=>p===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=_s(o);l.reachable||it(i).find(p=>p===a)||l.blocks.forEach(p=>{t(a,p.blockedByCalling)})}}),i.calledByError.forEach(a=>{[...a.errorCalls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(p=>p===l)||t(a,l))});let o;if(nt.includes(a.type)&&(o=a),o){const l=_s(o);l.reachable||it(i).find(p=>p===a)||l.blocks.forEach(p=>{t(a,p.blockedByCalling)})}}),i.calledByEntry.forEach(a=>{if([...a.calls||[]].forEach(l=>{st.includes(l.type)&&l!==i&&(it(i).find(p=>p===l)||t(a,l))}),a===r)return;let o;if(a.type===n.FunctionDeclaration){const l=wt(a);if(l.type===n.DefinitionEntity)return;l.type===n.Loop&&(o=l)}if(o){const l=_s(o);l.reachable||l.blocks.forEach(c=>{t(a,c.blockedByCalling)})}}),{reachable:s.length===0,entryPoint:r,blocks:s}}function Yq(i){return $s.includes(i.type)?i.type===n.FunctionDeclaration?!vP(i):!0:!1}function zq(i){if(n.ActionDescriptor===i.type){if(i.project.operationDeclarations.find(a=>a.id===i.id))return n.Operation;if(i.project.globalEventActionDescriptors.find(a=>a.id===i.id))return n.GlobalEvent;if(i.project.loopDeclarations.find(a=>a.id===i.id))return n.Loop;if(i.project.conditionDeclarations.find(a=>a.id===i.id))return n.Condition}return i.type}function Aa(i,s){if(i.type!==n.DefinitionEntity||i.abstract)return!1;const e=Sp(i)||i;return!!Gp(e).includes(s)}function Hq(i){const s=[];return i.entities.forEach(e=>{if(Aa(e,z.PERSISTED_ENTITY)){s.push(e);return}}),u(s)}function Kq(i){const s=[];return i.entities.forEach(e=>{if(Aa(e,z.RELATIONAL_DATABASE)){s.push(e);return}}),u(s)}function Xq(i){return i.type!==n.DefinitionEntity||i.abstract||!Aa(i,z.PERSISTED_ENTITY)?null:(i==null?void 0:i.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===F[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function Qq(i){if(i.type!==n.DefinitionEntity)return[];if(i.abstract)return[];if(!Aa(i,z.PERSISTED_ENTITY))return[];const s=[],e=i.properties.filter(t=>{var r;return((r=t.implements)==null?void 0:r.id)!==F[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return s.push(...e),s}function eJ(i){var e;if(!i||i.type!==n.DefinitionEntity||!Aa(i,z.PERSISTED_ENTITY))return null;const s=i.properties.find(t=>{var r;return((r=t.implements)==null?void 0:r.id)===F[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id});return(e=s==null?void 0:s.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function ft(i,s){var t;if(!Xp.includes(s.type)||!i)return s.project||null;let e=s.project;return i.type===n.Project?e=i:((t=s.project)==null?void 0:t.id)!==i.project.id&&(e=i.project),e}function tJ(i){switch(i){case n.Project:return R;case n.InstalledProject:return Gi;case n.DefinitionEntity:return zi;case n.FunctionDeclaration:return _i;case n.GlobalEvent:return Vn;case n.VariableInstance:return Ui;case n.VariableDeclaration:return ji;case n.InputMap:return kr;case n.OutputMap:return Zr;case n.Condition:return Li;case n.Operation:return Mi;case n.FunctionCall:return qi;case n.ReturnDeclaration:return rr;case n.ArgumentDeclaration:return Si;case n.PrimitiveEntity:return fr;case n.DataType:return wn;case n.Property:return gi;case n.ActionDescriptor:return qe;case n.ReturnStatement:return Bi;case n.ContinueStatement:return $t;case n.BreakStatement:return Cn;case n.Loop:return Ni;case n.Search:return $i;case n.ValueDescriptor:return Fi;case n.InternalCall:return gn;case n.LiteralValue:return Bn}return null}function rJ(i){const s={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:i==null?void 0:i.self};return i==null||i.added.forEach(e=>{s.added[e.id]=e}),i==null||i.updated.forEach(e=>{s.updated[e.id]=e}),i==null||i.removed.forEach(e=>{s.removed[e.id]=e}),s.affected=Array.from(new Set(i==null?void 0:i.affected.map(e=>e.id))),s}function dt(i,s){const e=gs(i.type);return e?!e.MUTABLE_META_PROPERTIES.every(r=>{const a=i[r],d=s[r];return d===void 0||a===d?!0:Array.isArray(a)&&Array.isArray(d)?a.length!==d.length?!1:a.every((o,l)=>o===d[l]):!1}):!1}function Kd(i,s={}){if(i.type===n.Project)return[];if(!i.parent)return[];const e=g(i.parent);if(!e)return[];const t=s[e];return t?[t.id,...Kd(t,s)]:[]}function iJ(i,s){const e=[];if(i.parent)if(i.id===i.parent)e.push(new O({id:`${i.id}--${i.parent}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=s.get(i.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new O({id:`${i.id}--${i.parent}--${I.InvalidParentReference}`,code:I.InvalidParentReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new O({id:`${i.id}--${i.parent}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${i.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return i.implements&&Array.isArray(i.implements)?i.implements.forEach(t=>{if(i.id===t){e.push(new O({id:`${i.id}--${t}--${I.SelfReference}`,code:I.SelfReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract||e.push(new O({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.InvalidImplementsReference}`,code:I.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new O({id:`${i.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'implements' property that isn't an array.`,issue:null})),i.extends&&Array.isArray(i.extends)&&i.extends.forEach(t=>{const r=s.get(t);r?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(r.type)?r.abstract&&e.push(new O({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.InvalidExtendsReference}`,code:I.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new O({id:`${i.id}--${t}--${I.ReferencedEntityNotFound}`,code:I.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var IP=(i=>(i.Extends="extends",i.Implements="implements",i))(IP||{});const Le=class Le extends rt{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 fromGenerationTarget(e,t){let r=t;if(e.parent){const c=g(e.parent);r=t.get(c)}const a=[];e.implements&&e.implements.forEach(c=>{a.push(t.get(c)||t.getBuiltIn(c))});const d=[];e.extends&&e.extends.forEach(c=>{d.push(t.get(c)||t.getBuiltIn(c))});const o={id:e.id,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:d,implements:a,x:0,y:0,parent:r},l=V(o,t);return l.setParent(r,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[],d=iJ(r,t),o=gd(r,t);a.push(...d,...o,...ot(r));const l=r.parent?t.get(r.parent):null;if(l&&l.type===n.DataType){const c=l;c.entity&&a.push(new O({id:`${e.id}--${I.NewEntityWouldOverriteExisting}`,code:I.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 '${c.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
406
406
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
407
407
|
${qr({describe_entity:c.entity.id})}
|
|
408
|
-
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:a,modifiedData:r}}get allBasePropertiesFromExtendedAndImplementedEntities(){return u([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[])])}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[]),...this.implements.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])].filter(e=>!!e.abstract))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{hr.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{hr.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Le(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Le(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.extends.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addExtension(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),this.initialData.implements.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addImplementation(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c,affected:h}=this.syncImplementationProperties(e);t.push(...o),r.push(...l),a.push(...c),d.push(...h);const{updated:p,added:v,removed:E,affected:P}=this.addExtendedProperties(e);return t.push(...p),r.push(...v),a.push(...E),d.push(...P),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}addExtension(e){return this.extends.includes(e)||this.extends.push(e),this}removeExtension(e){return this.extends=this.extends.filter(t=>t.id!==e.id),this}addImplementation(e){return this.implements.includes(e)||this.implements.push(e),this}removeImplementation(e){return this.implements=this.implements.filter(t=>t.id!==e.id),this}removeProperty(e){return this.properties=this.properties.filter(t=>t.id!==e.id),this}addMethod(e){return this.methods.includes(e)||(this.methods.push(e),this.suggestedMethods=this.suggestedMethods.filter(t=>t.name!==e.name)),this}removeMethod(e){return this.methods=this.methods.filter(t=>t.id!==e.id),this}addProperty(e){return this.properties.includes(e)||(this.properties.push(e),this.suggestedProperties=this.suggestedProperties.filter(t=>t.name!==e.name)),this}addSuggestedProperty(e){return this.suggestedProperties.includes(e)||this.suggestedProperties.push(e),this}addSuggestedMethod(e){return this.suggestedMethods.includes(e)||this.suggestedMethods.push(e),this}removeSuggestedProperty(e){return this.suggestedProperties=this.suggestedProperties.filter(t=>t.id!==e.id),this}removeSuggestedMethod(e){return this.suggestedMethods=this.suggestedMethods.filter(t=>t.id!==e.id),this}addAbstractMethod(e){return this.abstractMethods.includes(e)||this.abstractMethods.push(e),this}removeAbstractMethod(e){return this.abstractMethods=this.abstractMethods.filter(t=>t.id!==e.id),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.methods=this.initialData.methods.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.extends=this.initialData.extends.map(t=>V(t,this.project)),this.implements=this.initialData.implements.map(t=>V(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}syncImplementationProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.implementedPropertiesFromOriginalParents,c=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return l.filter(p=>!c.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===p.id})).forEach(p=>{if(this.properties.find(w=>{var C;return((C=w.implements)==null?void 0:C.id)===p.id}))return;const E=this.properties.find(w=>w.name===p.name&&!!w.abstract&&!w.implements);if(E){E.implements=p,E.abstract=!1;return}const P=p.clone(e,this,R.UUID.uuid());P.initChildren(e),r.push(P),e==null||e.add(P,b.Added),P.setImplements(p,e),P.metaSync({abstract:!1},e),this.addProperty(P)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addExtendedProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.extendedPropertiesFromOriginalParents,c=l.filter(p=>l.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===p.id})?!1:!p.abstract),h=new Set(o.map(p=>p.name));return c.forEach(p=>{if(h.has(p.name))return;h.add(p.name);const v=p.clone(e,this,R.UUID.uuid());v.initChildren(e),r.push(v),e==null||e.add(v,b.Added),this.addProperty(v)}),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSuggestions(){return this.implements.forEach(e=>{B5(this,e).forEach(a=>{const d=a.toJSON();d.id=`_suggestion--parent--${this.id}--${a.id}`;const o=V(d,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),_5(this,e).forEach(a=>{const d=`_suggestion--parent--${this.id}--${a.id}`,o=a.implementAsFunctionDeclaration(d),l=V(o,this.project);if(l.suggestion=!0,l.setParent(this,null),l.initChildren(null),l.inputs.forEach(c=>{c.suggestion=!0}),l.returnStatements.length){const c=l.returnStatements[0];c.suggestion=!0,c.outputs.forEach(h=>{h.suggestion=!0})}this.addSuggestedMethod(l)})}),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.x=e.x||this.x,this.y=e.y||this.y,this.static=e.static||this.static,this.abstract=e.abstract||this.abstract,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Le.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Le.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Le.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.properties.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.methods.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.abstractMethods.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.suggestedProperties.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.suggestedMethods.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const l=this.parent.setEntity(null);r.push(l)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.properties.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.methods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.abstractMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedProperties.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(r=>r.toFlat(e)),...this.implements.flatMap(r=>r.toFlat(e)),...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(r=>r.toFlatIds(e)),...this.implements.flatMap(r=>r.toFlatIds(e)),...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.parent.toFlatIds(e)])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(c=>c.toJSONClone({...e,newId:null})),methods:this.methods.map(c=>c.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(c=>c.toJSONClone({...e,newId:null})),implements:this.implements.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),extends:this.extends.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toReference(e)),methods:this.methods.map(a=>a.toReference(e)),abstractMethods:this.abstractMethods.map(a=>a.toReference(e)),implements:this.implements.map(a=>a.toReference(e)),extends:this.extends.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e)),...this.implements.flatMap(r=>r.toFlatJSON(e)),...this.extends.flatMap(r=>r.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=g5(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C,U;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t&&p.setParent(t,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(w=this.properties)==null?void 0:w.map(S=>S.clone(e,p,R.UUID.uuid(),a));p.properties=v;const E=(C=this.methods)==null?void 0:C.map((S,B)=>S.clone(e,p,h+"-method-"+B+"-id",a));p.methods=E;const P=(U=this.abstractMethods)==null?void 0:U.map((S,B)=>S.clone(e,p,h+"-abstract-method-"+B+"-id",a));return p.abstractMethods=P,e==null||e.attemptAutoclose("clone-entity",this.id),p}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"implement-definition-entity")),r){const a=Sd(this,e,t,r);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),a}getAllInteractiveMethods(){const e=this.implements.filter(r=>r.type===n.DefinitionEntity||r.type===n.BuiltInBaseEntity&&r.interactive);return u([...this.methods,...this.extends.flatMap(r=>r.getAllInteractiveMethods()),...e.flatMap(r=>r.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const r=[],a=[],d=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[];e.forEach(p=>{l.find(E=>G(E,this.project)===G(p,this.project))||l.push(p)});const c=this.properties.filter(p=>!p.dataType);l.forEach(p=>{var U,S;const v=c.find(B=>G(B,this.project)===G(p,this.project));if(!v)return;const P=Pn(p.parent).getMasterInputWithValueWritterFromAllInstances(p),w=xr(P,t),C=w==null?void 0:w.clone(t,v,R.UUID.uuid(),!0);if(C){const B=(U=v.dataType)==null?void 0:U.merge(C,t);v.dataType&&(B==null?void 0:B.self.id)!==v.dataType.id&&v.dataType.remove({ignoreUpstream:!1},t),C.id!==((S=B==null?void 0:B.self)==null?void 0:S.id)&&C.remove({ignoreUpstream:!1},t),B!=null&&B.self&&(B.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(B.self,b.Added),v.setDataType(B.self),t==null||t.add(v,b.Updated))}p.setDeclaration(v),t==null||t.add(p,b.Updated)});const h=[];return l.forEach(p=>{if(!p.declaration){h.push(p);return}}),h.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(h.forEach(p=>{var B,$,k,W;const v=this.properties.find(ee=>G(ee,this.project)===G(p,this.project));if(v){if(p.setDeclaration(v),!v.getDataType(t)){const ce=Pn(p.parent).getMasterInputWithValueWritterFromAllInstances(p),Te=xr(ce),Q=Te==null?void 0:Te.clone(t,v,R.UUID.uuid(),!0);if(Q){const se=(B=v.dataType)==null?void 0:B.merge(Q,t);v.dataType&&(se==null?void 0:se.self.id)!==v.dataType.id&&v.dataType.remove({ignoreUpstream:!1},t),Q.id!==(($=se==null?void 0:se.self)==null?void 0:$.id)&&Q.remove({ignoreUpstream:!1},t),se!=null&&se.self&&(se.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(se.self,b.Added),v.setDataType(se.self),t==null||t.add(v,b.Updated))}}return}const E={id:R.UUID.uuid(),type:n.Property,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:G(p,this.project),description:p.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:p.index,implements:null,dataType:null,parent:this.toReference()},P=V(E,this.project);P.setParent(this,t),P.initChildren(t),t==null||t.add(P,b.Added);const C=Pn(p.parent).getMasterInputWithValueWritterFromAllInstances(p),U=xr(C),S=U==null?void 0:U.clone(t,P,R.UUID.uuid(),!0);if(S){const ee=(k=P.dataType)==null?void 0:k.merge(S,t);P.dataType&&(ee==null?void 0:ee.self.id)!==P.dataType.id&&P.dataType.remove({ignoreUpstream:!1},t),S.id!==((W=ee==null?void 0:ee.self)==null?void 0:W.id)&&S.remove({ignoreUpstream:!1},t),ee!=null&&ee.self&&(ee.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(ee.self,b.Added),P.setDataType(ee.self),t==null||t.add(P,b.Updated))}return this.addProperty(P),p.setDeclaration(P),t==null||t.add(p,b.Updated),P}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:u(r),updated:u(a),removed:u(d),affected:u(o),self:this})}};f(Le,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(Le,"type",n.DefinitionEntity),f(Le,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),f(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),f(Le,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),f(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),f(Le,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),f(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),f(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),f(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let zi=Le;function nJ(i){const s=d6(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Ns=class Ns extends rt{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(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.extends=this.initialData.extends.map(r=>V(r,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=L,...t){return await Ns.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.extends.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.extends.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=Z){return{id:this.id+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=Z){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=nJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}implement(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),null,!0,"implement-built-in-base-entity")),r){const a=Sd(this,e,t,r);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),a}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Ns&&e.push(...r.getAllInteractiveMethods())})),u(e)}};f(Ns,"repository",{APILoad:async(e,...t)=>null});let Yr=Ns;function aJ(i){const s=Q9(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Qd=class Qd extends rt{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(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=V(r,this.project);return a.parent=this,a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=V(r,this.project);return a.parent=this,a})}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=L,...t){return await Qd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=Z){return{id:this.id+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=Z){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=aJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Yr&&e.push(...r.getAllInteractiveMethods())}),u(e)}};f(Qd,"repository",{APILoad:async(e,...t)=>null});let fr=Qd;function lt(i,s){if(!i)throw new Error("Entity is null");const e=s.get(i.id);switch(i.type){case n.LiteralValue:return e||new Bn(i,s);case n.DefinitionEntity:return e||new zi(i,s);case n.PrimitiveEntity:return e||new fr(i,s);case n.FunctionDeclaration:return e||new _i(i,s);case n.GlobalEvent:return e||new Vn(i,s);case n.DataType:return e||new wn(i,s);case n.Property:return e||new gi(i,s);case n.FunctionCall:return e||new qi(i,s);case n.Condition:return e||new Li(i,s);case n.Operation:return e||new Mi(i,s);case n.VariableDeclaration:return e||new ji(i,s);case n.VariableInstance:return e||new Ui(i,s);case n.OutputMap:return e||new Zr(i,s);case n.ReturnDeclaration:return e||new rr(i,s);case n.ArgumentDeclaration:return e||new Si(i,s);case n.InputMap:return e||new kr(i,s);case n.Project:return e||new R(i);case n.InstalledProject:return e||new Gi(i,s);case n.ActionDescriptor:return e||new qe(i,s);case n.ReturnStatement:return e||new Bi(i,s);case n.Loop:return e||new Ni(i,s);case n.Search:return e||new $i(i,s);case n.ValueDescriptor:return e||new Fi(i,s);case n.BuiltInBaseEntity:return e||new Yr(i,s);case n.InternalCall:return e||new gn(i,s);case n.ContinueStatement:return e||new $t(i,s);case n.BreakStatement:return e||new Cn(i,s);case n.GenericReference:return s.get(i.entityId);default:throw new Error("Invalid entity type: "+i.type)}}function V(i,s){if(!i)throw new Error("Entity is null");const e=lt(i,s);return e.subscribe(),e}function sJ(i,s){if(!i)throw new Error("Entity is null");switch(i.type){case n.LiteralValue:return Bn.fromGenerationTarget(i,s);case n.DefinitionEntity:return zi.fromGenerationTarget(i,s);case n.FunctionDeclaration:return _i.fromGenerationTarget(i,s);case n.GlobalEvent:return Vn.fromGenerationTarget(i,s);case n.DataType:return wn.fromGenerationTarget(i,s);case n.Property:return gi.fromGenerationTarget(i,s);case n.FunctionCall:return qi.fromGenerationTarget(i,s);case n.Condition:return Li.fromGenerationTarget(i,s);case n.Operation:return Mi.fromGenerationTarget(i,s);case n.VariableDeclaration:return ji.fromGenerationTarget(i,s);case n.VariableInstance:return Ui.fromGenerationTarget(i,s);case n.OutputMap:return Zr.fromGenerationTarget(i,s);case n.ReturnDeclaration:return rr.fromGenerationTarget(i,s);case n.ArgumentDeclaration:return Si.fromGenerationTarget(i,s);case n.InputMap:return kr.fromGenerationTarget(i,s);case n.InstalledProject:return Gi.fromGenerationTarget(i,s);case n.ReturnStatement:return Bi.fromGenerationTarget(i,s);case n.Loop:return Ni.fromGenerationTarget(i,s);case n.Search:return $i.fromGenerationTarget(i,s);case n.ActionDescriptor:return qe.fromGenerationTarget(i,s);case n.ValueDescriptor:return Fi.fromGenerationTarget(i,s);case n.InternalCall:return gn.fromGenerationTarget(i,s);case n.ContinueStatement:return $t.fromGenerationTarget(i,s);case n.BreakStatement:return Cn.fromGenerationTarget(i,s);default:throw new Error("Invalid entity type: "+i.type)}}const Z={seenEntityMaps:new Map,seenEntities:new Set};class bP{constructor(){f(this,"initialData")}}const L={cascade:!1},RP={APILoad:async(i,...s)=>null},oJ={APICreate:async(i,...s)=>i,APIUpdate:async(i,...s)=>i,APIDelete:async(i,...s)=>{},APIClone:async(i,...s)=>{},APILoadVersion:async(i,s,...e)=>null,...RP};class dJ{}class lJ extends bP{}class uJ{}class cJ{}class pJ{}class qp{}class fJ extends qp{}class yJ extends qp{}class hJ{}class yi{static initReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=V(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=nr(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),s.readsValue.initChildren(null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}static hydrateReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=V(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=nr(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}}class Ms{static initWritesValues(s,e){const t=s.initialData.writesValues.reduce((a,d)=>{if(d.type===n.GenericReference||s.writesValues.some(l=>l.id===d.id))return a;const o=V(d,s.project);return o.setValueWriter(s),Qe.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...a,o]},[]),r=[...s.writesValues];return s.writesValues=u([...r,...t]),s.writesValues}}class mJ{}const de=class de extends rt{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{(!de.UUID||de.UUID.isBackup)&&(de.UUID=Lo==null?void 0:Lo()),de.UUID||(de.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),de.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:r=>r}}}static injectUUIDModule(e){de.UUID=e}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}onCloseChangeSet(e){this.onCloseChangeSetCallback=e}closeChangeSet(e){this.onCloseChangeSetCallback&&this.onCloseChangeSetCallback(e)}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(a=>a.id===(e==null?void 0:e.id));if(t)return t;const r=this.history.findIndex(a=>T(a.timestamp).isBefore(T(e==null?void 0:e.timestamp)));return r===-1?this.history.push(e):this.history.splice(r,0,e),e}discardChangeSet(e){const t=this.history.findIndex(r=>r.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}redo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async r=>{await t.init(this),r(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=de.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new de(this);return(r=this.knownVersions)==null||r.set(this.version,e),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new de(c)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=null){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e){const t=[],r=[],a=[],d=[];return this.subscribe(),this.subscribeToDependencies(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.projects=this.initialData.projects.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableInstances=this.initialData.variableInstances.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.conditions=this.initialData.conditions.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.operations=this.initialData.operations.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functions=this.initialData.functions.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functionCalls=this.initialData.functionCalls.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.loops=this.initialData.loops.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.searches=this.initialData.searches.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.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,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await de.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await de.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await de.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await de.repository.APIDelete(this.id,...t),this}async APIClone(e=L,...t){return await de.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await de.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(r=>r.toFlat(e)),...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e)),...this.projects.flatMap(r=>r.toFlat(e)),...this.variableDeclarations.flatMap(r=>r.toFlat(e)),...this.variableInstances.flatMap(r=>r.toFlat(e)),...this.conditions.flatMap(r=>r.toFlat(e)),...this.operations.flatMap(r=>r.toFlat(e)),...this.functionCalls.flatMap(r=>r.toFlat(e)),...this.loops.flatMap(r=>r.toFlat(e)),...this.searches.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(r=>r.toFlatIds(e)),...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e)),...this.projects.flatMap(r=>r.toFlatIds(e)),...this.variableDeclarations.flatMap(r=>r.toFlatIds(e)),...this.variableInstances.flatMap(r=>r.toFlatIds(e)),...this.conditions.flatMap(r=>r.toFlatIds(e)),...this.operations.flatMap(r=>r.toFlatIds(e)),...this.functionCalls.flatMap(r=>r.toFlatIds(e)),...this.loops.flatMap(r=>r.toFlatIds(e)),...this.searches.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,r=new Set,a=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(d=>{if(a.includes(d)){t.set(d,d);return}t.set(d,de.UUID.uuid())}),r.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),projects:this.projects.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableDeclarations:this.variableDeclarations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableInstances:this.variableInstances.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),conditions:this.conditions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),operations:this.operations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functions:this.functions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),events:this.events.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functionCalls:this.functionCalls.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),loops:this.loops.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),searches:this.searches.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null}))}}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+de.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(a=>a.toReference(e)),functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),projects:this.projects.map(a=>a.toReference(e)),variableDeclarations:this.variableDeclarations.map(a=>a.toReference(e)),variableInstances:this.variableInstances.map(a=>a.toReference(e)),conditions:this.conditions.map(a=>a.toReference(e)),operations:this.operations.map(a=>a.toReference(e)),functionCalls:this.functionCalls.map(a=>a.toReference(e)),loops:this.loops.map(a=>a.toReference(e)),searches:this.searches.map(a=>a.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(r=>r.toFlatJSON(e)),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e)),...this.projects.flatMap(r=>r.toFlatJSON(e)),...this.variableDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.variableInstances.flatMap(r=>r.toFlatJSON(e)),...this.conditions.flatMap(r=>r.toFlatJSON(e)),...this.operations.flatMap(r=>r.toFlatJSON(e)),...this.functionCalls.flatMap(r=>r.toFlatJSON(e)),...this.loops.flatMap(r=>r.toFlatJSON(e)),...this.searches.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(r=>r.toFlatGenerationTarget(e)),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e)),...this.projects.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(r=>r.toFlatGenerationTarget(e)),...this.conditions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.operations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.loops.flatMap(r=>r.toFlatGenerationTarget(e)),...this.searches.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=D5(),t=this.toJSON();return e.safeParse(t),this.validateChildren(),{success:!0,error:null,data:t}}validateChildren(){this.entities.forEach(e=>e.validate()),this.projects.forEach(e=>e.validate()),this.functions.forEach(e=>e.validate()),this.events.forEach(e=>e.validate()),this.variableDeclarations.forEach(e=>e.validate()),this.variableInstances.forEach(e=>e.validate()),this.conditions.forEach(e=>e.validate()),this.operations.forEach(e=>e.validate()),this.functionCalls.forEach(e=>e.validate()),this.loops.forEach(e=>e.validate()),this.searches.forEach(e=>e.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(t=>t.getErrors()),...this.projects.flatMap(t=>t.getErrors()),...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors()),...this.variableDeclarations.flatMap(t=>t.getErrors()),...this.variableInstances.flatMap(t=>t.getErrors()),...this.conditions.flatMap(t=>t.getErrors()),...this.operations.flatMap(t=>t.getErrors()),...this.functionCalls.flatMap(t=>t.getErrors()),...this.loops.flatMap(t=>t.getErrors()),...this.searches.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(e){return this.entities.find(t=>t.id===e)||null}addDefinitionEntityFromTransfer(e){const t=V(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=V(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=V(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=V(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=V(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=V(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=V(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=V(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=V(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=V(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=V(e,this);return this.addSearch(t),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(r=>r.id===e.id);if(t>-1){const r=this.entities[t];return this.entities.splice(t,1),r}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(r=>r.id===e.id);if(t>-1){const r=this.functions[t];return this.functions.splice(t,1),r}return null}removeExternalProject(e){const t=this.projects.findIndex(r=>r.id===e.id);if(t>-1){const r=this.projects[t];return this.projects.splice(t,1),r}return null}removeGlobalEvent(e){const t=this.events.findIndex(r=>r.id===e.id);if(t>-1){const r=this.events[t];return this.events.splice(t,1),r}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(r=>r.id===e.id);if(t>-1){const r=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),r}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.functionCalls.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.conditions.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.operations.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.loops.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.searches.reduce((t,r)=>{const a=We(r);return[...t,...a]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[])]}getVariableDeclarations(){return u([...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[])])}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(r=>{if(!r.declaration){const a=r.initialData,d=a.declaration.entityId||a.declaration.id,o=t.find(l=>l.id===d);o&&r.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===z.PERSISTED_ENTITY)||null}};f(de,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),f(de,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>{},APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...r)=>null}),f(de,"type",n.Project),f(de,"USER_MANAGED_PARENT_TYPES",[]),f(de,"PARENT_TYPES",[...de.USER_MANAGED_PARENT_TYPES]),f(de,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(de,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(de,"BASE_PROPERTIES",[...de.MUTABLE_BASE_PROPERTIES,...de.INMUTABLE_BASE_PROPERTIES]),f(de,"MUTABLE_META_PROPERTIES",[...de.MUTABLE_BASE_PROPERTIES,"x","y"]),f(de,"INMUTABLE_META_PROPERTIES",[...de.INMUTABLE_BASE_PROPERTIES]),f(de,"META_PROPERTIES",[...de.MUTABLE_META_PROPERTIES,...de.INMUTABLE_META_PROPERTIES]),f(de,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(de,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),f(de,"UPSTREAM_PROPERTIES",[...de.MUTABLE_UPSTREAM_PROPERTIES,...de.INMUTABLE_UPSTREAM_PROPERTIES]),f(de,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),f(de,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(de,"DOWNSTREAM_PROPERTIES",[...de.MUTABLE_DOWNSTREAM_PROPERTIES,...de.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(de,"PROPERTIES",[...de.META_PROPERTIES,...de.UPSTREAM_PROPERTIES,...de.DOWNSTREAM_PROPERTIES]);let R=de;var AP=(i=>(i.PersistChangeSet="persist-change-set",i.CreateSingle="create-single",i.CreateBulk="create-bulk",i.CreateSingleNested="create-single-nested",i.CreateBulkNested="create-bulk-nested",i.Update="update",i.Clone="clone",i.Delete="delete",i.Load="load",i.LoadNested="load-nested",i.LoadVersion="load-version",i))(AP||{});class DP extends qe{constructor(e){super(Rr,e);f(this,"id",He.Parallel);f(this,"name",He.Parallel);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",Rr);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Rr.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=Rr.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=Rr.error?V(Rr.error,this.project):null}}class OP extends qe{constructor(e){super(St,e);f(this,"id",St.id);f(this,"name",St.name);f(this,"description",St.description);f(this,"version",St.version);f(this,"autoexecutable",!1);f(this,"initialData",St);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=St.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=St.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=St.error?V(St.error,this.project):null}}class PP extends qe{constructor(e){super(ti,e);f(this,"id",He.Sequential);f(this,"name",He.Sequential);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",ti);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=ti.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=ti.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=ti.error?V(ti.error,this.project):null}}class vJ extends qe{constructor(s){super(wa,s)}}class TJ extends qe{constructor(s){super(Xi,s)}}class EJ extends qe{constructor(e){super(Qi,e);f(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-entity-to-match-validate-data"))){let r=null;if(e.readsValue){const d=e.readsValue.getDataType(t);d&&d.entity&&d.entity.type===n.DefinitionEntity&&(r=d.entity)}const a=e.getDefaultValue();return!r&&a&&a.valueAsTypeSingle&&!Array.isArray(a.valueAsTypeSingle)&&a.valueAsTypeSingle.type===n.DefinitionEntity&&(r=a.valueAsTypeSingle),r}syncOperationInstance(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const r=[],a=[],d=[],o=[],l=this.getEntityToMatchInputMap(e);if(l){const{added:p,updated:v,removed:E,affected:P}=this.syncEntityToMatchInputMapDataType(l,t);r.push(...v),a.push(...p),d.push(...E),o.push(...P)}const c=this.getDataToValidateInputMap(e);if(c){const{added:p,updated:v,removed:E,affected:P}=this.syncDataToValidateInputMapDataType(c,t);r.push(...v),a.push(...p),d.push(...E),o.push(...P)}const h=this.getOutputDataOutputMap(e);if(h){const{added:p,updated:v,removed:E,affected:P}=this.syncOutputDataOutputMapDataType(h,t);r.push(...v),a.push(...p),d.push(...E),o.push(...P)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var c,h,p;const r=[],a=[],d=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==F.operation[Ke.Validate].inputs.entityToMatch.id)return t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const v={id:R.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=V(v,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,b.Added),r.push(E),e.setDataType(E)}(h=e.dataType)==null||h.metaSync({inferred:!0,like:!1,asType:!0},t);const l=this.getEntityToMatch(e,t);return(p=e.dataType)==null||p.setEntity(l),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var p,v,E;const r=[],a=[],d=[],o=[];if(((p=e.declaration)==null?void 0:p.id)!==F.operation[Ke.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l,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 P={id:R.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},w=V(P,e.project);w.setParent(e,t),w.initChildren(t),t==null||t.add(w,b.Added),r.push(w),e.setDataType(w)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const h=this.getEntityToMatch(l,t);return(E=e.dataType)==null||E.setEntity(h),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var p,v,E;const r=[],a=[],d=[],o=[];if(((p=e.declaration)==null?void 0:p.id)!==F.operation[Ke.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l,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 P={id:R.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},w=V(P,e.project);w.setParent(e,t),w.initChildren(t),t==null||t.add(w,b.Added),r.push(w),e.setDataType(w)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const h=this.getEntityToMatch(l,t);return(E=e.dataType)==null||E.setEntity(h),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var r,a;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id){const{added:d,updated:o,removed:l,affected:c}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}else if(((a=e.declaration)==null?void 0:a.id)===F.operation[Ke.Validate].inputs.dataToValidate.id){const{added:d,updated:o,removed:l,affected:c}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var r;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id){const{added:a,updated:d,removed:o,affected:l}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:u(d),added:u(a),removed:u(o),affected:u(l),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class IJ extends qe{constructor(s){super(ul,s)}}class bJ extends qe{constructor(s){super(pl,s)}}class RJ extends qe{constructor(s){super(fl,s)}}class AJ extends qe{constructor(s){super(ks,s)}}class DJ extends qe{constructor(s){super(Ss,s)}}class OJ extends qe{constructor(s){super(Pa,s)}}function PJ(i){const s=[new PP(i),new DP(i),new OP(i),new vJ(i),new TJ(i),new EJ(i),new AJ(i),new IJ(i),new RJ(i),new bJ(i),new DJ(i),new OJ(i),new qe(ll,i),new qe(dl,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}class wP extends Yr{constructor(e){super(Ot,e);f(this,"initialData");f(this,"id",z.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",z.PERSISTED_ENTITY);f(this,"description",Ot.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",Ot.abstract);f(this,"static",Ot.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=Ot,this.project=e,this.id=Ot.id,this.version=Ot.version,this.name=Ot.name,this.static=Ot.static,this.abstract=Ot.abstract,this.properties=this.initialData.properties.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.methods=this.initialData.methods.map(t=>{const r=V(t,this.project);return r.parent=this,r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=V(t,this.project);return r.parent=this,r}),this.extends=this.initialData.extends.map(t=>V(t,this.project))}}function wJ(i){const s=[new wP(i),new Yr(Ma,i),new Yr(Mr,i),new Yr(so,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.builtInBaseEntities=s,s}function VJ(i){const s=[new fr(ne,i),new fr(Kr,i),new fr(me,i),new fr(At,i),new fr(Xr,i),new fr(gr,i),new fr(Qr,i),new fr($n,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.primitives=s,s}function CJ(i){const s=[new qe(lo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.globalEventActionDescriptors=s,s}function gJ(i){const s=[new qe(Ba,i),new qe(mi,i),new qe(Ca,i),new qe(Fn,i),new qe(xn,i),new qe(Ks,i)];s.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarations=s;const e=[new qe(to,i),new qe(ga,i),new qe(Qs,i),new qe(Pl,i),new qe(Vl,i),new qe(Xs,i)];return e.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarationsBodies=e,s}function BJ(i){const s=[new Fi(uo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.valueDescriptors=s,s}function _J(i){const s=[new qe(an,i),new qe(Wn,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}const Mn={},Xd={};async function MJ(i,s={}){const e={...kA};return e.id=i.id,s.empty?{data:{id:i.id,type:n.Project,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]}}:{data:e}}function Jp(i){const s=new R(i);return VJ(s),wJ(s),PJ(s),CJ(s),gJ(s),BJ(s),_J(s),Array.from(new Set([...s.getAllBuiltInIds(),...Wr()])).forEach(t=>{!s.builtInInstances[t]&&s.instances[t]&&(s.builtInInstances[t]=s.instances[t],delete s.instances[t])}),s}function NJ(i,{enrich:s}={enrich:!0}){const e=new Map,t=Array.from(new Set([...i.getAllBuiltInIds(),...Wr()]));Object.keys(i.instances).forEach(o=>{if(t.includes(o)){e.set(o,o);return}const l=i.get(o);if(!Kd(l,{...i.instances,...i.builtInInstances}).every(p=>!t.includes(p))){e.set(o,o);return}e.set(o,R.UUID.uuid())});const r=Jp(i.toShallowJSON({seenEntityMaps:e})),a=s?r.addChangeSet(new A(r,"",T().toISOString(),r)):null,d=new gp(i);return d.visit(o=>{const l=V(o.toShallowJSON({seenEntityMaps:e}),r);l.hydrateAncestors(),l.addSelfToProject(a),a==null||a.add(l,b.Added)}),s&&(d.visit(o=>{const l=r.get(e.get(o.id));l&&l.afterAllChildrenInitialized(a)}),r.afterAllChildrenInitialized(a)),a==null||a.close(),r}function VP(i,{enrich:s}={enrich:!0}){const e=Jp(i),t=s?e.addChangeSet(new A(e,"",T().toISOString(),e)):null;t&&(t.type=hp.Automatic);const r=new gp(i);return r.visit(a=>{const d=V(a,e);d.hydrateAncestors(),d.addSelfToProject(t)}),s&&(r.visit(a=>{const d=e.get(a.id);d&&d.afterAllChildrenInitialized(t)}),e.afterAllChildrenInitialized(t)),t==null||t.close(),e}async function LJ(i,s={}){if(i.id&&Mn[i.id])return Mn[i.id];if(i.id&&Xd[i.id])return await Xd[i.id],Mn[i.id];const e=MJ(i,s);i.id&&(Xd[i.id]=e);const t=await e;if(t.data){const r=VP(t.data);return Mn[i.id]=r,i.id&&delete Xd[i.id],r}return null}function UJ(i){return Mn[i.id]&&delete Mn[i.id],null}const jJ="test_primitive_entities_export";y.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Pp,y.ALL_BUILT_IN_BASE_ENTITIES=VE,y.ALL_BUILT_IN_CONDITION_ENTITIES=xE,y.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=ZE,y.ALL_BUILT_IN_LOOP_BODY_ENTITIES=nT,y.ALL_BUILT_IN_LOOP_ENTITIES=iT,y.ALL_BUILT_IN_OPERATION_ENTITIES=h0,y.ALL_BUILT_IN_PRIMITIVE_ENTITIES=sf,y.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=YE,y.ALL_BUILT_IN_VALUE_DESCRIPTORS=WE,y.ActionDescriptorState=qe,y.ActionInputMapState=dq,y.ActionOutputMapState=cq,y.AppendToListOperationInputIds=yh,y.AppendToListOperationOutputIds=hh,y.ArgumentDeclarationDependencyField=eO,y.ArgumentDeclarationState=Si,y.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Rp,y.BUILT_IN_BASE_ENTITY_IDS=F,y.BUILT_IN_ENTITY_TYPES=hr,y.BaseCanvasDraggableState=uJ,y.BaseEntityNames=z,y.BaseState=lJ,y.BaseValueDescriptorIds=Gs,y.BreakStatementDependencyField=vp,y.BreakStatementState=Cn,y.BuiltInBaseEntityState=Yr,y.CACHED_PROJECTS_BY_ID=Mn,y.CALLABLE_ENTITIES_EXPLANATION=Eq,y.CALLABLE_TYPES=Vr,y.CALLER_ENTITIES_EXPLANATION=aO,y.CALLER_TYPES=Cr,y.CALLS_UPDATE_EXPLANATION=ki,y.COMPARISON_CONDITIONS=SE,y.CONDITIONS=FE,y.CUSTOM_ENTITY_OPERATIONS=Mm,y.CallableEntityClass=pJ,y.CallerEntityClass=qp,y.ChangeSet=A,y.ChangeSetChangeCaptureType=hp,y.ChangeSetEntityChangeType=b,y.ChildEntityState=cJ,y.ComparisonOperatorTypes=ct,y.ConditionDependencyField=Y1,y.ConditionState=Li,y.ContinueStatementDependencyField=mp,y.ContinueStatementState=$t,y.CreateNewInputIds=om,y.CreateNewOutputIds=dm,y.DRAGGABLE_CALLABLE_TYPES=rl,y.DRAGGABLE_CALLER_TYPES=Hp,y.DRAGGABLE_ELEMENT_TYPES=$s,y.DRAGGABLE_EXECUTABLE_TYPES=MP,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=js,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=tl,y.DataTypeCompatibilityTypes=Er,y.DataTypeDependencyField=Z1,y.DataTypeParentChildRelation=Rt,y.DataTypeState=wn,y.DefinitionEntityDependencyField=IP,y.DefinitionEntityState=zi,y.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=oJ,y.ENTITIES_WITH_VALLUES_EXPLANATION=Ld,y.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=L,y.ENTITY_RECUSION_OPTIONS_DEFAULTS=Z,y.ENTITY_TYPES=NP,y.ENTITY_WITH_DECLARATION_TYPES=BP,y.ENTITY_WITH_LOGIC_SCOPE_TYPES=mt,y.ENTITY_WITH_NAMES_TYPES=Kp,y.ENTITY_WITH_PARENT_TYPES=CP,y.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=Yp,y.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=gP,y.ENTITY_WITH_VALUE_TYPES=Wp,y.ENTRY_POINT_ENTITIES_EXPLANATION=Ps,y.ENTRY_POINT_TYPES=at,y.EVENT_TYPES=jn,y.EXECUTABLE_TYPES=_P,y.EXECUTION_OPERATIONS=sm,y.EntityAction=AP,y.EntityError=hn,y.EntityErrorSeverity=D,y.EntityGenerationError=O,y.EntityGenerationErrorCode=I,y.EntityInstanceErrorCode=q,y.EntityOperations=Ke,y.EntityType=n,y.EntityWithLogicScopeClass=mJ,y.EntityWithValueClass=hJ,y.EntryPointEntityClass=fJ,y.ExecutionOperations=He,y.ExecutionTerminationType=J1,y.FunctionCallDependencyField=hO,y.FunctionCallState=qi,y.FunctionDeclarationDependencyField=k1,y.FunctionDeclarationState=_i,y.GLOBAL_EVENT_DECLARATIONS=kE,y.GetLastInListOperationInputIds=rh,y.GetLastInListOperationOutputIds=ih,y.GlobalEventNames=Hr,y.GlobalEventState=Vn,y.HTTPOperations=Ct,y.HTTP_OPERATIONS=f0,y.InputMapDependencyField=X1,y.InputMapState=kr,y.InstalledProjectState=Gi,y.InternalCallDependencyField=K1,y.InternalCallState=gn,y.JoinListOperationInputIds=Ry,y.JoinListOperationOutputIds=Ay,y.LIST_OPERATIONS=Vh,y.ListOperations=fe,y.LiteralValueDependencyField=tO,y.LiteralValueState=Bn,y.LoopDependencyField=W1,y.LoopState=Ni,y.LoopTypes=K,y.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=Zi,y.NUMBER_OPERATIONS=Uf,y.NumberOperations=Xe,y.OPERATION_DECLARATIONS=y0,y.OperationDependencyField=q1,y.OperationState=Mi,y.OutputMapDependencyField=Q1,y.OutputMapParentChildRelation=Un,y.OutputMapState=Zr,y.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Ud,y.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=xi,y.PASS_THROUGH_CALLABLE_TYPES=nt,y.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=zp,y.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Op,y.ParallelExecutionOperation=DP,y.PassThroughCallableEntityClass=yJ,y.PersistedEntity=wP,y.PersistedEntityMethods=sr,y.PrimitiveEntityState=fr,y.PrimitiveTypes=M,y.ProjectState=R,y.PropertyDependencyField=F1,y.PropertyState=gi,y.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=RP,y.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=Iq,y.ReturnDeclarationDependencyField=x1,y.ReturnDeclarationState=rr,y.ReturnStatementDependencyField=Bd,y.ReturnStatementState=Bi,y.STANDALONE_CONDITIONS=BE,y.STRING_OPERATIONS=by,y.ScopeCompatibilityType=Hd,y.SearchDependencyField=H1,y.SearchState=$i,y.SequentialExecutionOperation=PP,y.SequentialExecutionOperationInputIds=Wh,y.SequentialExecutionOperationOutputIds=Yh,y.SharedEntityErrorCode=j,y.SharedStateFunctionality=bP,y.SplitListOperationInputIds=$y,y.SplitListOperationOutputIds=Gy,y.StandaloneOperatorTypes=yr,y.StringOperations=Ee,y.TERMINATION_TYPES=st,y.Traverser=gp,y.USER_MANAGED_ENTITY_TYPES=Xp,y.UserManagedEntityStateTemplate=dJ,y.VALUE_READING_ENTITIES_EXPLANATION=Dp,y.VALUE_READING_TYPES=hi,y.VALUE_WRITING_ENTITIES_EXPLANATION=sO,y.VALUE_WRITING_TYPES=ht,y.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=Ap,y.VARIABLE_TYPES=Qe,y.ValueAutogenerationType=yt,y.ValueDescriptorDependencyField=rO,y.ValueDescriptorParentChildRelation=_,y.ValueDescriptorState=Fi,y.ValueReadingEntityClass=yi,y.ValueWritingEntityClass=Ms,y.VariableDeclarationDependencyField=z1,y.VariableDeclarationState=ji,y.VariableInputMapState=oq,y.VariableInstanceDependencyField=Tp,y.VariableInstanceState=Ui,y.VariableOutputMapState=uq,y.WaitOperation=OP,y.WaitOperationInputIds=Sh,y.WaitOperationOutputIds=Fh,y.appendToListOperation=ks,y.appendToListOperationElementToAppendArgument=hl,y.appendToListOperationElementToAppendArgumentParentRef=Ah,y.appendToListOperationElementToAppendArgumentRef=Th,y.appendToListOperationError=wh,y.appendToListOperationErrorParentRef=Ph,y.appendToListOperationListArgument=yl,y.appendToListOperationListArgumentParentRef=Rh,y.appendToListOperationListArgumentRef=mh,y.appendToListOperationListDataType=vh,y.appendToListOperationResultListDataType=bh,y.appendToListOperationResultListReturn=Oh,y.appendToListOperationResultListReturnParentRef=Dh,y.appendToListOperationResultListReturnRef=Ih,y.appendToListOperationSecondListDataType=Eh,y.asGenerationActionExample=qr,y.booleanPrototype=Kr,y.capitalizeFirstLetter=Wt,y.changeSetJSONRecordToUniqueIds=$7,y.checkAreDataTypesCompatible=Ir,y.checkAreDefinitionEntitiesCompatibleAsDataType=V1,y.checkArePropertiesCompatibleAsDataType=w1,y.checkHasMetadataChanged=dt,y.checkIsBranchDependentButNotDirectlyOnBranch=Vs,y.checkIsBranchDependentOnBranch=Cq,y.checkIsCallableEntityReachable=_s,y.checkIsCanvasEntity=Yq,y.checkIsDetachedBranch=yP,y.checkIsDetachedBranchShallow=kp,y.checkIsGlobalVariable=qq,y.checkIsGloballyDeclared=xp,y.checkIsMethod=vP,y.checkIsNestedScope=zd,y.checkScopeCompatibility=Bs,y.cloneProject=NJ,y.countedLoopActionDescriptor=Ba,y.countedLoopActionDescriptorDynamicReturnDeclaration=zv,y.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=Yv,y.countedLoopActionDescriptorStringArgumentDeclaration=Wv,y.countedLoopActionDescriptorStringArgumentDeclarationDataType=qv,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=kv,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=xv,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=Zv,y.countedLoopActionDescriptorStringArgumentDeclarationParentRef=Jv,y.countedLoopBodyActionDescriptor=to,y.countedLoopBodyActionDescriptorAnyDynamicArgument=eT,y.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Qv,y.countedLoopBodyActionDescriptorAnyDynamicReturn=rT,y.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=tT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=gl,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Kv,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Hv,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Xv,y.createDefinitionEntityFromJSONObject=Fd,y.createEntityError=ye,y.createNestedDataTypeForEntity=TO,y.createNewInstanceOperation=Xi,y.createNewInstanceOperationEntityToInstanciateArgument=mm,y.createNewInstanceOperationEntityToInstanciateArgumentRef=fm,y.createNewInstanceOperationEntityToInstanciateDataType=ym,y.createNewInstanceOperationError=Im,y.createNewInstanceOperationErrorParentRef=Em,y.createNewInstanceOperationNewEntityDataArgument=pm,y.createNewInstanceOperationNewEntityDataArgumentDataType=cm,y.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=um,y.createNewInstanceOperationNewEntityDataArgumentParentRef=lm,y.createNewInstanceOperationOutputEntityDeclaration=Tm,y.createNewInstanceOperationOutputEntityDeclarationParentRef=vm,y.createNewInstanceOperationRef=hm,y.createSemanticId=S1,y.createStateFromGenerationTargetType=sJ,y.createStateFromType=lt,y.createStateFromTypeAndSubscribe=V,y.cronJobBuiltInBaseEntity=so,y.cronJobBuiltInBaseEntityExpressionProperty=PE,y.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=FP,y.cronJobBuiltInBaseEntityExpressionPropertyRef=DE,y.cronJobBuiltInBaseEntityRef=OE,y.cronJobTriggeredFunctionDeclarationBlueprint=Zl,y.cronJobTriggeredFunctionDeclarationBlueprintParentRef=RE,y.dataTypeCompatibilityToErrorExplanation=yO,y.datePrototype=gr,y.dateValueAutogenerationSchema=ic,y.definitionEntityToZodSchema=uI,y.deletePersistedEntityMethod=kl,y.deletePersistedEntityMethodParentRef=oE,y.deleteRootProject=UJ,y.endpointBuiltInBaseEntity=Ma,y.endpointBuiltInBaseEntityRef=dT,y.endpointBuiltInBaseEntityRefFour=kT,y.endpointBuiltInBaseEntityRefThree=vT,y.endpointBuiltInBaseEntityRefTwo=fT,y.endpointBuiltInCorsProperty=lT,y.endpointBuiltInCorsPropertyDataType=oT,y.endpointBuiltInCorsPropertyDataTypeRef=aT,y.endpointBuiltInCorsPropertyRef=sT,y.endpointBuiltInMethodProperty=_l,y.endpointBuiltInMethodPropertyDataType=mT,y.endpointBuiltInMethodPropertyDataTypeRef=yT,y.endpointBuiltInMethodPropertyRef=hT,y.endpointBuiltInPathProperty=Bl,y.endpointBuiltInPathPropertyDataType=pT,y.endpointBuiltInPathPropertyDataTypeRef=uT,y.endpointBuiltInPathPropertyRef=cT,y.endpointPathParamsArgumentDeclaration=Nl,y.endpointPathParamsArgumentDeclarationRef=wT,y.endpointPathParamsVariableDataType=VT,y.endpointPathParamsVariableDataTypeRef=PT,y.endpointReachedTriggerActionDescriptor=Sl,y.endpointReachedTriggerActionDescriptorRef=CT,y.endpointReachedTriggerActionDescriptorRefFour=_T,y.endpointReachedTriggerActionDescriptorRefThree=BT,y.endpointReachedTriggerActionDescriptorRefTwo=gT,y.endpointRequestBodyArgumentDeclaration=Ul,y.endpointRequestBodyArgumentDeclarationRef=bT,y.endpointRequestBodyVariableDataType=RT,y.endpointRequestHeadersArgumentDeclaration=Ml,y.endpointRequestHeadersArgumentDeclarationRef=ET,y.endpointRequestHeadersVariableDataType=IT,y.endpointRequestHeadersVariableDataTypeRef=TT,y.endpointRequestQueryParamsArgumentDeclaration=Ll,y.endpointRequestQueryParamsArgumentDeclarationRef=DT,y.endpointRequestQueryParamsVariableDataType=OT,y.endpointRequestQueryParamsVariableDataTypeRef=AT,y.endpointResponseBodyDataType=FT,y.endpointResponseBodyReturnDeclaration=Gl,y.endpointResponseBodyReturnDeclarationRef=ST,y.endpointResponseCodeDataType=NT,y.endpointResponseCodeReturnDeclaration=jl,y.endpointResponseCodeReturnDeclarationRef=MT,y.endpointResponseHeadersDataType=$T,y.endpointResponseHeadersDataTypeRef=UT,y.endpointResponseHeadersReturnDeclaration=$l,y.endpointResponseHeadersReturnDeclarationRef=jT,y.endpointReturnStatementRef=LT,y.endpointReturnStatementRefThree=xT,y.endpointReturnStatementRefTwo=GT,y.enrichFromKnownEntities=Cs,y.enumOptionsProperty=af,y.enumOptionsPropertyDataType=rf,y.enumOptionsPropertyDataTypeRef=ef,y.enumOptionsPropertyRef=tf,y.enumPrototype=Xr,y.enumPrototypeRef=nf,y.executionBuiltInBaseEntity=oo,y.executionBuiltInEntityAbortMethod=ql,y.executionBuiltInEntityAbortMethodParentRef=wE,y.filterOutDuplicateEntities=u,y.filterOutDuplicateErrors=Z9,y.findEntityFromKeys=Bp,y.findReferenceToSelfInList=MO,y.findReferencesToSelfInProject=$q,y.flattenActionDescriptor=NO,y.flattenArgumentDeclaration=LO,y.flattenBreakStatement=UO,y.flattenBuiltInBaseEntity=jO,y.flattenCalls=Jr,y.flattenCanvasAncestorsUntil=xd,y.flattenCondition=$O,y.flattenContinueStatement=GO,y.flattenDataType=FO,y.flattenDefinitionEntity=SO,y.flattenDefinitionEntityExtensionAndImplementationTypes=Gp,y.flattenDefinitionEntityExtensionTypes=Yd,y.flattenDefinitionEntityExtensions=jp,y.flattenDefinitionEntityImplementations=$p,y.flattenDefinitionEntityImplementionTypes=Wd,y.flattenDerivedCanvasEntities=ir,y.flattenDetachedBranch=mP,y.flattenElementCalls=it,y.flattenElementCallsOnTheSameScope=jq,y.flattenEntity=N,y.flattenFunctionCall=xO,y.flattenFunctionDeclaration=kO,y.flattenGlobalEvent=ZO,y.flattenInputMap=qO,y.flattenInstalledProject=JO,y.flattenInternalCall=WO,y.flattenLiteralValue=YO,y.flattenLoop=zO,y.flattenOperation=HO,y.flattenOutputMap=KO,y.flattenPrimitiveEntity=XO,y.flattenProject=QO,y.flattenProjectElements=_O,y.flattenProperty=eP,y.flattenRelatedCanvasElementsOnTheLeft=pP,y.flattenRelatedCanvasElementsOnTheRight=cP,y.flattenReturnDeclaration=tP,y.flattenReturnStatement=rP,y.flattenSearch=iP,y.flattenValueDescriptor=nP,y.flattenVariableDeclaration=aP,y.flattenVariableInstance=sP,y.flattenVariableReads=BO,y.flattenVariableWrites=gO,y.flattenVariables=We,y.fromChangeSetToRecordChangeSet=rJ,y.fromZodParseToEntityGenerationErrors=Ep,y.generate=qV,y.generateActionExample=bq,y.generateExecutionDataType=V7,y.generateIdFromStrategy=pt,y.generateMutablePropertiesExplanation=_d,y.generateRandomBoolean=jI,y.generateRandomDate=yI,y.generateRandomDateAfter=cI,y.generateRandomDateBefore=pI,y.generateRandomDateBetweenRange=fI,y.generateRandomNumber=_I,y.generateRandomNumberAfter=CI,y.generateRandomNumberBefore=gI,y.generateRandomNumberBetweenRange=BI,y.generateRandomText=UI,y.generateRandomTextAfter=MI,y.generateRandomTextBefore=NI,y.generateRandomTextBetweenRange=LI,y.generateUniqueUUID=VI,y.getAllActionDescriptorsForConditions=Gd,y.getAllActionDescriptorsForGlobalEvents=jd,y.getAllActionDescriptorsForLoops=$d,y.getAllActionDescriptorsForOperations=Oq,y.getAllBuiltInEntityIds=Wr,y.getAllGloballyDeclaredFunctionDeclarationsExplanation=cO,y.getBaseBuiltInEntities=Wi,y.getBaseSchemaBasedOnType=iO,y.getBuiltInEntityOwner=Yi,y.getCallableEntityReferenceSchema=Dt,y.getCallableEntityTypeSchema=hD,y.getCalledBy=pr,y.getCallerEntityReferenceSchema=Y3,y.getCallerEntityTypeSchema=W3,y.getCalls=Np,y.getCanvasEntitiesDerivedFromInternalCalls=uP,y.getCanvasEntitiesDerivedFromWrites=Ra,y.getCanvasEntityDerivedFromValueReadingEntity=Jd,y.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=lP,y.getCanvasEntityReferenceSchema=c5,y.getCanvasEntityTypeSchema=u5,y.getChildrenEntityWithValues=Bq,y.getColumnProperties=Qq,y.getCommonAncestor=Mp,y.getCommonChildren=EO,y.getDatabaseEntities=Kq,y.getDatabaseEntity=eJ,y.getDeclaration=Pn,y.getDeepestScope=EP,y.getDefinitionEntityExtends=Aa,y.getDraggableCallableEntityReferenceSchema=vD,y.getDraggableCallableEntityTypeSchema=mD,y.getDraggableCallerEntityReferenceSchema=H3,y.getDraggableCallerEntityTypeSchema=z3,y.getDraggableExecutableEntityReferenceSchema=e5,y.getDraggableExecutableEntityTypeSchema=Q3,y.getDraggablePassThroughCallableEntityReferenceSchema=vd,y.getDraggablePassThroughCallableEntityTypeSchema=md,y.getDraggablePlayableEntityReferenceSchema=a5,y.getDraggablePlayableEntityTypeSchema=n5,y.getEntityArgumentDeclarations=Up,y.getEntityInputMaps=oP,y.getEntityOutputMaps=xq,y.getEntityReferenceSchema=l5,y.getEntityReturnDeclarations=dP,y.getEntityTypeSchema=d5,y.getEntityWithLogicScopeReferenceSchema=ui,y.getEntityWithLogicScopeTypeSchema=t5,y.getEntityWithValueReferenceSchema=yD,y.getEntityWithValueTypeSchema=J3,y.getEntryPointEntityReferenceSchema=bt,y.getEntryPointEntityTypeSchema=wi,y.getEventEntityReferenceSchema=yd,y.getEventEntityTypeSchema=fd,y.getExecutableEntityReferenceSchema=X3,y.getExecutableEntityTypeSchema=K3,y.getExtendedBuiltInEntity=kq,y.getExtendedDefinitionEntity=Sp,y.getGenerationTargetSchemaBasedOnType=nO,y.getHeadIfPartOfDetachedBranch=hP,y.getHighestScope=TP,y.getImplementedBuiltInEntity=Zq,y.getIsInteractive=Fp,y.getLastInListOperation=fl,y.getLastInListOperationError=fh,y.getLastInListOperationErrorParentRef=ph,y.getLastInListOperationInputListArgument=lh,y.getLastInListOperationInputListArgumentParentRef=dh,y.getLastInListOperationInputListArgumentRef=nh,y.getLastInListOperationInputListDataType=ah,y.getLastInListOperationOutputElementDataType=oh,y.getLastInListOperationOutputElementReturn=ch,y.getLastInListOperationOutputElementReturnParentRef=uh,y.getLastInListOperationOutputElementReturnRef=sh,y.getLinkedEntitiesFromArgumentDeclaration=Uq,y.getLowestPersistedEntityImplementation=fP,y.getParentCallableEntity=IO,y.getParentCallerEntity=RO,y.getParentCanvasEntities=Yt,y.getParentCanvasEntity=wt,y.getParentCanvasEntityFromTransfer=kd,y.getParentEntryPoint=gq,y.getParentPassthroughCallableEntity=bO,y.getPassThroughCallableEntityReferenceSchema=et,y.getPassThroughCallableEntityTypeSchema=hd,y.getPeristedEntities=Hq,y.getPlayableEntityReferenceSchema=i5,y.getPlayableEntityTypeSchema=r5,y.getProject=LJ,y.getPrototypeByType=gs,y.getRecusriveParentsIds=Kd,y.getReferenceEntityId=g,y.getReferencedEntitiesStateOrErrors=Nd,y.getReferencedEntityStateOrErrors=Ip,y.getReferencedIds=qd,y.getRelatedCanvasElementsOnTheLeft=_n,y.getRelatedCanvasElementsOnTheLeftFromTransfer=Gq,y.getRelatedCanvasElementsOnTheRight=Ji,y.getRootEntryPointScopeOwner=Zp,y.getScopeOwner=zt,y.getStateClassFromType=tJ,y.getTerminationReferenceSchema=o5,y.getTerminationTypeSchema=s5,y.getUsedArgFromDeclaration=Sq,y.getUsedReturnFromDeclaration=Fq,y.getValueReadingEntityReferenceSchema=fD,y.getValueReadingEntityTypeSchema=li,y.getValueWritingEntityReferenceSchema=q3,y.getValueWritingEntityTypeSchema=ms,y.getVariableFromInputMapping=DO,y.getVariableFromReturnVariablePointer=wO,y.getVariableReferenceSchema=Pi,y.getVariableTypeSchema=In,y.getVariablesFromArgumentDeclarations=Zd,y.getVariablesFromInputMaps=OO,y.getVariablesFromOutputMapping=VO,y.getVariablesFromOutputMaps=CO,y.getVariablesFromReturnDeclarations=PO,y.getVariablesInSameOrHigherScope=dp,y.getWrites=Lp,y.groupCallsBasedOnParallelizableExecution=Mq,y.handleAfterEntityImplementationSideEffects=vO,y.handleBeforeEntityImplementationSideEffects=mO,y.httpRequestBodyArgument=Ws,y.httpRequestBodyArgumentRef=Jm,y.httpRequestBodyDataType=Wm,y.httpRequestHeadersArgument=Js,y.httpRequestHeadersArgumentRef=Zm,y.httpRequestHeadersDataType=qm,y.httpRequestMethodArgument=Zs,y.httpRequestMethodArgumentRef=xm,y.httpRequestMethodDataType=km,y.httpRequestMethodDataTypeRef=Sm,y.httpRequestOperation=wa,y.httpRequestOperationErrorValueDescriptor=bl,y.httpRequestOperationErrorValueDescriptorDatatype=p0,y.httpRequestOperationErrorValueDescriptorRef=c0,y.httpRequestOperationRef=o0,y.httpRequestOperationRefEight=l0,y.httpRequestOperationRefFive=a0,y.httpRequestOperationRefFour=n0,y.httpRequestOperationRefNine=u0,y.httpRequestOperationRefSeven=d0,y.httpRequestOperationRefSix=s0,y.httpRequestOperationRefThree=i0,y.httpRequestOperationRefTwo=r0,y.httpRequestQueryParamsArgument=Il,y.httpRequestQueryParamsArgumentRef=$m,y.httpRequestQueryParamsDataType=Gm,y.httpRequestVariableURLArgument=qs,y.httpRequestVariableURLArgumentRef=Um,y.httpRequestVariableURLDataType=jm,y.httpRequestVariableURLDataTypeRef=Nm,y.httpResponseBodyReturnDataType=t0,y.httpResponseBodyReturnDataTypeRef=Qm,y.httpResponseBodyReturnReturn=Hs,y.httpResponseBodyReturnReturnRef=e0,y.httpResponseCodeDataType=zm,y.httpResponseCodeReturn=Ys,y.httpResponseCodeReturnRef=Ym,y.httpResponseHeadersDataType=Xm,y.httpResponseHeadersDataTypeRef=Hm,y.httpResponseHeadersReturn=zs,y.httpResponseHeadersReturnRef=Km,y.implement=Sd,y.inferArgumentDeclarationDataType=C1,y.inferDataType=xr,y.inferInputMapDataType=ap,y.inferOutputMapDataType=op,y.inferPropertyDataType=_1,y.inferReturnDeclarationDataType=sp,y.inferValueDescriptorDataType=M1,y.inferVariableDeclarationDataType=B1,y.inferVariableInstanceDataType=g1,y.initBaseProjectEntity=Jp,y.initProject=VP,y.isPromise=Cp,y.iterateOverListActionDescriptorListArgumentDeclaration=J0,y.iterateOverListActionDescriptorListArgumentDeclarationDataType=Z0,y.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=k0,y.iterateOverListActionDescriptorListArgumentDeclarationParentRef=q0,y.iterateOverListLoopActionDescriptor=mi,y.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=Y0,y.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=W0,y.iterateOverListLoopBodyActionDescriptor=ga,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=iv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=rv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=av,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=nv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=eo,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=H0,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=z0,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=K0,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=tv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Q0,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=X0,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=ev,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=uv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=dv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=ov,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=lv,y.iterateOverObjectKeysLoopActionDescriptor=Fn,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=pv,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=cv,y.iterateOverObjectKeysLoopBodyActionDescriptor=Pl,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=bv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Iv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=Av,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Rv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ol,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=yv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=fv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=hv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Ev,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=vv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=mv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Tv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=Vv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Pv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Ov,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=wv,y.iterateOverObjectValuesLoopActionDescriptor=xn,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=gv,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Cv,y.iterateOverObjectValuesLoopBodyActionDescriptor=Vl,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Gv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$v,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=Fv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Sv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=wl,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=_v,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Bv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Mv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Lv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Nv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Uv,y.iterateOverStringActionDescriptorDynamicReturnDeclaration=B0,y.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=g0,y.iterateOverStringActionDescriptorStringArgumentDeclaration=C0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=w0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=P0,y.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=V0,y.iterateOverStringLoopActionDescriptor=Ca,y.iterateOverStringLoopBodyActionDescriptor=Qs,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=G0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=F0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=S0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Al,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=M0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=_0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=N0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Dl,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=U0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=L0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=j0,y.joinListOperation=ul,y.joinListOperationError=jy,y.joinListOperationErrorParentRef=Uy,y.joinListOperationFirstListArgument=By,y.joinListOperationFirstListArgumentParentRef=gy,y.joinListOperationFirstListArgumentRef=Dy,y.joinListOperationFirstListDataType=Oy,y.joinListOperationResultListDataType=Cy,y.joinListOperationResultListReturn=Ly,y.joinListOperationResultListReturnParentRef=Ny,y.joinListOperationResultListReturnRef=Vy,y.joinListOperationSecondListArgument=My,y.joinListOperationSecondListArgumentParentRef=_y,y.joinListOperationSecondListArgumentRef=Py,y.joinListOperationSecondListDataType=wy,y.joinListWithLastSeparator=ie,y.joinStringsOperation=Pa,y.joinStringsOperationDynamicStringArgument=iy,y.joinStringsOperationDynamicStringArgumentParentRef=ry,y.joinStringsOperationDynamicStringArgumentRef=ey,y.joinStringsOperationDynamicStringDataType=ty,y.joinStringsOperationError=Qf,y.joinStringsOperationErrorParentRef=Xf,y.joinStringsOperationFirstStringArgument=Fs,y.joinStringsOperationFirstStringArgumentParentRef=kf,y.joinStringsOperationFirstStringArgumentRef=jf,y.joinStringsOperationFirstStringDataType=$f,y.joinStringsOperationResultStringDataType=xf,y.joinStringsOperationResultStringReturn=Oa,y.joinStringsOperationResultStringReturnParentRef=Kf,y.joinStringsOperationResultStringReturnRef=Ff,y.joinStringsOperationSecondStringArgument=xs,y.joinStringsOperationSecondStringArgumentParentRef=Hf,y.joinStringsOperationSecondStringArgumentRef=Gf,y.joinStringsOperationSecondStringDataType=Sf,y.joinStringsOperationSeparatorStringArgument=zf,y.joinStringsOperationSeparatorStringArgumentParentRef=Yf,y.joinStringsOperationSeparatorStringArgumentRef=Zf,y.joinStringsOperationSeparatorStringDataType=Wf,y.joinStringsOperationSeparatorStringDataTypeDefaultValue=Jf,y.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=qf,y.keyValuePrototype=$n,y.lowercaseFirstLetter=Od,y.manualFlowActionDescriptorDeclarationArgumentDeclaration=Rl,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=E0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=T0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=I0,y.manualFlowLoopActionDescriptor=Ks,y.manualFlowLoopActionDescriptorDynamicReturnDeclaration=v0,y.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=m0,y.manualFlowLoopBodyActionDescriptor=Xs,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=R0,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=b0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=D0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=A0,y.mapActionDescriptorToTypeItRepresents=zq,y.mergeEntityErrorsList=q9,y.mergeListOfEntities=Jq,y.methodDefaultValue=Fm,y.mockClientProject=kA,y.moreThanOrEqualCondition=Wn,y.moreThanOrEqualConditionLeftHandArgument=LE,y.moreThanOrEqualConditionLeftHandArgumentDataType=ME,y.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=_E,y.moreThanOrEqualConditionLeftHandArgumentParentRef=NE,y.moreThanOrEqualConditionRightHandArgument=GE,y.moreThanOrEqualConditionRightHandArgumentDataType=jE,y.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=UE,y.moreThanOrEqualConditionRightHandArgumentParentRef=$E,y.notEmptyCondition=an,y.notEmptyConditionArgument=gE,y.notEmptyConditionRef=CE,y.nullPrototype=Qp,y.numberAdditionOperation=Ss,y.numberAdditionOperationDynamicSummandArgument=Ef,y.numberAdditionOperationDynamicSummandArgumentType=Tf,y.numberAdditionOperationDynamicSummandArgumentTypeParentRef=vf,y.numberAdditionOperationError=mf,y.numberAdditionOperationErrorParentRef=hf,y.numberAdditionOperationFirstNumberArgument=il,y.numberAdditionOperationFirstNumberArgumentRef=of,y.numberAdditionOperationFirstNumberDataType=df,y.numberAdditionOperationRef=ff,y.numberAdditionOperationRefThree=al,y.numberAdditionOperationRefTwo=yf,y.numberAdditionOperationResultNumberDataType=pf,y.numberAdditionOperationResultNumberReturn=sl,y.numberAdditionOperationResultNumberReturnRef=cf,y.numberAdditionOperationSecondNumberArgument=nl,y.numberAdditionOperationSecondNumberArgumentRef=lf,y.numberAdditionOperationSecondNumberDataType=uf,y.numberPrototype=me,y.numberSubtractionOperation=dl,y.numberSubtractionOperationDynamicSubtrahendArgument=Lf,y.numberSubtractionOperationDynamicSubtrahendArgumentType=Nf,y.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Mf,y.numberSubtractionOperationError=_f,y.numberSubtractionOperationErrorParentRef=Bf,y.numberSubtractionOperationFirstNumberArgument=Pf,y.numberSubtractionOperationFirstNumberArgumentRef=If,y.numberSubtractionOperationFirstNumberDataType=bf,y.numberSubtractionOperationRef=ol,y.numberSubtractionOperationRefThree=Cf,y.numberSubtractionOperationRefTwo=wf,y.numberSubtractionOperationResultNumberDataType=Of,y.numberSubtractionOperationResultNumberReturn=gf,y.numberSubtractionOperationResultNumberReturnRef=Df,y.numberSubtractionOperationSecondNumberArgument=Vf,y.numberSubtractionOperationSecondNumberArgumentRef=Rf,y.numberSubtractionOperationSecondNumberDataType=Af,y.numberValueAutogenerationSchema=rc,y.parallelExecutionOperation=Rr,y.parallelExecutionOperationError=Gh,y.parallelExecutionOperationErrorParentRef=$h,y.parallelExecutionOperationListOfExecutionResultsDataType=Lh,y.parallelExecutionOperationListOfExecutionResultsReturn=vl,y.parallelExecutionOperationListOfExecutionResultsReturnRef=Nh,y.parallelExecutionOperationListOfFunctionsArgument=ml,y.parallelExecutionOperationListOfFunctionsArgumentDatatype=Mh,y.parallelExecutionOperationListOfFunctionsArgumentRef=_h,y.parallelExecutionOperationListOfFunctionsBlueprint=Bh,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=gh,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Ch,y.parallelExecutionOperationRef=Uh,y.parallelExecutionOperationRefThree=jh,y.persistedBuiltInBaseEntity=Ot,y.persistedBuiltInBaseEntityDatabaseProperty=Zn,y.persistedBuiltInBaseEntityDatabasePropertyDataType=uE,y.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=GP,y.persistedBuiltInBaseEntityDatabasePropertyParentRef=cE,y.persistedBuiltInBaseEntityDatabasePropertyRef=lE,y.persistedBuiltInBaseEntityPrimaryKeyProperty=qn,y.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=EE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=fE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=pE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=IE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=TE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=hE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=yE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=vE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=mE,y.processOutputGlobalValueDescriptorDataType=JE,y.processOutputGlobalValueDescriptorReturn=uo,y.processOutputGlobalValueDescriptorReturnRef=qE,y.projectPublicationCompletedGlobalEvent=lo,y.propertyToZodSchema=lI,y.relationalDatabaseBuiltInBaseEntity=Mr,y.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=xl,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=aE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=nE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=sE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=iE,y.relationalDatabaseBuiltInBaseEntityDefaultProperty=Fl,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=rE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=eE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=tE,y.relationalDatabaseBuiltInBaseEntityIdentifierProperty=ro,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=JT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=ZT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=qT,y.relationalDatabaseBuiltInBaseEntityMinSizeProperty=ao,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=QT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=KT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=XT,y.relationalDatabaseBuiltInBaseEntityPasswordProperty=no,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=HT,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=$P,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=zT,y.relationalDatabaseBuiltInBaseEntityRef=kn,y.relationalDatabaseBuiltInBaseEntityUsernameProperty=io,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=YT,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=jP,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=WT,y.resolveActionDescriptorName=G1,y.resolveBaseEntityName=L1,y.resolveBuiltInBaseEntityDataTypeLabel=U1,y.resolveClonedEntityProject=ft,y.resolveConditionOperatorLabel=Cd,y.resolveDataType=Pd,y.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=_p,y.resolveDataTypeLabel=Vd,y.resolveDefinitionEntityDataTypeLabel=M7,y.resolveEntityDataTypeLabel=_7,y.resolveEntityName=G,y.resolveFirstCallsSecond=Nq,y.resolveFirstWritesSecond=Lq,y.resolvePrimaryKeyProperty=Xq,y.resolvePrimitiveEntityName=$1,y.resolveSearchName=j1,y.resolveVariableScope=C7,y.sequentialExecutionOperation=ti,y.sequentialExecutionOperationError=am,y.sequentialExecutionOperationErrorParentRef=nm,y.sequentialExecutionOperationListOfExecutionResultsDataType=tm,y.sequentialExecutionOperationListOfExecutionResultsReturn=El,y.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=im,y.sequentialExecutionOperationListOfExecutionResultsReturnRef=em,y.sequentialExecutionOperationListOfFunctionsArgument=Tl,y.sequentialExecutionOperationListOfFunctionsArgumentDatatype=Qh,y.sequentialExecutionOperationListOfFunctionsArgumentParentRef=rm,y.sequentialExecutionOperationListOfFunctionsArgumentRef=Xh,y.sequentialExecutionOperationListOfFunctionsBlueprint=Kh,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=Hh,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=zh,y.softDeletePersistedEntityMethod=SP,y.softDeletePersistedEntityMethodParentRef=bE,y.sortCallsBasedOnExecutionDependencies=AO,y.sortChildrenEntitiesBasedOnExecutionDependencies=_q,y.splitListOperation=pl,y.splitListOperationError=th,y.splitListOperationErrorParentRef=eh,y.splitListOperationFirstOutputListDataType=Zy,y.splitListOperationFirstOutputListReturn=Hy,y.splitListOperationFirstOutputListReturnParentRef=zy,y.splitListOperationFirstOutputListReturnRef=cl,y.splitListOperationInputListArgument=Jy,y.splitListOperationInputListArgumentParentRef=qy,y.splitListOperationInputListArgumentRef=Sy,y.splitListOperationInputListDataType=Fy,y.splitListOperationSecondOutputListDataType=Ky,y.splitListOperationSecondOutputListReturn=Qy,y.splitListOperationSecondOutputListReturnParentRef=Xy,y.splitListOperationSplitIndexArgument=Yy,y.splitListOperationSplitIndexArgumentParentRef=Wy,y.splitListOperationSplitIndexArgumentRef=xy,y.splitListOperationSplitIndexDataType=ky,y.splitStringOperation=ll,y.splitStringOperationError=Iy,y.splitStringOperationErrorParentRef=Ey,y.splitStringOperationFirstPartResultStringDataType=ly,y.splitStringOperationFirstPartResultStringReturn=Ty,y.splitStringOperationFirstPartResultStringReturnParentRef=vy,y.splitStringOperationFirstPartResultStringReturnRef=dy,y.splitStringOperationIndexArgument=hy,y.splitStringOperationIndexArgumentParentRef=yy,y.splitStringOperationIndexArgumentRef=sy,y.splitStringOperationIndexDataType=oy,y.splitStringOperationSecondPartResultStringDataType=cy,y.splitStringOperationSecondPartResultStringReturn=LP,y.splitStringOperationSecondPartResultStringReturnParentRef=my,y.splitStringOperationSecondPartResultStringReturnRef=uy,y.splitStringOperationStringArgument=fy,y.splitStringOperationStringArgumentParentRef=py,y.splitStringOperationStringArgumentRef=ny,y.splitStringOperationStringDataType=ay,y.stringPrototype=ne,y.stringValueAutogenerationSchema=tc,y.suggestNewIdForEntity=yp,y.test_primitive_entities_export=jJ,y.toCamelCase=g7,y.toEntityState=nr,y.toKebabCase=N1,y.toLowerCaseKebabCase=wd,y.toPascalCase=B7,y.untypedDataPrototype=At,y.updateErrorsList=Ye,y.updateValueReader=Wq,y.urlDefaultValue=Lm,y.uuidPrototype=Qr,y.validateArgumentDeclarationName=pp,y.validateCalledByErrorIdInAction=Aq,y.validateCalledByIdInAction=Rq,y.validateCallers=uO,y.validateConditionEntityDeclaration=Pq,y.validateDataOperation=Qi,y.validateDataOperationDataToValidateArgument=Dm,y.validateDataOperationDataToValidateArgumentParentRef=Am,y.validateDataOperationDataToValidateArgumentRef=bm,y.validateDataOperationDataToValidateDataType=Rm,y.validateDataOperationEntityToMatchTypeArgument=Vm,y.validateDataOperationEntityToMatchTypeArgumentParentRef=wm,y.validateDataOperationEntityToMatchTypeArgumentRef=Om,y.validateDataOperationEntityToMatchTypeDataType=Pm,y.validateDataOperationError=_m,y.validateDataOperationErrorParentRef=Bm,y.validateDataOperationOutputEntityDeclaration=gm,y.validateDataOperationOutputEntityDeclarationParentRef=Cm,y.validateDefinitionEntityName=gd,y.validateEntryCaller=lO,y.validateErrorCaller=dO,y.validateFunctionCallDeclaration=pO,y.validateFunctionDeclarationName=lp,y.validateGeneratedEntityParentIsNotBuiltInEntity=Tq,y.validateGeneration=mq,y.validateGenerationTarget=ot,y.validateGenerationUpdate=vq,y.validateLoopEntityDeclaration=wq,y.validateName=N7,y.validateOperationEntityDeclaration=fO,y.validatePropertyName=cp,y.validateReachability=fi,y.validateReadsValueInActionPayload=Dq,y.validateReferenceObject=Md,y.validateReferenceToOne=bp,y.validateReferences=Et,y.validateReturnDeclarationName=fp,y.validateSuccessCaller=oO,y.validateValueReaderGenerationUpdate=ws,y.validateValueWritter=wp,y.validateVariableDeclarationName=up,y.validateVariableInternalCallUse=Vp,y.valueAutogenerationCurrentDateAndTimeSchema=JA,y.valueAutogenerationGenericSchema=Xo,y.valueAutogenerationOptions=nc,y.valueAutogenerationOptionsSchema=qA,y.valueAutogenerationRandomBooleanSchema=ec,y.valueAutogenerationRandomDateBetweenSchema=tD,y.valueAutogenerationRandomDateFromSchema=QA,y.valueAutogenerationRandomDateSchema=td,y.valueAutogenerationRandomDateUntilSchema=eD,y.valueAutogenerationRandomNumberBetweenSchema=zA,y.valueAutogenerationRandomNumberFromSchema=WA,y.valueAutogenerationRandomNumberSchema=Qo,y.valueAutogenerationRandomNumberUntilSchema=YA,y.valueAutogenerationRandomSchema=ls,y.valueAutogenerationRandomTextBetweenSchema=XA,y.valueAutogenerationRandomTextFromSchema=HA,y.valueAutogenerationRandomTextSchema=ed,y.valueAutogenerationRandomTextUntilSchema=KA,y.valueAutogenerationRangeValueTypesSchema=ds,y.valueAutogenerationUniqueSchema=Qu,y.waitOperation=St,y.waitOperationMillisecondsNumberArgument=Ki,y.waitOperationMillisecondsNumberArgumentRef=xh,y.waitOperationMillisecondsNumberDataType=kh,y.waitOperationOperationError=Jh,y.waitOperationOperationErrorParentRef=qh,y.waitOperationRef=Zh,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
|
408
|
+
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:a,modifiedData:r}}get allBasePropertiesFromExtendedAndImplementedEntities(){return u([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract),...e],[])])}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[]),...this.implements.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])].filter(e=>!!e.abstract))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new O({id:`${this.id}--${I.InvalidParentUpdate}`,code:I.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(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{hr.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{hr.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=R.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Le(this,this.project);return(r=this.knownVersions)==null||r.set(this.version,e),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),r.push(...o.added),a.push(...o.removed)}return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Le(c,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];if(this.initialData.parent){const d=g(this.initialData.parent),o=this.project.get(d);o&&(this.setParent(o,null),e.push(o))}return this.initialData.extends.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addExtension(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),this.initialData.implements.forEach(d=>{const o=g(d),l=this.project.get(o);l&&(this.addImplementation(l),l.type!==n.BuiltInBaseEntity&&e.push(l))}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],r=[],a=[],d=[];this.initialized=!0,this.captureVersion();const{updated:o,added:l,removed:c,affected:h}=this.syncImplementationProperties(e);t.push(...o),r.push(...l),a.push(...c),d.push(...h);const{updated:p,added:v,removed:E,affected:P}=this.addExtendedProperties(e);return t.push(...p),r.push(...v),a.push(...E),d.push(...P),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],r=[],a=[],d=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}setParent(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"set-parent"))){var r;return((r=this.parent)==null?void 0:r.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,b.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}addExtension(e){return this.extends.includes(e)||this.extends.push(e),this}removeExtension(e){return this.extends=this.extends.filter(t=>t.id!==e.id),this}addImplementation(e){return this.implements.includes(e)||this.implements.push(e),this}removeImplementation(e){return this.implements=this.implements.filter(t=>t.id!==e.id),this}removeProperty(e){return this.properties=this.properties.filter(t=>t.id!==e.id),this}addMethod(e){return this.methods.includes(e)||(this.methods.push(e),this.suggestedMethods=this.suggestedMethods.filter(t=>t.name!==e.name)),this}removeMethod(e){return this.methods=this.methods.filter(t=>t.id!==e.id),this}addProperty(e){return this.properties.includes(e)||(this.properties.push(e),this.suggestedProperties=this.suggestedProperties.filter(t=>t.name!==e.name)),this}addSuggestedProperty(e){return this.suggestedProperties.includes(e)||this.suggestedProperties.push(e),this}addSuggestedMethod(e){return this.suggestedMethods.includes(e)||this.suggestedMethods.push(e),this}removeSuggestedProperty(e){return this.suggestedProperties=this.suggestedProperties.filter(t=>t.id!==e.id),this}removeSuggestedMethod(e){return this.suggestedMethods=this.suggestedMethods.filter(t=>t.id!==e.id),this}addAbstractMethod(e){return this.abstractMethods.includes(e)||this.abstractMethods.push(e),this}removeAbstractMethod(e){return this.abstractMethods=this.abstractMethods.filter(t=>t.id!==e.id),this}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.methods=this.initialData.methods.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(e),r}),this.extends=this.initialData.extends.map(t=>V(t,this.project)),this.implements=this.initialData.implements.map(t=>V(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}syncImplementationProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.implementedPropertiesFromOriginalParents,c=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return l.filter(p=>!c.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===p.id})).forEach(p=>{if(this.properties.find(w=>{var C;return((C=w.implements)==null?void 0:C.id)===p.id}))return;const E=this.properties.find(w=>w.name===p.name&&!!w.abstract&&!w.implements);if(E){E.implements=p,E.abstract=!1;return}const P=p.clone(e,this,R.UUID.uuid());P.initChildren(e),r.push(P),e==null||e.add(P,b.Added),P.setImplements(p,e),P.metaSync({abstract:!1},e),this.addProperty(P)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addExtendedProperties(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"add-extended-properties"))){const t=[],r=[],a=[],d=[],o=this.properties,l=this.extendedPropertiesFromOriginalParents,c=l.filter(p=>l.find(E=>{var P;return((P=E.implements)==null?void 0:P.id)===p.id})?!1:!p.abstract),h=new Set(o.map(p=>p.name));return c.forEach(p=>{if(h.has(p.name))return;h.add(p.name);const v=p.clone(e,this,R.UUID.uuid());v.initChildren(e),r.push(v),e==null||e.add(v,b.Added),this.addProperty(v)}),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSuggestions(){return this.implements.forEach(e=>{B5(this,e).forEach(a=>{const d=a.toJSON();d.id=`_suggestion--parent--${this.id}--${a.id}`;const o=V(d,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),_5(this,e).forEach(a=>{const d=`_suggestion--parent--${this.id}--${a.id}`,o=a.implementAsFunctionDeclaration(d),l=V(o,this.project);if(l.suggestion=!0,l.setParent(this,null),l.initChildren(null),l.inputs.forEach(c=>{c.suggestion=!0}),l.returnStatements.length){const c=l.returnStatements[0];c.suggestion=!0,c.outputs.forEach(h=>{h.suggestion=!0})}this.addSuggestedMethod(l)})}),this}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.x=e.x||this.x,this.y=e.y||this.y,this.static=e.static||this.static,this.abstract=e.abstract||this.abstract,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await Le.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await Le.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){const r=[],a=[],d=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(a.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(l=>{const{updated:c,removed:h,added:p}=l.entity.onDetachedDependencyRemoved(this,l.field,t);r.push(...c),a.push(...h),d.push(...p)}),this.properties.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.methods.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.abstractMethods.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.suggestedProperties.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),this.suggestedMethods.forEach(l=>{const{updated:c,removed:h}=l.remove({ignoreUpstream:!0},t);r.push(...c),a.push(...h)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const l=this.parent.setEntity(null);r.push(l)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:u(d),updated:u(r),removed:u(a),affected:u(o),self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){const t=[],r=[],a=[],d=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.properties.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.methods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.abstractMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedProperties.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),this.suggestedMethods.forEach(o=>{const{updated:l}=o.restore({},e);r.push(...l)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:u(t),updated:u(r),removed:u(a),affected:u(d),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(r=>r.toFlat(e)),...this.implements.flatMap(r=>r.toFlat(e)),...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(r=>r.toFlatIds(e)),...this.implements.flatMap(r=>r.toFlatIds(e)),...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.parent.toFlatIds(e)])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=Z){var r,a,d,o,l;let t;return(r=e.seenEntityMaps)!=null&&r.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||pt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(a=e.seenEntities)!=null&&a.has(t)||(d=e.seenEntities)!=null&&d.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(l=e.seenEntities)==null||l.add(this.id),{id:t,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(c=>c.toJSONClone({...e,newId:null})),methods:this.methods.map(c=>c.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(c=>c.toJSONClone({...e,newId:null})),implements:this.implements.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),extends:this.extends.map(c=>c.type===n.BuiltInBaseEntity?c.toJSON():c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toReference(e)),methods:this.methods.map(a=>a.toReference(e)),abstractMethods:this.abstractMethods.map(a=>a.toReference(e)),implements:this.implements.map(a=>a.toReference(e)),extends:this.extends.map(a=>a.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e)),...this.implements.flatMap(r=>r.toFlatJSON(e)),...this.extends.flatMap(r=>r.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.toFlatGenerationTarget(e)),...this.implements.filter(r=>r.type===n.DefinitionEntity).flatMap(r=>r.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=g5(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,"",T().toISOString(),this,!0,"clone-entity")),t=null,r=null,a=!0){var w,C,U;let d=ft(t,this);const o=this.toJSON(),l=r||R.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const c=l.split("-id"),h=c[c.length-1||0]||l;o.id=l,o.version=R.UUID.uuid();const p=lt(o,d);t&&p.setParent(t,null),a&&p.subscribe(),p.initChildren(e),e==null||e.add(p,b.Added);const v=(w=this.properties)==null?void 0:w.map(S=>S.clone(e,p,R.UUID.uuid(),a));p.properties=v;const E=(C=this.methods)==null?void 0:C.map((S,B)=>S.clone(e,p,h+"-method-"+B+"-id",a));p.methods=E;const P=(U=this.abstractMethods)==null?void 0:U.map((S,B)=>S.clone(e,p,h+"-abstract-method-"+B+"-id",a));return p.abstractMethods=P,e==null||e.attemptAutoclose("clone-entity",this.id),p}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"implement-definition-entity")),r){const a=Sd(this,e,t,r);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),a}getAllInteractiveMethods(){const e=this.implements.filter(r=>r.type===n.DefinitionEntity||r.type===n.BuiltInBaseEntity&&r.interactive);return u([...this.methods,...this.extends.flatMap(r=>r.getAllInteractiveMethods()),...e.flatMap(r=>r.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const r=[],a=[],d=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[];e.forEach(p=>{l.find(E=>G(E,this.project)===G(p,this.project))||l.push(p)});const c=this.properties.filter(p=>!p.dataType);l.forEach(p=>{var U,S;const v=c.find(B=>G(B,this.project)===G(p,this.project));if(!v)return;const P=Pn(p.parent).getMasterInputWithValueWritterFromAllInstances(p),w=xr(P,t),C=w==null?void 0:w.clone(t,v,R.UUID.uuid(),!0);if(C){const B=(U=v.dataType)==null?void 0:U.merge(C,t);v.dataType&&(B==null?void 0:B.self.id)!==v.dataType.id&&v.dataType.remove({ignoreUpstream:!1},t),C.id!==((S=B==null?void 0:B.self)==null?void 0:S.id)&&C.remove({ignoreUpstream:!1},t),B!=null&&B.self&&(B.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(B.self,b.Added),v.setDataType(B.self),t==null||t.add(v,b.Updated))}p.setDeclaration(v),t==null||t.add(p,b.Updated)});const h=[];return l.forEach(p=>{if(!p.declaration){h.push(p);return}}),h.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(h.forEach(p=>{var B,$,k,W;const v=this.properties.find(ee=>G(ee,this.project)===G(p,this.project));if(v){if(p.setDeclaration(v),!v.getDataType(t)){const ce=Pn(p.parent).getMasterInputWithValueWritterFromAllInstances(p),Te=xr(ce),Q=Te==null?void 0:Te.clone(t,v,R.UUID.uuid(),!0);if(Q){const se=(B=v.dataType)==null?void 0:B.merge(Q,t);v.dataType&&(se==null?void 0:se.self.id)!==v.dataType.id&&v.dataType.remove({ignoreUpstream:!1},t),Q.id!==(($=se==null?void 0:se.self)==null?void 0:$.id)&&Q.remove({ignoreUpstream:!1},t),se!=null&&se.self&&(se.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(se.self,b.Added),v.setDataType(se.self),t==null||t.add(v,b.Updated))}}return}const E={id:R.UUID.uuid(),type:n.Property,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:G(p,this.project),description:p.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:p.index,implements:null,dataType:null,parent:this.toReference()},P=V(E,this.project);P.setParent(this,t),P.initChildren(t),t==null||t.add(P,b.Added);const C=Pn(p.parent).getMasterInputWithValueWritterFromAllInstances(p),U=xr(C),S=U==null?void 0:U.clone(t,P,R.UUID.uuid(),!0);if(S){const ee=(k=P.dataType)==null?void 0:k.merge(S,t);P.dataType&&(ee==null?void 0:ee.self.id)!==P.dataType.id&&P.dataType.remove({ignoreUpstream:!1},t),S.id!==((W=ee==null?void 0:ee.self)==null?void 0:W.id)&&S.remove({ignoreUpstream:!1},t),ee!=null&&ee.self&&(ee.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(ee.self,b.Added),P.setDataType(ee.self),t==null||t.add(P,b.Updated))}return this.addProperty(P),p.setDeclaration(P),t==null||t.add(p,b.Updated),P}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:u(r),updated:u(a),removed:u(d),affected:u(o),self:this})}};f(Le,"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,...r)=>null}),f(Le,"type",n.DefinitionEntity),f(Le,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),f(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),f(Le,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),f(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),f(Le,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),f(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),f(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),f(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let zi=Le;function nJ(i){const s=d6(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Ns=class Ns extends rt{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(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.extends=this.initialData.extends.map(r=>V(r,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=L,...t){return await Ns.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e)),...this.extends.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e)),...this.extends.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=Z){return{id:this.id+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=Z){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=nJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}implement(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),null,!0,"implement-built-in-base-entity")),r){const a=Sd(this,e,t,r);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),a}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Ns&&e.push(...r.getAllInteractiveMethods())})),u(e)}};f(Ns,"repository",{APILoad:async(e,...t)=>null});let Yr=Ns;function aJ(i){const s=Q9(),e=i.toJSON();s.safeParse(e).success;const r=[];return Ye(i.errors,r)}const Qd=class Qd extends rt{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(r=>{const a=V(r,this.project);return a.setParent(this,null),a.initChildren(null),a}),this.methods=this.initialData.methods.map(r=>{const a=V(r,this.project);return a.parent=this,a}),this.abstractMethods=this.initialData.abstractMethods.map(r=>{const a=V(r,this.project);return a.parent=this,a})}get allBasePropertiesFromExtendedAndImplementedEntities(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(a=>!a.abstract);return[...e,...r]},[]))}get extendedPropertiesFromOriginalParents(){return u(this.extends.reduce((e,t)=>{const r=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(a=>!a.abstract);return[...e,...r]},[]))}get implementedPropertiesFromOriginalParents(){return u([...this.extends.reduce((e,t)=>{const r=t.implementedPropertiesFromOriginalParents,a=[...t.ownDeclaredProperties].filter(d=>!!d.abstract&&!r.find(o=>o.name===d.name));return[...r,...a,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=L,...t){return await Qd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(r=>r.toFlat(e)),...this.methods.flatMap(r=>r.toFlat(e)),...this.abstractMethods.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(r=>r.toFlatIds(e)),...this.methods.flatMap(r=>r.toFlatIds(e)),...this.abstractMethods.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=Z){return{id:this.id+"--"+R.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=Z){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(r=>r.toFlatJSON(e)),...this.methods.flatMap(r=>r.toFlatJSON(e)),...this.abstractMethods.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(r=>r.toFlatGenerationTarget(e)),...this.methods.flatMap(r=>r.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=aJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(r=>r.type===n.BuiltInBaseEntity&&r.interactive||r.type===n.PrimitiveEntity).forEach(r=>{r instanceof Yr&&e.push(...r.getAllInteractiveMethods())}),u(e)}};f(Qd,"repository",{APILoad:async(e,...t)=>null});let fr=Qd;function lt(i,s){if(!i)throw new Error("Entity is null");const e=s.get(i.id);switch(i.type){case n.LiteralValue:return e||new Bn(i,s);case n.DefinitionEntity:return e||new zi(i,s);case n.PrimitiveEntity:return e||new fr(i,s);case n.FunctionDeclaration:return e||new _i(i,s);case n.GlobalEvent:return e||new Vn(i,s);case n.DataType:return e||new wn(i,s);case n.Property:return e||new gi(i,s);case n.FunctionCall:return e||new qi(i,s);case n.Condition:return e||new Li(i,s);case n.Operation:return e||new Mi(i,s);case n.VariableDeclaration:return e||new ji(i,s);case n.VariableInstance:return e||new Ui(i,s);case n.OutputMap:return e||new Zr(i,s);case n.ReturnDeclaration:return e||new rr(i,s);case n.ArgumentDeclaration:return e||new Si(i,s);case n.InputMap:return e||new kr(i,s);case n.Project:return e||new R(i);case n.InstalledProject:return e||new Gi(i,s);case n.ActionDescriptor:return e||new qe(i,s);case n.ReturnStatement:return e||new Bi(i,s);case n.Loop:return e||new Ni(i,s);case n.Search:return e||new $i(i,s);case n.ValueDescriptor:return e||new Fi(i,s);case n.BuiltInBaseEntity:return e||new Yr(i,s);case n.InternalCall:return e||new gn(i,s);case n.ContinueStatement:return e||new $t(i,s);case n.BreakStatement:return e||new Cn(i,s);case n.GenericReference:return s.get(i.entityId);default:throw new Error("Invalid entity type: "+i.type)}}function V(i,s){if(!i)throw new Error("Entity is null");const e=lt(i,s);return e.subscribe(),e}function sJ(i,s){if(!i)throw new Error("Entity is null");switch(i.type){case n.LiteralValue:return Bn.fromGenerationTarget(i,s);case n.DefinitionEntity:return zi.fromGenerationTarget(i,s);case n.FunctionDeclaration:return _i.fromGenerationTarget(i,s);case n.GlobalEvent:return Vn.fromGenerationTarget(i,s);case n.DataType:return wn.fromGenerationTarget(i,s);case n.Property:return gi.fromGenerationTarget(i,s);case n.FunctionCall:return qi.fromGenerationTarget(i,s);case n.Condition:return Li.fromGenerationTarget(i,s);case n.Operation:return Mi.fromGenerationTarget(i,s);case n.VariableDeclaration:return ji.fromGenerationTarget(i,s);case n.VariableInstance:return Ui.fromGenerationTarget(i,s);case n.OutputMap:return Zr.fromGenerationTarget(i,s);case n.ReturnDeclaration:return rr.fromGenerationTarget(i,s);case n.ArgumentDeclaration:return Si.fromGenerationTarget(i,s);case n.InputMap:return kr.fromGenerationTarget(i,s);case n.InstalledProject:return Gi.fromGenerationTarget(i,s);case n.ReturnStatement:return Bi.fromGenerationTarget(i,s);case n.Loop:return Ni.fromGenerationTarget(i,s);case n.Search:return $i.fromGenerationTarget(i,s);case n.ActionDescriptor:return qe.fromGenerationTarget(i,s);case n.ValueDescriptor:return Fi.fromGenerationTarget(i,s);case n.InternalCall:return gn.fromGenerationTarget(i,s);case n.ContinueStatement:return $t.fromGenerationTarget(i,s);case n.BreakStatement:return Cn.fromGenerationTarget(i,s);default:throw new Error("Invalid entity type: "+i.type)}}const Z={seenEntityMaps:new Map,seenEntities:new Set};class bP{constructor(){f(this,"initialData")}}const L={cascade:!1},RP={APILoad:async(i,...s)=>null},oJ={APICreate:async(i,...s)=>i,APIUpdate:async(i,...s)=>i,APIDelete:async(i,...s)=>i,APIClone:async(i,...s)=>{},APILoadVersion:async(i,s,...e)=>null,...RP};class dJ{}class lJ extends bP{}class uJ{}class cJ{}class pJ{}class qp{}class fJ extends qp{}class yJ extends qp{}class hJ{}class yi{static initReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=V(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=nr(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),s.readsValue.initChildren(null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}static hydrateReadsValue(s){if(s.initialData.readsValue&&s.initialData.readsValue.type!==n.GenericReference)s.readsValue=V(s.initialData.readsValue,s.project);else if(s.initialData.readsValue&&s.initialData.readsValue.type===n.GenericReference){const e=nr(s.initialData.readsValue,s.project);e&&(s.readsValue=e)}if(s.readsValue){if(Qe.includes(s.readsValue.type)){let e=s.parent;mt.includes(e.type)||(e=e.parent);const t=s.type===n.InputMap&&s.parent.type===n.Loop;t&&(e=s.parent.parent),s.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(s)?e.replaceDetachedChild(s,s.readsValue):t||e.subscribeDetachedChild(s.readsValue)}s.readsValue.addValueReader(s)}return s.readsValue}}class Ms{static initWritesValues(s,e){const t=s.initialData.writesValues.reduce((a,d)=>{if(d.type===n.GenericReference||s.writesValues.some(l=>l.id===d.id))return a;const o=V(d,s.project);return o.setValueWriter(s),Qe.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...a,o]},[]),r=[...s.writesValues];return s.writesValues=u([...r,...t]),s.writesValues}}class mJ{}const de=class de extends rt{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{(!de.UUID||de.UUID.isBackup)&&(de.UUID=Lo==null?void 0:Lo()),de.UUID||(de.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),de.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:r=>r}}}static injectUUIDModule(e){de.UUID=e}static validateGenerationTarget(e,t){let r=JSON.parse(JSON.stringify(e));const a=[];return a.push(...ot(r)),{errors:a,modifiedData:r}}onCloseChangeSet(e){this.onCloseChangeSetCallback=e}closeChangeSet(e){this.onCloseChangeSetCallback&&this.onCloseChangeSetCallback(e)}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(a=>a.id===(e==null?void 0:e.id));if(t)return t;const r=this.history.findIndex(a=>T(a.timestamp).isBefore(T(e==null?void 0:e.timestamp)));return r===-1?this.history.push(e):this.history.splice(r,0,e),e}discardChangeSet(e){const t=this.history.findIndex(r=>r.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}redo(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async r=>{await t.init(this),r(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],r=[],a=[];return Object.values(this.detachedDependents).forEach(d=>{const o=d.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),r.push(...o.removed),a.push(...o.affected)}),{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}onDetachedDependencyRemoved(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}onDetachedDependencyRestored(e,t,r){const a=[],d=[],o=[],l=[];return{updated:u(a),added:u(d),removed:u(o),affected:u(l),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=de.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t,r;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new de(this);return(r=this.knownVersions)==null||r.set(this.version,e),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],r=[],a=[],d=[];return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}async restoreVersion(e){var l;const t=[],r=[],a=[],d=[];if(this.version===e)return{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this};if(!this.knownVersions){const c=new Map;for(const[h,p]of this.knownVersions||new Map){if(c.set(h,p),p.activeVersion=!1,p.knownVersions)for(const[v,E]of p.knownVersions)c.set(v,E);p.knownVersions=null}}let o=(l=this.knownVersions)==null?void 0:l.get(e);if(!o){const c=await this.APILoadVersion({},e);if(!c)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new de(c)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}hydrateAncestors(){const e=[],t=[],r=[],a=[];return{updated:u(e),added:u(t),removed:u(r),affected:u(a),self:this}}afterAllChildrenInitialized(e=null){const t=[],r=[],a=[],d=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}addSelfToProject(e){const t=[],r=[],a=[],d=[];return this.subscribe(),this.subscribeToDependencies(),{updated:u(t),added:u(r),removed:u(a),affected:u(d),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.projects=this.initialData.projects.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.variableInstances=this.initialData.variableInstances.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.conditions=this.initialData.conditions.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.operations=this.initialData.operations.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functions=this.initialData.functions.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.events=this.initialData.events.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.functionCalls=this.initialData.functionCalls.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.loops=this.initialData.loops.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.searches=this.initialData.searches.map(t=>{const r=V(t,this);return r.setParent(this,null),r.initChildren(e),r}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.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,"",T().toISOString(),this,!0,"sync-meta"))){const r=dt(this,e);return e.deleted===!0&&!this.deleted?t==null||t.add(this,b.Removed):e.deleted===!1&&this.deleted?t==null||t.add(this,b.Added):r&&(t==null||t.add(this,b.Updated)),super.metaSync(e),this.name=e.name||this.name,this.description=e.description||this.description,this.x=e.x||this.x,this.y=e.y||this.y,t==null||t.attemptAutoclose("sync-meta",this.id),this}async APILoad(e=L,...t){return await de.repository.APILoad(this.id,...t),this}async APICreate(e=L,...t){return await de.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=L,...t){return await de.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=L,...t){return await de.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=L,...t){return await de.repository.APIClone(this.id,...t),this}async APILoadVersion(e=L,t,...r){return await de.repository.APILoadVersion(this.id,t,...r)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(r=>r.toFlat(e)),...this.functions.flatMap(r=>r.toFlat(e)),...this.events.flatMap(r=>r.toFlat(e)),...this.projects.flatMap(r=>r.toFlat(e)),...this.variableDeclarations.flatMap(r=>r.toFlat(e)),...this.variableInstances.flatMap(r=>r.toFlat(e)),...this.conditions.flatMap(r=>r.toFlat(e)),...this.operations.flatMap(r=>r.toFlat(e)),...this.functionCalls.flatMap(r=>r.toFlat(e)),...this.loops.flatMap(r=>r.toFlat(e)),...this.searches.flatMap(r=>r.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(r=>r.toFlatIds(e)),...this.functions.flatMap(r=>r.toFlatIds(e)),...this.events.flatMap(r=>r.toFlatIds(e)),...this.projects.flatMap(r=>r.toFlatIds(e)),...this.variableDeclarations.flatMap(r=>r.toFlatIds(e)),...this.variableInstances.flatMap(r=>r.toFlatIds(e)),...this.conditions.flatMap(r=>r.toFlatIds(e)),...this.operations.flatMap(r=>r.toFlatIds(e)),...this.functionCalls.flatMap(r=>r.toFlatIds(e)),...this.loops.flatMap(r=>r.toFlatIds(e)),...this.searches.flatMap(r=>r.toFlatIds(e))])}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,r=new Set,a=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(d=>{if(a.includes(d)){t.set(d,d);return}t.set(d,de.UUID.uuid())}),r.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),projects:this.projects.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableDeclarations:this.variableDeclarations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),variableInstances:this.variableInstances.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),conditions:this.conditions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),operations:this.operations.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functions:this.functions.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),events:this.events.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),functionCalls:this.functionCalls.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),loops:this.loops.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null})),searches:this.searches.map(d=>d.toJSONClone({...e,seenEntityMaps:t,seenEntities:r,newId:null}))}}toReference(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+de.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=Z){var r;let t=this.id;return(r=e.seenEntityMaps)!=null&&r.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(a=>a.toReference(e)),functions:this.functions.map(a=>a.toReference(e)),events:this.events.map(a=>a.toReference(e)),projects:this.projects.map(a=>a.toReference(e)),variableDeclarations:this.variableDeclarations.map(a=>a.toReference(e)),variableInstances:this.variableInstances.map(a=>a.toReference(e)),conditions:this.conditions.map(a=>a.toReference(e)),operations:this.operations.map(a=>a.toReference(e)),functionCalls:this.functionCalls.map(a=>a.toReference(e)),loops:this.loops.map(a=>a.toReference(e)),searches:this.searches.map(a=>a.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(r=>r.toFlatJSON(e)),...this.functions.flatMap(r=>r.toFlatJSON(e)),...this.events.flatMap(r=>r.toFlatJSON(e)),...this.projects.flatMap(r=>r.toFlatJSON(e)),...this.variableDeclarations.flatMap(r=>r.toFlatJSON(e)),...this.variableInstances.flatMap(r=>r.toFlatJSON(e)),...this.conditions.flatMap(r=>r.toFlatJSON(e)),...this.operations.flatMap(r=>r.toFlatJSON(e)),...this.functionCalls.flatMap(r=>r.toFlatJSON(e)),...this.loops.flatMap(r=>r.toFlatJSON(e)),...this.searches.flatMap(r=>r.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(r=>r.toFlatGenerationTarget(e)),...this.functions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.events.flatMap(r=>r.toFlatGenerationTarget(e)),...this.projects.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(r=>r.toFlatGenerationTarget(e)),...this.conditions.flatMap(r=>r.toFlatGenerationTarget(e)),...this.operations.flatMap(r=>r.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(r=>r.toFlatGenerationTarget(e)),...this.loops.flatMap(r=>r.toFlatGenerationTarget(e)),...this.searches.flatMap(r=>r.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=D5(),t=this.toJSON();return e.safeParse(t),this.validateChildren(),{success:!0,error:null,data:t}}validateChildren(){this.entities.forEach(e=>e.validate()),this.projects.forEach(e=>e.validate()),this.functions.forEach(e=>e.validate()),this.events.forEach(e=>e.validate()),this.variableDeclarations.forEach(e=>e.validate()),this.variableInstances.forEach(e=>e.validate()),this.conditions.forEach(e=>e.validate()),this.operations.forEach(e=>e.validate()),this.functionCalls.forEach(e=>e.validate()),this.loops.forEach(e=>e.validate()),this.searches.forEach(e=>e.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(t=>t.getErrors()),...this.projects.flatMap(t=>t.getErrors()),...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors()),...this.variableDeclarations.flatMap(t=>t.getErrors()),...this.variableInstances.flatMap(t=>t.getErrors()),...this.conditions.flatMap(t=>t.getErrors()),...this.operations.flatMap(t=>t.getErrors()),...this.functionCalls.flatMap(t=>t.getErrors()),...this.loops.flatMap(t=>t.getErrors()),...this.searches.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(e){return this.entities.find(t=>t.id===e)||null}addDefinitionEntityFromTransfer(e){const t=V(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=V(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=V(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=V(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=V(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=V(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=V(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=V(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=V(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=V(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=V(e,this);return this.addSearch(t),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(r=>r.id===e.id);if(t>-1){const r=this.entities[t];return this.entities.splice(t,1),r}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(r=>r.id===e.id);if(t>-1){const r=this.functions[t];return this.functions.splice(t,1),r}return null}removeExternalProject(e){const t=this.projects.findIndex(r=>r.id===e.id);if(t>-1){const r=this.projects[t];return this.projects.splice(t,1),r}return null}removeGlobalEvent(e){const t=this.events.findIndex(r=>r.id===e.id);if(t>-1){const r=this.events[t];return this.events.splice(t,1),r}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(r=>r.id===e.id);if(t>-1){const r=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),r}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.functionCalls.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.operations.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.loops.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[]),...this.searches.reduce((t,r)=>{const a=it(r);return[...t,...a.filter(d=>d.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.functionCalls.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.conditions.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.operations.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.loops.reduce((t,r)=>{const a=We(r);return[...t,...a]},[]),...this.searches.reduce((t,r)=>{const a=We(r);return[...t,...a]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableInstance);return[...t,...d]},[])]}getVariableDeclarations(){return u([...this.variableDeclarations,...this.getEntryPoints().reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.functionCalls.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.conditions.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.operations.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.loops.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[]),...this.searches.reduce((t,r)=>{const d=We(r).filter(o=>o.type===n.VariableDeclaration);return[...t,...d]},[])])}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(r=>{if(!r.declaration){const a=r.initialData,d=a.declaration.entityId||a.declaration.id,o=t.find(l=>l.id===d);o&&r.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===z.PERSISTED_ENTITY)||null}};f(de,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),f(de,"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,...r)=>null}),f(de,"type",n.Project),f(de,"USER_MANAGED_PARENT_TYPES",[]),f(de,"PARENT_TYPES",[...de.USER_MANAGED_PARENT_TYPES]),f(de,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(de,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(de,"BASE_PROPERTIES",[...de.MUTABLE_BASE_PROPERTIES,...de.INMUTABLE_BASE_PROPERTIES]),f(de,"MUTABLE_META_PROPERTIES",[...de.MUTABLE_BASE_PROPERTIES,"x","y"]),f(de,"INMUTABLE_META_PROPERTIES",[...de.INMUTABLE_BASE_PROPERTIES]),f(de,"META_PROPERTIES",[...de.MUTABLE_META_PROPERTIES,...de.INMUTABLE_META_PROPERTIES]),f(de,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(de,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),f(de,"UPSTREAM_PROPERTIES",[...de.MUTABLE_UPSTREAM_PROPERTIES,...de.INMUTABLE_UPSTREAM_PROPERTIES]),f(de,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),f(de,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(de,"DOWNSTREAM_PROPERTIES",[...de.MUTABLE_DOWNSTREAM_PROPERTIES,...de.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(de,"PROPERTIES",[...de.META_PROPERTIES,...de.UPSTREAM_PROPERTIES,...de.DOWNSTREAM_PROPERTIES]);let R=de;var AP=(i=>(i.PersistChangeSet="persist-change-set",i.CreateSingle="create-single",i.CreateBulk="create-bulk",i.CreateSingleNested="create-single-nested",i.CreateBulkNested="create-bulk-nested",i.Update="update",i.Clone="clone",i.Delete="delete",i.Load="load",i.LoadNested="load-nested",i.LoadVersion="load-version",i))(AP||{});class DP extends qe{constructor(e){super(Rr,e);f(this,"id",He.Parallel);f(this,"name",He.Parallel);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",Rr);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Rr.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=Rr.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=Rr.error?V(Rr.error,this.project):null}}class OP extends qe{constructor(e){super(St,e);f(this,"id",St.id);f(this,"name",St.name);f(this,"description",St.description);f(this,"version",St.version);f(this,"autoexecutable",!1);f(this,"initialData",St);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=St.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=St.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=St.error?V(St.error,this.project):null}}class PP extends qe{constructor(e){super(ti,e);f(this,"id",He.Sequential);f(this,"name",He.Sequential);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",ti);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=ti.inputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.outputs=ti.outputs.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.error=ti.error?V(ti.error,this.project):null}}class vJ extends qe{constructor(s){super(wa,s)}}class TJ extends qe{constructor(s){super(Xi,s)}}class EJ extends qe{constructor(e){super(Qi,e);f(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var r;return((r=t.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"get-entity-to-match-validate-data"))){let r=null;if(e.readsValue){const d=e.readsValue.getDataType(t);d&&d.entity&&d.entity.type===n.DefinitionEntity&&(r=d.entity)}const a=e.getDefaultValue();return!r&&a&&a.valueAsTypeSingle&&!Array.isArray(a.valueAsTypeSingle)&&a.valueAsTypeSingle.type===n.DefinitionEntity&&(r=a.valueAsTypeSingle),r}syncOperationInstance(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const r=[],a=[],d=[],o=[],l=this.getEntityToMatchInputMap(e);if(l){const{added:p,updated:v,removed:E,affected:P}=this.syncEntityToMatchInputMapDataType(l,t);r.push(...v),a.push(...p),d.push(...E),o.push(...P)}const c=this.getDataToValidateInputMap(e);if(c){const{added:p,updated:v,removed:E,affected:P}=this.syncDataToValidateInputMapDataType(c,t);r.push(...v),a.push(...p),d.push(...E),o.push(...P)}const h=this.getOutputDataOutputMap(e);if(h){const{added:p,updated:v,removed:E,affected:P}=this.syncOutputDataOutputMapDataType(h,t);r.push(...v),a.push(...p),d.push(...E),o.push(...P)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:u(r),added:u(a),removed:u(d),affected:u(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var c,h,p;const r=[],a=[],d=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==F.operation[Ke.Validate].inputs.entityToMatch.id)return t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const v={id:R.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=V(v,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,b.Added),r.push(E),e.setDataType(E)}(h=e.dataType)==null||h.metaSync({inferred:!0,like:!1,asType:!0},t);const l=this.getEntityToMatch(e,t);return(p=e.dataType)==null||p.setEntity(l),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var p,v,E;const r=[],a=[],d=[],o=[];if(((p=e.declaration)==null?void 0:p.id)!==F.operation[Ke.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l,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 P={id:R.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},w=V(P,e.project);w.setParent(e,t),w.initChildren(t),t==null||t.add(w,b.Added),r.push(w),e.setDataType(w)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const h=this.getEntityToMatch(l,t);return(E=e.dataType)==null||E.setEntity(h),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var p,v,E;const r=[],a=[],d=[],o=[];if(((p=e.declaration)==null?void 0:p.id)!==F.operation[Ke.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const l=this.getEntityToMatchInputMap(e.parent);if(!l)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(l,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 P={id:R.UUID.uuid(),version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,type:n.DataType,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},w=V(P,e.project);w.setParent(e,t),w.initChildren(t),t==null||t.add(w,b.Added),r.push(w),e.setDataType(w)}(v=e.dataType)==null||v.metaSync({inferred:!0,like:!0,asType:!1},t);const h=this.getEntityToMatch(l,t);return(E=e.dataType)==null||E.setEntity(h),e.dataType&&a.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:u(a),added:u(r),removed:u(d),affected:u(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var r,a;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].inputs.entityToMatch.id){const{added:d,updated:o,removed:l,affected:c}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}else if(((a=e.declaration)==null?void 0:a.id)===F.operation[Ke.Validate].inputs.dataToValidate.id){const{added:d,updated:o,removed:l,affected:c}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:u(o),added:u(d),removed:u(l),affected:u(c),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new A(this.project,"",T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var r;if(((r=e.declaration)==null?void 0:r.id)===F.operation[Ke.Validate].outputs.outputEntity.id){const{added:a,updated:d,removed:o,affected:l}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:u(d),added:u(a),removed:u(o),affected:u(l),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class IJ extends qe{constructor(s){super(ul,s)}}class bJ extends qe{constructor(s){super(pl,s)}}class RJ extends qe{constructor(s){super(fl,s)}}class AJ extends qe{constructor(s){super(ks,s)}}class DJ extends qe{constructor(s){super(Ss,s)}}class OJ extends qe{constructor(s){super(Pa,s)}}function PJ(i){const s=[new PP(i),new DP(i),new OP(i),new vJ(i),new TJ(i),new EJ(i),new AJ(i),new IJ(i),new RJ(i),new bJ(i),new DJ(i),new OJ(i),new qe(ll,i),new qe(dl,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}class wP extends Yr{constructor(e){super(Ot,e);f(this,"initialData");f(this,"id",z.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",z.PERSISTED_ENTITY);f(this,"description",Ot.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",Ot.abstract);f(this,"static",Ot.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=Ot,this.project=e,this.id=Ot.id,this.version=Ot.version,this.name=Ot.name,this.static=Ot.static,this.abstract=Ot.abstract,this.properties=this.initialData.properties.map(t=>{const r=V(t,this.project);return r.setParent(this,null),r.initChildren(null),r}),this.methods=this.initialData.methods.map(t=>{const r=V(t,this.project);return r.parent=this,r}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const r=V(t,this.project);return r.parent=this,r}),this.extends=this.initialData.extends.map(t=>V(t,this.project))}}function wJ(i){const s=[new wP(i),new Yr(Ma,i),new Yr(Mr,i),new Yr(so,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.builtInBaseEntities=s,s}function VJ(i){const s=[new fr(ne,i),new fr(Kr,i),new fr(me,i),new fr(At,i),new fr(Xr,i),new fr(gr,i),new fr(Qr,i),new fr($n,i)];return s.forEach(e=>{i.subscribeBuiltInInstance(e)}),i.primitives=s,s}function CJ(i){const s=[new qe(lo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.globalEventActionDescriptors=s,s}function gJ(i){const s=[new qe(Ba,i),new qe(mi,i),new qe(Ca,i),new qe(Fn,i),new qe(xn,i),new qe(Ks,i)];s.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarations=s;const e=[new qe(to,i),new qe(ga,i),new qe(Qs,i),new qe(Pl,i),new qe(Vl,i),new qe(Xs,i)];return e.forEach(t=>{t.initChildren(null),i.subscribeBuiltInInstance(t)}),i.loopDeclarationsBodies=e,s}function BJ(i){const s=[new Fi(uo,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.valueDescriptors=s,s}function _J(i){const s=[new qe(an,i),new qe(Wn,i)];return s.forEach(e=>{e.initChildren(null),i.subscribeBuiltInInstance(e)}),i.operationDeclarations=s,s}const Mn={},Xd={};async function MJ(i,s={}){const e={...kA};return e.id=i.id,s.empty?{data:{id:i.id,type:n.Project,version:R.UUID.uuid(),createdAt:T().toISOString(),author:"1",previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]}}:{data:e}}function Jp(i){const s=new R(i);return VJ(s),wJ(s),PJ(s),CJ(s),gJ(s),BJ(s),_J(s),Array.from(new Set([...s.getAllBuiltInIds(),...Wr()])).forEach(t=>{!s.builtInInstances[t]&&s.instances[t]&&(s.builtInInstances[t]=s.instances[t],delete s.instances[t])}),s}function NJ(i,{enrich:s}={enrich:!0}){const e=new Map,t=Array.from(new Set([...i.getAllBuiltInIds(),...Wr()]));Object.keys(i.instances).forEach(l=>{if(t.includes(l)){e.set(l,l);return}const c=i.get(l);if(!Kd(c,{...i.instances,...i.builtInInstances}).every(v=>!t.includes(v))){e.set(l,l);return}e.set(l,R.UUID.uuid())});const r=i.toShallowJSON({seenEntityMaps:e});r.previousVersion=null;const a=Jp(r),d=s?a.addChangeSet(new A(a,"",T().toISOString(),a)):null,o=new gp(i);return o.visit(l=>{const c=l.toShallowJSON({seenEntityMaps:e});c.previousVersion=null;const h=V(c,a);h.hydrateAncestors(),h.addSelfToProject(d),d==null||d.add(h,b.Added)}),s&&(o.visit(l=>{const c=a.get(e.get(l.id));c&&c.afterAllChildrenInitialized(d)}),a.afterAllChildrenInitialized(d)),d==null||d.close(),a}function VP(i,{enrich:s}={enrich:!0}){const e=Jp(i),t=s?e.addChangeSet(new A(e,"",T().toISOString(),e)):null;t&&(t.type=hp.Automatic);const r=new gp(i);return r.visit(a=>{const d=V(a,e);d.hydrateAncestors(),d.addSelfToProject(t)}),s&&(r.visit(a=>{const d=e.get(a.id);d&&d.afterAllChildrenInitialized(t)}),e.afterAllChildrenInitialized(t)),t==null||t.close(),e}async function LJ(i,s={}){if(i.id&&Mn[i.id])return Mn[i.id];if(i.id&&Xd[i.id])return await Xd[i.id],Mn[i.id];const e=MJ(i,s);i.id&&(Xd[i.id]=e);const t=await e;if(t.data){const r=VP(t.data);return Mn[i.id]=r,i.id&&delete Xd[i.id],r}return null}function UJ(i){return Mn[i.id]&&delete Mn[i.id],null}const jJ="test_primitive_entities_export";y.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Pp,y.ALL_BUILT_IN_BASE_ENTITIES=VE,y.ALL_BUILT_IN_CONDITION_ENTITIES=xE,y.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=ZE,y.ALL_BUILT_IN_LOOP_BODY_ENTITIES=nT,y.ALL_BUILT_IN_LOOP_ENTITIES=iT,y.ALL_BUILT_IN_OPERATION_ENTITIES=h0,y.ALL_BUILT_IN_PRIMITIVE_ENTITIES=sf,y.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=YE,y.ALL_BUILT_IN_VALUE_DESCRIPTORS=WE,y.ActionDescriptorState=qe,y.ActionInputMapState=dq,y.ActionOutputMapState=cq,y.AppendToListOperationInputIds=yh,y.AppendToListOperationOutputIds=hh,y.ArgumentDeclarationDependencyField=eO,y.ArgumentDeclarationState=Si,y.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Rp,y.BUILT_IN_BASE_ENTITY_IDS=F,y.BUILT_IN_ENTITY_TYPES=hr,y.BaseCanvasDraggableState=uJ,y.BaseEntityNames=z,y.BaseState=lJ,y.BaseValueDescriptorIds=Gs,y.BreakStatementDependencyField=vp,y.BreakStatementState=Cn,y.BuiltInBaseEntityState=Yr,y.CACHED_PROJECTS_BY_ID=Mn,y.CALLABLE_ENTITIES_EXPLANATION=Eq,y.CALLABLE_TYPES=Vr,y.CALLER_ENTITIES_EXPLANATION=aO,y.CALLER_TYPES=Cr,y.CALLS_UPDATE_EXPLANATION=ki,y.COMPARISON_CONDITIONS=SE,y.CONDITIONS=FE,y.CUSTOM_ENTITY_OPERATIONS=Mm,y.CallableEntityClass=pJ,y.CallerEntityClass=qp,y.ChangeSet=A,y.ChangeSetChangeCaptureType=hp,y.ChangeSetEntityChangeType=b,y.ChildEntityState=cJ,y.ComparisonOperatorTypes=ct,y.ConditionDependencyField=Y1,y.ConditionState=Li,y.ContinueStatementDependencyField=mp,y.ContinueStatementState=$t,y.CreateNewInputIds=om,y.CreateNewOutputIds=dm,y.DRAGGABLE_CALLABLE_TYPES=rl,y.DRAGGABLE_CALLER_TYPES=Hp,y.DRAGGABLE_ELEMENT_TYPES=$s,y.DRAGGABLE_EXECUTABLE_TYPES=MP,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=js,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=tl,y.DataTypeCompatibilityTypes=Er,y.DataTypeDependencyField=Z1,y.DataTypeParentChildRelation=Rt,y.DataTypeState=wn,y.DefinitionEntityDependencyField=IP,y.DefinitionEntityState=zi,y.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=oJ,y.ENTITIES_WITH_VALLUES_EXPLANATION=Ld,y.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=L,y.ENTITY_RECUSION_OPTIONS_DEFAULTS=Z,y.ENTITY_TYPES=NP,y.ENTITY_WITH_DECLARATION_TYPES=BP,y.ENTITY_WITH_LOGIC_SCOPE_TYPES=mt,y.ENTITY_WITH_NAMES_TYPES=Kp,y.ENTITY_WITH_PARENT_TYPES=CP,y.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=Yp,y.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=gP,y.ENTITY_WITH_VALUE_TYPES=Wp,y.ENTRY_POINT_ENTITIES_EXPLANATION=Ps,y.ENTRY_POINT_TYPES=at,y.EVENT_TYPES=jn,y.EXECUTABLE_TYPES=_P,y.EXECUTION_OPERATIONS=sm,y.EntityAction=AP,y.EntityError=hn,y.EntityErrorSeverity=D,y.EntityGenerationError=O,y.EntityGenerationErrorCode=I,y.EntityInstanceErrorCode=q,y.EntityOperations=Ke,y.EntityType=n,y.EntityWithLogicScopeClass=mJ,y.EntityWithValueClass=hJ,y.EntryPointEntityClass=fJ,y.ExecutionOperations=He,y.ExecutionTerminationType=J1,y.FunctionCallDependencyField=hO,y.FunctionCallState=qi,y.FunctionDeclarationDependencyField=k1,y.FunctionDeclarationState=_i,y.GLOBAL_EVENT_DECLARATIONS=kE,y.GetLastInListOperationInputIds=rh,y.GetLastInListOperationOutputIds=ih,y.GlobalEventNames=Hr,y.GlobalEventState=Vn,y.HTTPOperations=Ct,y.HTTP_OPERATIONS=f0,y.InputMapDependencyField=X1,y.InputMapState=kr,y.InstalledProjectState=Gi,y.InternalCallDependencyField=K1,y.InternalCallState=gn,y.JoinListOperationInputIds=Ry,y.JoinListOperationOutputIds=Ay,y.LIST_OPERATIONS=Vh,y.ListOperations=fe,y.LiteralValueDependencyField=tO,y.LiteralValueState=Bn,y.LoopDependencyField=W1,y.LoopState=Ni,y.LoopTypes=K,y.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=Zi,y.NUMBER_OPERATIONS=Uf,y.NumberOperations=Xe,y.OPERATION_DECLARATIONS=y0,y.OperationDependencyField=q1,y.OperationState=Mi,y.OutputMapDependencyField=Q1,y.OutputMapParentChildRelation=Un,y.OutputMapState=Zr,y.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=Ud,y.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=xi,y.PASS_THROUGH_CALLABLE_TYPES=nt,y.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=zp,y.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=Op,y.ParallelExecutionOperation=DP,y.PassThroughCallableEntityClass=yJ,y.PersistedEntity=wP,y.PersistedEntityMethods=sr,y.PrimitiveEntityState=fr,y.PrimitiveTypes=M,y.ProjectState=R,y.PropertyDependencyField=F1,y.PropertyState=gi,y.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=RP,y.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=Iq,y.ReturnDeclarationDependencyField=x1,y.ReturnDeclarationState=rr,y.ReturnStatementDependencyField=Bd,y.ReturnStatementState=Bi,y.STANDALONE_CONDITIONS=BE,y.STRING_OPERATIONS=by,y.ScopeCompatibilityType=Hd,y.SearchDependencyField=H1,y.SearchState=$i,y.SequentialExecutionOperation=PP,y.SequentialExecutionOperationInputIds=Wh,y.SequentialExecutionOperationOutputIds=Yh,y.SharedEntityErrorCode=j,y.SharedStateFunctionality=bP,y.SplitListOperationInputIds=$y,y.SplitListOperationOutputIds=Gy,y.StandaloneOperatorTypes=yr,y.StringOperations=Ee,y.TERMINATION_TYPES=st,y.Traverser=gp,y.USER_MANAGED_ENTITY_TYPES=Xp,y.UserManagedEntityStateTemplate=dJ,y.VALUE_READING_ENTITIES_EXPLANATION=Dp,y.VALUE_READING_TYPES=hi,y.VALUE_WRITING_ENTITIES_EXPLANATION=sO,y.VALUE_WRITING_TYPES=ht,y.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=Ap,y.VARIABLE_TYPES=Qe,y.ValueAutogenerationType=yt,y.ValueDescriptorDependencyField=rO,y.ValueDescriptorParentChildRelation=_,y.ValueDescriptorState=Fi,y.ValueReadingEntityClass=yi,y.ValueWritingEntityClass=Ms,y.VariableDeclarationDependencyField=z1,y.VariableDeclarationState=ji,y.VariableInputMapState=oq,y.VariableInstanceDependencyField=Tp,y.VariableInstanceState=Ui,y.VariableOutputMapState=uq,y.WaitOperation=OP,y.WaitOperationInputIds=Sh,y.WaitOperationOutputIds=Fh,y.appendToListOperation=ks,y.appendToListOperationElementToAppendArgument=hl,y.appendToListOperationElementToAppendArgumentParentRef=Ah,y.appendToListOperationElementToAppendArgumentRef=Th,y.appendToListOperationError=wh,y.appendToListOperationErrorParentRef=Ph,y.appendToListOperationListArgument=yl,y.appendToListOperationListArgumentParentRef=Rh,y.appendToListOperationListArgumentRef=mh,y.appendToListOperationListDataType=vh,y.appendToListOperationResultListDataType=bh,y.appendToListOperationResultListReturn=Oh,y.appendToListOperationResultListReturnParentRef=Dh,y.appendToListOperationResultListReturnRef=Ih,y.appendToListOperationSecondListDataType=Eh,y.asGenerationActionExample=qr,y.booleanPrototype=Kr,y.capitalizeFirstLetter=Wt,y.changeSetJSONRecordToUniqueIds=$7,y.checkAreDataTypesCompatible=Ir,y.checkAreDefinitionEntitiesCompatibleAsDataType=V1,y.checkArePropertiesCompatibleAsDataType=w1,y.checkHasMetadataChanged=dt,y.checkIsBranchDependentButNotDirectlyOnBranch=Vs,y.checkIsBranchDependentOnBranch=Cq,y.checkIsCallableEntityReachable=_s,y.checkIsCanvasEntity=Yq,y.checkIsDetachedBranch=yP,y.checkIsDetachedBranchShallow=kp,y.checkIsGlobalVariable=qq,y.checkIsGloballyDeclared=xp,y.checkIsMethod=vP,y.checkIsNestedScope=zd,y.checkScopeCompatibility=Bs,y.cloneProject=NJ,y.countedLoopActionDescriptor=Ba,y.countedLoopActionDescriptorDynamicReturnDeclaration=zv,y.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=Yv,y.countedLoopActionDescriptorStringArgumentDeclaration=Wv,y.countedLoopActionDescriptorStringArgumentDeclarationDataType=qv,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=kv,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=xv,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=Zv,y.countedLoopActionDescriptorStringArgumentDeclarationParentRef=Jv,y.countedLoopBodyActionDescriptor=to,y.countedLoopBodyActionDescriptorAnyDynamicArgument=eT,y.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Qv,y.countedLoopBodyActionDescriptorAnyDynamicReturn=rT,y.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=tT,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=gl,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Kv,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Hv,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Xv,y.createDefinitionEntityFromJSONObject=Fd,y.createEntityError=ye,y.createNestedDataTypeForEntity=TO,y.createNewInstanceOperation=Xi,y.createNewInstanceOperationEntityToInstanciateArgument=mm,y.createNewInstanceOperationEntityToInstanciateArgumentRef=fm,y.createNewInstanceOperationEntityToInstanciateDataType=ym,y.createNewInstanceOperationError=Im,y.createNewInstanceOperationErrorParentRef=Em,y.createNewInstanceOperationNewEntityDataArgument=pm,y.createNewInstanceOperationNewEntityDataArgumentDataType=cm,y.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=um,y.createNewInstanceOperationNewEntityDataArgumentParentRef=lm,y.createNewInstanceOperationOutputEntityDeclaration=Tm,y.createNewInstanceOperationOutputEntityDeclarationParentRef=vm,y.createNewInstanceOperationRef=hm,y.createSemanticId=S1,y.createStateFromGenerationTargetType=sJ,y.createStateFromType=lt,y.createStateFromTypeAndSubscribe=V,y.cronJobBuiltInBaseEntity=so,y.cronJobBuiltInBaseEntityExpressionProperty=PE,y.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=FP,y.cronJobBuiltInBaseEntityExpressionPropertyRef=DE,y.cronJobBuiltInBaseEntityRef=OE,y.cronJobTriggeredFunctionDeclarationBlueprint=Zl,y.cronJobTriggeredFunctionDeclarationBlueprintParentRef=RE,y.dataTypeCompatibilityToErrorExplanation=yO,y.datePrototype=gr,y.dateValueAutogenerationSchema=ic,y.definitionEntityToZodSchema=uI,y.deletePersistedEntityMethod=kl,y.deletePersistedEntityMethodParentRef=oE,y.deleteRootProject=UJ,y.endpointBuiltInBaseEntity=Ma,y.endpointBuiltInBaseEntityRef=dT,y.endpointBuiltInBaseEntityRefFour=kT,y.endpointBuiltInBaseEntityRefThree=vT,y.endpointBuiltInBaseEntityRefTwo=fT,y.endpointBuiltInCorsProperty=lT,y.endpointBuiltInCorsPropertyDataType=oT,y.endpointBuiltInCorsPropertyDataTypeRef=aT,y.endpointBuiltInCorsPropertyRef=sT,y.endpointBuiltInMethodProperty=_l,y.endpointBuiltInMethodPropertyDataType=mT,y.endpointBuiltInMethodPropertyDataTypeRef=yT,y.endpointBuiltInMethodPropertyRef=hT,y.endpointBuiltInPathProperty=Bl,y.endpointBuiltInPathPropertyDataType=pT,y.endpointBuiltInPathPropertyDataTypeRef=uT,y.endpointBuiltInPathPropertyRef=cT,y.endpointPathParamsArgumentDeclaration=Nl,y.endpointPathParamsArgumentDeclarationRef=wT,y.endpointPathParamsVariableDataType=VT,y.endpointPathParamsVariableDataTypeRef=PT,y.endpointReachedTriggerActionDescriptor=Sl,y.endpointReachedTriggerActionDescriptorRef=CT,y.endpointReachedTriggerActionDescriptorRefFour=_T,y.endpointReachedTriggerActionDescriptorRefThree=BT,y.endpointReachedTriggerActionDescriptorRefTwo=gT,y.endpointRequestBodyArgumentDeclaration=Ul,y.endpointRequestBodyArgumentDeclarationRef=bT,y.endpointRequestBodyVariableDataType=RT,y.endpointRequestHeadersArgumentDeclaration=Ml,y.endpointRequestHeadersArgumentDeclarationRef=ET,y.endpointRequestHeadersVariableDataType=IT,y.endpointRequestHeadersVariableDataTypeRef=TT,y.endpointRequestQueryParamsArgumentDeclaration=Ll,y.endpointRequestQueryParamsArgumentDeclarationRef=DT,y.endpointRequestQueryParamsVariableDataType=OT,y.endpointRequestQueryParamsVariableDataTypeRef=AT,y.endpointResponseBodyDataType=FT,y.endpointResponseBodyReturnDeclaration=Gl,y.endpointResponseBodyReturnDeclarationRef=ST,y.endpointResponseCodeDataType=NT,y.endpointResponseCodeReturnDeclaration=jl,y.endpointResponseCodeReturnDeclarationRef=MT,y.endpointResponseHeadersDataType=$T,y.endpointResponseHeadersDataTypeRef=UT,y.endpointResponseHeadersReturnDeclaration=$l,y.endpointResponseHeadersReturnDeclarationRef=jT,y.endpointReturnStatementRef=LT,y.endpointReturnStatementRefThree=xT,y.endpointReturnStatementRefTwo=GT,y.enrichFromKnownEntities=Cs,y.enumOptionsProperty=af,y.enumOptionsPropertyDataType=rf,y.enumOptionsPropertyDataTypeRef=ef,y.enumOptionsPropertyRef=tf,y.enumPrototype=Xr,y.enumPrototypeRef=nf,y.executionBuiltInBaseEntity=oo,y.executionBuiltInEntityAbortMethod=ql,y.executionBuiltInEntityAbortMethodParentRef=wE,y.filterOutDuplicateEntities=u,y.filterOutDuplicateErrors=Z9,y.findEntityFromKeys=Bp,y.findReferenceToSelfInList=MO,y.findReferencesToSelfInProject=$q,y.flattenActionDescriptor=NO,y.flattenArgumentDeclaration=LO,y.flattenBreakStatement=UO,y.flattenBuiltInBaseEntity=jO,y.flattenCalls=Jr,y.flattenCanvasAncestorsUntil=xd,y.flattenCondition=$O,y.flattenContinueStatement=GO,y.flattenDataType=FO,y.flattenDefinitionEntity=SO,y.flattenDefinitionEntityExtensionAndImplementationTypes=Gp,y.flattenDefinitionEntityExtensionTypes=Yd,y.flattenDefinitionEntityExtensions=jp,y.flattenDefinitionEntityImplementations=$p,y.flattenDefinitionEntityImplementionTypes=Wd,y.flattenDerivedCanvasEntities=ir,y.flattenDetachedBranch=mP,y.flattenElementCalls=it,y.flattenElementCallsOnTheSameScope=jq,y.flattenEntity=N,y.flattenFunctionCall=xO,y.flattenFunctionDeclaration=kO,y.flattenGlobalEvent=ZO,y.flattenInputMap=qO,y.flattenInstalledProject=JO,y.flattenInternalCall=WO,y.flattenLiteralValue=YO,y.flattenLoop=zO,y.flattenOperation=HO,y.flattenOutputMap=KO,y.flattenPrimitiveEntity=XO,y.flattenProject=QO,y.flattenProjectElements=_O,y.flattenProperty=eP,y.flattenRelatedCanvasElementsOnTheLeft=pP,y.flattenRelatedCanvasElementsOnTheRight=cP,y.flattenReturnDeclaration=tP,y.flattenReturnStatement=rP,y.flattenSearch=iP,y.flattenValueDescriptor=nP,y.flattenVariableDeclaration=aP,y.flattenVariableInstance=sP,y.flattenVariableReads=BO,y.flattenVariableWrites=gO,y.flattenVariables=We,y.fromChangeSetToRecordChangeSet=rJ,y.fromZodParseToEntityGenerationErrors=Ep,y.generate=qV,y.generateActionExample=bq,y.generateExecutionDataType=V7,y.generateIdFromStrategy=pt,y.generateMutablePropertiesExplanation=_d,y.generateRandomBoolean=jI,y.generateRandomDate=yI,y.generateRandomDateAfter=cI,y.generateRandomDateBefore=pI,y.generateRandomDateBetweenRange=fI,y.generateRandomNumber=_I,y.generateRandomNumberAfter=CI,y.generateRandomNumberBefore=gI,y.generateRandomNumberBetweenRange=BI,y.generateRandomText=UI,y.generateRandomTextAfter=MI,y.generateRandomTextBefore=NI,y.generateRandomTextBetweenRange=LI,y.generateUniqueUUID=VI,y.getAllActionDescriptorsForConditions=Gd,y.getAllActionDescriptorsForGlobalEvents=jd,y.getAllActionDescriptorsForLoops=$d,y.getAllActionDescriptorsForOperations=Oq,y.getAllBuiltInEntityIds=Wr,y.getAllGloballyDeclaredFunctionDeclarationsExplanation=cO,y.getBaseBuiltInEntities=Wi,y.getBaseSchemaBasedOnType=iO,y.getBuiltInEntityOwner=Yi,y.getCallableEntityReferenceSchema=Dt,y.getCallableEntityTypeSchema=hD,y.getCalledBy=pr,y.getCallerEntityReferenceSchema=Y3,y.getCallerEntityTypeSchema=W3,y.getCalls=Np,y.getCanvasEntitiesDerivedFromInternalCalls=uP,y.getCanvasEntitiesDerivedFromWrites=Ra,y.getCanvasEntityDerivedFromValueReadingEntity=Jd,y.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=lP,y.getCanvasEntityReferenceSchema=c5,y.getCanvasEntityTypeSchema=u5,y.getChildrenEntityWithValues=Bq,y.getColumnProperties=Qq,y.getCommonAncestor=Mp,y.getCommonChildren=EO,y.getDatabaseEntities=Kq,y.getDatabaseEntity=eJ,y.getDeclaration=Pn,y.getDeepestScope=EP,y.getDefinitionEntityExtends=Aa,y.getDraggableCallableEntityReferenceSchema=vD,y.getDraggableCallableEntityTypeSchema=mD,y.getDraggableCallerEntityReferenceSchema=H3,y.getDraggableCallerEntityTypeSchema=z3,y.getDraggableExecutableEntityReferenceSchema=e5,y.getDraggableExecutableEntityTypeSchema=Q3,y.getDraggablePassThroughCallableEntityReferenceSchema=vd,y.getDraggablePassThroughCallableEntityTypeSchema=md,y.getDraggablePlayableEntityReferenceSchema=a5,y.getDraggablePlayableEntityTypeSchema=n5,y.getEntityArgumentDeclarations=Up,y.getEntityInputMaps=oP,y.getEntityOutputMaps=xq,y.getEntityReferenceSchema=l5,y.getEntityReturnDeclarations=dP,y.getEntityTypeSchema=d5,y.getEntityWithLogicScopeReferenceSchema=ui,y.getEntityWithLogicScopeTypeSchema=t5,y.getEntityWithValueReferenceSchema=yD,y.getEntityWithValueTypeSchema=J3,y.getEntryPointEntityReferenceSchema=bt,y.getEntryPointEntityTypeSchema=wi,y.getEventEntityReferenceSchema=yd,y.getEventEntityTypeSchema=fd,y.getExecutableEntityReferenceSchema=X3,y.getExecutableEntityTypeSchema=K3,y.getExtendedBuiltInEntity=kq,y.getExtendedDefinitionEntity=Sp,y.getGenerationTargetSchemaBasedOnType=nO,y.getHeadIfPartOfDetachedBranch=hP,y.getHighestScope=TP,y.getImplementedBuiltInEntity=Zq,y.getIsInteractive=Fp,y.getLastInListOperation=fl,y.getLastInListOperationError=fh,y.getLastInListOperationErrorParentRef=ph,y.getLastInListOperationInputListArgument=lh,y.getLastInListOperationInputListArgumentParentRef=dh,y.getLastInListOperationInputListArgumentRef=nh,y.getLastInListOperationInputListDataType=ah,y.getLastInListOperationOutputElementDataType=oh,y.getLastInListOperationOutputElementReturn=ch,y.getLastInListOperationOutputElementReturnParentRef=uh,y.getLastInListOperationOutputElementReturnRef=sh,y.getLinkedEntitiesFromArgumentDeclaration=Uq,y.getLowestPersistedEntityImplementation=fP,y.getParentCallableEntity=IO,y.getParentCallerEntity=RO,y.getParentCanvasEntities=Yt,y.getParentCanvasEntity=wt,y.getParentCanvasEntityFromTransfer=kd,y.getParentEntryPoint=gq,y.getParentPassthroughCallableEntity=bO,y.getPassThroughCallableEntityReferenceSchema=et,y.getPassThroughCallableEntityTypeSchema=hd,y.getPeristedEntities=Hq,y.getPlayableEntityReferenceSchema=i5,y.getPlayableEntityTypeSchema=r5,y.getProject=LJ,y.getPrototypeByType=gs,y.getRecusriveParentsIds=Kd,y.getReferenceEntityId=g,y.getReferencedEntitiesStateOrErrors=Nd,y.getReferencedEntityStateOrErrors=Ip,y.getReferencedIds=qd,y.getRelatedCanvasElementsOnTheLeft=_n,y.getRelatedCanvasElementsOnTheLeftFromTransfer=Gq,y.getRelatedCanvasElementsOnTheRight=Ji,y.getRootEntryPointScopeOwner=Zp,y.getScopeOwner=zt,y.getStateClassFromType=tJ,y.getTerminationReferenceSchema=o5,y.getTerminationTypeSchema=s5,y.getUsedArgFromDeclaration=Sq,y.getUsedReturnFromDeclaration=Fq,y.getValueReadingEntityReferenceSchema=fD,y.getValueReadingEntityTypeSchema=li,y.getValueWritingEntityReferenceSchema=q3,y.getValueWritingEntityTypeSchema=ms,y.getVariableFromInputMapping=DO,y.getVariableFromReturnVariablePointer=wO,y.getVariableReferenceSchema=Pi,y.getVariableTypeSchema=In,y.getVariablesFromArgumentDeclarations=Zd,y.getVariablesFromInputMaps=OO,y.getVariablesFromOutputMapping=VO,y.getVariablesFromOutputMaps=CO,y.getVariablesFromReturnDeclarations=PO,y.getVariablesInSameOrHigherScope=dp,y.getWrites=Lp,y.groupCallsBasedOnParallelizableExecution=Mq,y.handleAfterEntityImplementationSideEffects=vO,y.handleBeforeEntityImplementationSideEffects=mO,y.httpRequestBodyArgument=Ws,y.httpRequestBodyArgumentRef=Jm,y.httpRequestBodyDataType=Wm,y.httpRequestHeadersArgument=Js,y.httpRequestHeadersArgumentRef=Zm,y.httpRequestHeadersDataType=qm,y.httpRequestMethodArgument=Zs,y.httpRequestMethodArgumentRef=xm,y.httpRequestMethodDataType=km,y.httpRequestMethodDataTypeRef=Sm,y.httpRequestOperation=wa,y.httpRequestOperationErrorValueDescriptor=bl,y.httpRequestOperationErrorValueDescriptorDatatype=p0,y.httpRequestOperationErrorValueDescriptorRef=c0,y.httpRequestOperationRef=o0,y.httpRequestOperationRefEight=l0,y.httpRequestOperationRefFive=a0,y.httpRequestOperationRefFour=n0,y.httpRequestOperationRefNine=u0,y.httpRequestOperationRefSeven=d0,y.httpRequestOperationRefSix=s0,y.httpRequestOperationRefThree=i0,y.httpRequestOperationRefTwo=r0,y.httpRequestQueryParamsArgument=Il,y.httpRequestQueryParamsArgumentRef=$m,y.httpRequestQueryParamsDataType=Gm,y.httpRequestVariableURLArgument=qs,y.httpRequestVariableURLArgumentRef=Um,y.httpRequestVariableURLDataType=jm,y.httpRequestVariableURLDataTypeRef=Nm,y.httpResponseBodyReturnDataType=t0,y.httpResponseBodyReturnDataTypeRef=Qm,y.httpResponseBodyReturnReturn=Hs,y.httpResponseBodyReturnReturnRef=e0,y.httpResponseCodeDataType=zm,y.httpResponseCodeReturn=Ys,y.httpResponseCodeReturnRef=Ym,y.httpResponseHeadersDataType=Xm,y.httpResponseHeadersDataTypeRef=Hm,y.httpResponseHeadersReturn=zs,y.httpResponseHeadersReturnRef=Km,y.implement=Sd,y.inferArgumentDeclarationDataType=C1,y.inferDataType=xr,y.inferInputMapDataType=ap,y.inferOutputMapDataType=op,y.inferPropertyDataType=_1,y.inferReturnDeclarationDataType=sp,y.inferValueDescriptorDataType=M1,y.inferVariableDeclarationDataType=B1,y.inferVariableInstanceDataType=g1,y.initBaseProjectEntity=Jp,y.initProject=VP,y.isPromise=Cp,y.iterateOverListActionDescriptorListArgumentDeclaration=J0,y.iterateOverListActionDescriptorListArgumentDeclarationDataType=Z0,y.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=k0,y.iterateOverListActionDescriptorListArgumentDeclarationParentRef=q0,y.iterateOverListLoopActionDescriptor=mi,y.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=Y0,y.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=W0,y.iterateOverListLoopBodyActionDescriptor=ga,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=iv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=rv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=av,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=nv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=eo,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=H0,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=z0,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=K0,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=tv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Q0,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=X0,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=ev,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=uv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=dv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=ov,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=lv,y.iterateOverObjectKeysLoopActionDescriptor=Fn,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=pv,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=cv,y.iterateOverObjectKeysLoopBodyActionDescriptor=Pl,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=bv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Iv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=Av,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Rv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ol,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=yv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=fv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=hv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Ev,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=vv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=mv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Tv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=Vv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Pv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Ov,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=wv,y.iterateOverObjectValuesLoopActionDescriptor=xn,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=gv,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Cv,y.iterateOverObjectValuesLoopBodyActionDescriptor=Vl,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Gv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$v,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=Fv,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Sv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=wl,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=_v,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Bv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Mv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Lv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Nv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Uv,y.iterateOverStringActionDescriptorDynamicReturnDeclaration=B0,y.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=g0,y.iterateOverStringActionDescriptorStringArgumentDeclaration=C0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=w0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=P0,y.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=V0,y.iterateOverStringLoopActionDescriptor=Ca,y.iterateOverStringLoopBodyActionDescriptor=Qs,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=G0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=F0,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=S0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Al,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=M0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=_0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=N0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Dl,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=U0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=L0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=j0,y.joinListOperation=ul,y.joinListOperationError=jy,y.joinListOperationErrorParentRef=Uy,y.joinListOperationFirstListArgument=By,y.joinListOperationFirstListArgumentParentRef=gy,y.joinListOperationFirstListArgumentRef=Dy,y.joinListOperationFirstListDataType=Oy,y.joinListOperationResultListDataType=Cy,y.joinListOperationResultListReturn=Ly,y.joinListOperationResultListReturnParentRef=Ny,y.joinListOperationResultListReturnRef=Vy,y.joinListOperationSecondListArgument=My,y.joinListOperationSecondListArgumentParentRef=_y,y.joinListOperationSecondListArgumentRef=Py,y.joinListOperationSecondListDataType=wy,y.joinListWithLastSeparator=ie,y.joinStringsOperation=Pa,y.joinStringsOperationDynamicStringArgument=iy,y.joinStringsOperationDynamicStringArgumentParentRef=ry,y.joinStringsOperationDynamicStringArgumentRef=ey,y.joinStringsOperationDynamicStringDataType=ty,y.joinStringsOperationError=Qf,y.joinStringsOperationErrorParentRef=Xf,y.joinStringsOperationFirstStringArgument=Fs,y.joinStringsOperationFirstStringArgumentParentRef=kf,y.joinStringsOperationFirstStringArgumentRef=jf,y.joinStringsOperationFirstStringDataType=$f,y.joinStringsOperationResultStringDataType=xf,y.joinStringsOperationResultStringReturn=Oa,y.joinStringsOperationResultStringReturnParentRef=Kf,y.joinStringsOperationResultStringReturnRef=Ff,y.joinStringsOperationSecondStringArgument=xs,y.joinStringsOperationSecondStringArgumentParentRef=Hf,y.joinStringsOperationSecondStringArgumentRef=Gf,y.joinStringsOperationSecondStringDataType=Sf,y.joinStringsOperationSeparatorStringArgument=zf,y.joinStringsOperationSeparatorStringArgumentParentRef=Yf,y.joinStringsOperationSeparatorStringArgumentRef=Zf,y.joinStringsOperationSeparatorStringDataType=Wf,y.joinStringsOperationSeparatorStringDataTypeDefaultValue=Jf,y.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=qf,y.keyValuePrototype=$n,y.lowercaseFirstLetter=Od,y.manualFlowActionDescriptorDeclarationArgumentDeclaration=Rl,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=E0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=T0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=I0,y.manualFlowLoopActionDescriptor=Ks,y.manualFlowLoopActionDescriptorDynamicReturnDeclaration=v0,y.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=m0,y.manualFlowLoopBodyActionDescriptor=Xs,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=R0,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=b0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=D0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=A0,y.mapActionDescriptorToTypeItRepresents=zq,y.mergeEntityErrorsList=q9,y.mergeListOfEntities=Jq,y.methodDefaultValue=Fm,y.mockClientProject=kA,y.moreThanOrEqualCondition=Wn,y.moreThanOrEqualConditionLeftHandArgument=LE,y.moreThanOrEqualConditionLeftHandArgumentDataType=ME,y.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=_E,y.moreThanOrEqualConditionLeftHandArgumentParentRef=NE,y.moreThanOrEqualConditionRightHandArgument=GE,y.moreThanOrEqualConditionRightHandArgumentDataType=jE,y.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=UE,y.moreThanOrEqualConditionRightHandArgumentParentRef=$E,y.notEmptyCondition=an,y.notEmptyConditionArgument=gE,y.notEmptyConditionRef=CE,y.nullPrototype=Qp,y.numberAdditionOperation=Ss,y.numberAdditionOperationDynamicSummandArgument=Ef,y.numberAdditionOperationDynamicSummandArgumentType=Tf,y.numberAdditionOperationDynamicSummandArgumentTypeParentRef=vf,y.numberAdditionOperationError=mf,y.numberAdditionOperationErrorParentRef=hf,y.numberAdditionOperationFirstNumberArgument=il,y.numberAdditionOperationFirstNumberArgumentRef=of,y.numberAdditionOperationFirstNumberDataType=df,y.numberAdditionOperationRef=ff,y.numberAdditionOperationRefThree=al,y.numberAdditionOperationRefTwo=yf,y.numberAdditionOperationResultNumberDataType=pf,y.numberAdditionOperationResultNumberReturn=sl,y.numberAdditionOperationResultNumberReturnRef=cf,y.numberAdditionOperationSecondNumberArgument=nl,y.numberAdditionOperationSecondNumberArgumentRef=lf,y.numberAdditionOperationSecondNumberDataType=uf,y.numberPrototype=me,y.numberSubtractionOperation=dl,y.numberSubtractionOperationDynamicSubtrahendArgument=Lf,y.numberSubtractionOperationDynamicSubtrahendArgumentType=Nf,y.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Mf,y.numberSubtractionOperationError=_f,y.numberSubtractionOperationErrorParentRef=Bf,y.numberSubtractionOperationFirstNumberArgument=Pf,y.numberSubtractionOperationFirstNumberArgumentRef=If,y.numberSubtractionOperationFirstNumberDataType=bf,y.numberSubtractionOperationRef=ol,y.numberSubtractionOperationRefThree=Cf,y.numberSubtractionOperationRefTwo=wf,y.numberSubtractionOperationResultNumberDataType=Of,y.numberSubtractionOperationResultNumberReturn=gf,y.numberSubtractionOperationResultNumberReturnRef=Df,y.numberSubtractionOperationSecondNumberArgument=Vf,y.numberSubtractionOperationSecondNumberArgumentRef=Rf,y.numberSubtractionOperationSecondNumberDataType=Af,y.numberValueAutogenerationSchema=rc,y.parallelExecutionOperation=Rr,y.parallelExecutionOperationError=Gh,y.parallelExecutionOperationErrorParentRef=$h,y.parallelExecutionOperationListOfExecutionResultsDataType=Lh,y.parallelExecutionOperationListOfExecutionResultsReturn=vl,y.parallelExecutionOperationListOfExecutionResultsReturnRef=Nh,y.parallelExecutionOperationListOfFunctionsArgument=ml,y.parallelExecutionOperationListOfFunctionsArgumentDatatype=Mh,y.parallelExecutionOperationListOfFunctionsArgumentRef=_h,y.parallelExecutionOperationListOfFunctionsBlueprint=Bh,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=gh,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Ch,y.parallelExecutionOperationRef=Uh,y.parallelExecutionOperationRefThree=jh,y.persistedBuiltInBaseEntity=Ot,y.persistedBuiltInBaseEntityDatabaseProperty=Zn,y.persistedBuiltInBaseEntityDatabasePropertyDataType=uE,y.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=GP,y.persistedBuiltInBaseEntityDatabasePropertyParentRef=cE,y.persistedBuiltInBaseEntityDatabasePropertyRef=lE,y.persistedBuiltInBaseEntityPrimaryKeyProperty=qn,y.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=EE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=fE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=pE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=IE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=TE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=hE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=yE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=vE,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=mE,y.processOutputGlobalValueDescriptorDataType=JE,y.processOutputGlobalValueDescriptorReturn=uo,y.processOutputGlobalValueDescriptorReturnRef=qE,y.projectPublicationCompletedGlobalEvent=lo,y.propertyToZodSchema=lI,y.relationalDatabaseBuiltInBaseEntity=Mr,y.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=xl,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=aE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=nE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=sE,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=iE,y.relationalDatabaseBuiltInBaseEntityDefaultProperty=Fl,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=rE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=eE,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=tE,y.relationalDatabaseBuiltInBaseEntityIdentifierProperty=ro,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=JT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=ZT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=qT,y.relationalDatabaseBuiltInBaseEntityMinSizeProperty=ao,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=QT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=KT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=XT,y.relationalDatabaseBuiltInBaseEntityPasswordProperty=no,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=HT,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=$P,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=zT,y.relationalDatabaseBuiltInBaseEntityRef=kn,y.relationalDatabaseBuiltInBaseEntityUsernameProperty=io,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=YT,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=jP,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=WT,y.resolveActionDescriptorName=G1,y.resolveBaseEntityName=L1,y.resolveBuiltInBaseEntityDataTypeLabel=U1,y.resolveClonedEntityProject=ft,y.resolveConditionOperatorLabel=Cd,y.resolveDataType=Pd,y.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=_p,y.resolveDataTypeLabel=Vd,y.resolveDefinitionEntityDataTypeLabel=M7,y.resolveEntityDataTypeLabel=_7,y.resolveEntityName=G,y.resolveFirstCallsSecond=Nq,y.resolveFirstWritesSecond=Lq,y.resolvePrimaryKeyProperty=Xq,y.resolvePrimitiveEntityName=$1,y.resolveSearchName=j1,y.resolveVariableScope=C7,y.sequentialExecutionOperation=ti,y.sequentialExecutionOperationError=am,y.sequentialExecutionOperationErrorParentRef=nm,y.sequentialExecutionOperationListOfExecutionResultsDataType=tm,y.sequentialExecutionOperationListOfExecutionResultsReturn=El,y.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=im,y.sequentialExecutionOperationListOfExecutionResultsReturnRef=em,y.sequentialExecutionOperationListOfFunctionsArgument=Tl,y.sequentialExecutionOperationListOfFunctionsArgumentDatatype=Qh,y.sequentialExecutionOperationListOfFunctionsArgumentParentRef=rm,y.sequentialExecutionOperationListOfFunctionsArgumentRef=Xh,y.sequentialExecutionOperationListOfFunctionsBlueprint=Kh,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=Hh,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=zh,y.softDeletePersistedEntityMethod=SP,y.softDeletePersistedEntityMethodParentRef=bE,y.sortCallsBasedOnExecutionDependencies=AO,y.sortChildrenEntitiesBasedOnExecutionDependencies=_q,y.splitListOperation=pl,y.splitListOperationError=th,y.splitListOperationErrorParentRef=eh,y.splitListOperationFirstOutputListDataType=Zy,y.splitListOperationFirstOutputListReturn=Hy,y.splitListOperationFirstOutputListReturnParentRef=zy,y.splitListOperationFirstOutputListReturnRef=cl,y.splitListOperationInputListArgument=Jy,y.splitListOperationInputListArgumentParentRef=qy,y.splitListOperationInputListArgumentRef=Sy,y.splitListOperationInputListDataType=Fy,y.splitListOperationSecondOutputListDataType=Ky,y.splitListOperationSecondOutputListReturn=Qy,y.splitListOperationSecondOutputListReturnParentRef=Xy,y.splitListOperationSplitIndexArgument=Yy,y.splitListOperationSplitIndexArgumentParentRef=Wy,y.splitListOperationSplitIndexArgumentRef=xy,y.splitListOperationSplitIndexDataType=ky,y.splitStringOperation=ll,y.splitStringOperationError=Iy,y.splitStringOperationErrorParentRef=Ey,y.splitStringOperationFirstPartResultStringDataType=ly,y.splitStringOperationFirstPartResultStringReturn=Ty,y.splitStringOperationFirstPartResultStringReturnParentRef=vy,y.splitStringOperationFirstPartResultStringReturnRef=dy,y.splitStringOperationIndexArgument=hy,y.splitStringOperationIndexArgumentParentRef=yy,y.splitStringOperationIndexArgumentRef=sy,y.splitStringOperationIndexDataType=oy,y.splitStringOperationSecondPartResultStringDataType=cy,y.splitStringOperationSecondPartResultStringReturn=LP,y.splitStringOperationSecondPartResultStringReturnParentRef=my,y.splitStringOperationSecondPartResultStringReturnRef=uy,y.splitStringOperationStringArgument=fy,y.splitStringOperationStringArgumentParentRef=py,y.splitStringOperationStringArgumentRef=ny,y.splitStringOperationStringDataType=ay,y.stringPrototype=ne,y.stringValueAutogenerationSchema=tc,y.suggestNewIdForEntity=yp,y.test_primitive_entities_export=jJ,y.toCamelCase=g7,y.toEntityState=nr,y.toKebabCase=N1,y.toLowerCaseKebabCase=wd,y.toPascalCase=B7,y.untypedDataPrototype=At,y.updateErrorsList=Ye,y.updateValueReader=Wq,y.urlDefaultValue=Lm,y.uuidPrototype=Qr,y.validateArgumentDeclarationName=pp,y.validateCalledByErrorIdInAction=Aq,y.validateCalledByIdInAction=Rq,y.validateCallers=uO,y.validateConditionEntityDeclaration=Pq,y.validateDataOperation=Qi,y.validateDataOperationDataToValidateArgument=Dm,y.validateDataOperationDataToValidateArgumentParentRef=Am,y.validateDataOperationDataToValidateArgumentRef=bm,y.validateDataOperationDataToValidateDataType=Rm,y.validateDataOperationEntityToMatchTypeArgument=Vm,y.validateDataOperationEntityToMatchTypeArgumentParentRef=wm,y.validateDataOperationEntityToMatchTypeArgumentRef=Om,y.validateDataOperationEntityToMatchTypeDataType=Pm,y.validateDataOperationError=_m,y.validateDataOperationErrorParentRef=Bm,y.validateDataOperationOutputEntityDeclaration=gm,y.validateDataOperationOutputEntityDeclarationParentRef=Cm,y.validateDefinitionEntityName=gd,y.validateEntryCaller=lO,y.validateErrorCaller=dO,y.validateFunctionCallDeclaration=pO,y.validateFunctionDeclarationName=lp,y.validateGeneratedEntityParentIsNotBuiltInEntity=Tq,y.validateGeneration=mq,y.validateGenerationTarget=ot,y.validateGenerationUpdate=vq,y.validateLoopEntityDeclaration=wq,y.validateName=N7,y.validateOperationEntityDeclaration=fO,y.validatePropertyName=cp,y.validateReachability=fi,y.validateReadsValueInActionPayload=Dq,y.validateReferenceObject=Md,y.validateReferenceToOne=bp,y.validateReferences=Et,y.validateReturnDeclarationName=fp,y.validateSuccessCaller=oO,y.validateValueReaderGenerationUpdate=ws,y.validateValueWritter=wp,y.validateVariableDeclarationName=up,y.validateVariableInternalCallUse=Vp,y.valueAutogenerationCurrentDateAndTimeSchema=JA,y.valueAutogenerationGenericSchema=Xo,y.valueAutogenerationOptions=nc,y.valueAutogenerationOptionsSchema=qA,y.valueAutogenerationRandomBooleanSchema=ec,y.valueAutogenerationRandomDateBetweenSchema=tD,y.valueAutogenerationRandomDateFromSchema=QA,y.valueAutogenerationRandomDateSchema=td,y.valueAutogenerationRandomDateUntilSchema=eD,y.valueAutogenerationRandomNumberBetweenSchema=zA,y.valueAutogenerationRandomNumberFromSchema=WA,y.valueAutogenerationRandomNumberSchema=Qo,y.valueAutogenerationRandomNumberUntilSchema=YA,y.valueAutogenerationRandomSchema=ls,y.valueAutogenerationRandomTextBetweenSchema=XA,y.valueAutogenerationRandomTextFromSchema=HA,y.valueAutogenerationRandomTextSchema=ed,y.valueAutogenerationRandomTextUntilSchema=KA,y.valueAutogenerationRangeValueTypesSchema=ds,y.valueAutogenerationUniqueSchema=Qu,y.waitOperation=St,y.waitOperationMillisecondsNumberArgument=Ki,y.waitOperationMillisecondsNumberArgumentRef=xh,y.waitOperationMillisecondsNumberDataType=kh,y.waitOperationOperationError=Jh,y.waitOperationOperationErrorParentRef=qh,y.waitOperationRef=Zh,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|