@elyx-code/project-logic-tree 0.0.6272 → 0.0.6274
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.js +30 -25
- package/dist/index.umd.cjs +24 -24
- package/dist/tree/state/change-set/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -40,9 +40,9 @@ Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInS
|
|
|
40
40
|
Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function wc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.EmptyName,issue:null}));const t=B(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:O.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.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:O.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=Xc(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${$.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
|
|
41
41
|
Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function Cc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${$.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:O.Error,code:$.EmptyName,issue:null}));const t=B(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:O.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.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:O.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=tw(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${$.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all outputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
|
|
42
42
|
Please provide a unique 'name' string.`,severity:O.Error,code:$.NameNotUniqueInScope,issue:null}))}}return e}function BJ(r,a){switch(r.type){case n.DefinitionEntity:return Rc(r,a);case n.FunctionDeclaration:return Dc(r,a);case n.VariableDeclaration:return Oc(r,a);case n.Property:return Pc(r,a);case n.ArgumentDeclaration:return wc(r,a);case n.ReturnDeclaration:return Cc(r,a);default:return[]}}function s1(r,a,e){const i=`${$l(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Vc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${$l(F(t,a))}-`),e=`${i}${$l(F(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function yt(r,a,e="uuid"){return e==="semantic"?s1(F(r,a),r.type,a):m.UUID.uuid()}function a1(r){var l;const a=o5(),e=r.toJSON();a.safeParse(e).success;const i=o1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function o1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=fe({id:`${r.id}--${x.NonStaticPropertyImplementsStatic}`,message:`Static property "${F(r,r.project)}" with id "${r.id}" implements a non-static property "${F(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:x.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=fe({id:`${r.id}--${x.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${F(r,r.project)}" with id "${r.id}" implements a static property "${F(e,r.project)}" with id "${e.id}".`,issue:null,severity:O.Error,code:x.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!Ci(r.dataType,e.dataType)){const i=fe({id:`${r.id}--${x.PropertyImplementsIncompatibleType}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a property "${F(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:O.Error,code:x.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return Ke(r.errors,a)}const MJ=Object.freeze(Object.defineProperty({__proto__:null,validate:a1,validateImplementation:o1},Symbol.toStringTag,{value:"Module"}));function NJ(r,a){const e=[];if(r.parent){const i=a.get(r.parent);if(!i)e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const s=ln(i);if(s){const l=i!==s?`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because the entity belongs to a built-in '${s.type}' entity with id '${s.id}' (${F(s,i.project)}) higher up in the tree.`:`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because it is a built-in entity of type ${s.type}.`;e.push(new w({id:`${r.id}--${R.InvalidBuiltInEntityReference}`,code:R.InvalidBuiltInEntityReference,severity:O.Error,message:l,issue:null}))}else if(![n.DefinitionEntity].includes(i.type))e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=St(i).filter(d=>!d.interactive);if(o.length){let d=o.length>1?`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(o.map(u=>F(u,u.project)),'", "','" and "')}").`:`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(o[0],o[0].project)}").`;d+=`
|
|
43
|
-
${sn}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:d,issue:null}))}else if(r.implements){const d=a.get(r.implements);if(r.id===r.implements)return e.push(new w({id:`${r.id}--${r.implements}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new w({id:`${r.id}--${r.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const u=i.properties.find(f=>{var c;return((c=f.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:O.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=bt(r,{},a);return e.push(...t.errors),e}class lt{constructor(a){h(this,"version");h(this,"previousVersion",null);h(this,"createdAt");h(this,"deleted",!1);h(this,"author");this.version=a.version,this.previousVersion=a.previousVersion,this.createdAt=E(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}function LJ(r){return r.listAdded.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_ADDED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,e,r))}),r.listUpdated.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_UPDATED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_UPDATED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,e,r))}),r.listRemoved.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_REMOVED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,e,r))}),r}var _c=(r=>(r.Manual="manual",r.Automatic="automatic",r))(_c||{}),A=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(A||{});class b{constructor(a,e,t,i,s=!1,l=""){h(this,"id",m.UUID.uuid());h(this,"seenEntities",[]);h(this,"added",{});h(this,"updated",{});h(this,"removed",{});h(this,"affected",{});h(this,"self",null);h(this,"author");h(this,"timestamp");h(this,"open",!0);h(this,"dirty",!0);h(this,"type","manual");h(this,"autoclose",!1);h(this,"autoCloseActionName","");h(this,"project");if(this.project=a,this.author=e||m.sessionAuthor||"",this.timestamp=t,this.self=i,this.autoclose=s,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var a;return!(this.isEmpty&&this.self&&!this.affected[(a=this.self)==null?void 0:a.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const a=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=Gi(),i=e.filter(l=>!t.includes(l));a.filter(l=>!i.includes(l)).forEach(l=>{this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()})}async attemptAutocloseAsync(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return this.beforeClose(),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.open=!1,this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.project.closePendingChangeSets(),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:i,updated:s,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of i)this.add(d,"added");for(const d of s)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}sanitize(){this.listAdded.forEach(a=>{a.previousVersion=null})}beforeClose(){this.emitSideEffects()}emitSideEffects(){LJ(this)}close(){if(this.beforeClose(),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.project.closePendingChangeSets(),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}addDependentsToAffected(a){Object.values(a.detachedDependents).forEach(e=>{const{entity:t,field:i}=e;this.has(t.id)||this.add(t,"affected")})}get(a){return this.added[a]?this.added[a]:this.updated[a]?this.updated[a]:this.removed[a]?this.removed[a]:null}remove(a){return this.has(a)&&(delete this.added[a],delete this.updated[a],delete this.removed[a],delete this.affected[a],this.seenEntities=this.seenEntities.filter(e=>e!==a)),this}add(a,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),...Gi()]));if(t.includes(a.id))return this;if(!nd(a,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(a.id)===-1&&this.seenEntities.push(a.id),e==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(f=>f!==a.id),delete this.project.deletedInstances[a.id],this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasRemoved(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:T,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of T)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.captureVersion();const u=(l=a.knownVersions)==null?void 0:l.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.removed[a.id]=u,this}if(e==="added"){if(this.removed[a.id])return this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasAdded(a.id)){const{added:f,updated:c,removed:T,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of T)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.previousVersion=null,a.captureVersion();const u=(o=a.knownVersions)==null?void 0:o.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.added[a.id]=u,delete this.affected[a.id],this.addDependentsToAffected(a),this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return a.captureVersion(),this.addDependentsToAffected(a),this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:T,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of T)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.captureVersion();const u=(d=a.knownVersions)==null?void 0:d.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.updated[a.id]=u,this.addDependentsToAffected(a),this}if(e==="affected"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.updated[a.id])return this;this.affected[a.id]=a}return this}toJSON(){const a={},e={},t={},i=new Set;for(const s of Object.values(this.added))a[s.id]=s.toShallowJSON();for(const s of Object.values(this.updated))e[s.id]=s.toShallowJSON();for(const s of Object.values(this.removed))t[s.id]=s.toShallowJSON();for(const s of Object.values(this.affected))i.add(s.id);return{added:a,updated:e,removed:t,affected:Array.from(i),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(a){return!!this.added[a]||!!this.removed[a]||!!this.updated[a]||!!this.affected[a]}hasAdded(a){return!!this.added[a]}hasUpdated(a){return!!this.updated[a]}hasRemoved(a){return!!this.removed[a]}hasAffected(a){return!!this.affected[a]}}function jJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var l1=(r=>(r.PropertyImplements="property-implements",r.PropertyExtends="property-extends",r.DataTypeEntity="data-type-entity",r))(l1||{});const be=class be extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"private");h(this,"abstract");h(this,"index");h(this,"static");h(this,"required");h(this,"constant",!1);h(this,"type",n.Property);h(this,"hidden",!1);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"implements",null);h(this,"extends",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,extends:null,private:!1,abstract:!1,static:!1,constant:!1,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;if(e.implements){const f=B(e.implements);l=t.get(f)}let o=null;if(e.extends){const f=B(e.extends);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:s.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,extends:o,dataType:null,parent:s},u=V(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=NJ(i,t),o=Pc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&!e.abstract}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.implements)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
43
|
+
${sn}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:d,issue:null}))}else if(r.implements){const d=a.get(r.implements);if(r.id===r.implements)return e.push(new w({id:`${r.id}--${r.implements}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new w({id:`${r.id}--${r.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const u=i.properties.find(f=>{var c;return((c=f.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${$.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:$.PropertyOverwritesOtherSiblingWithSameImplementation,severity:O.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=bt(r,{},a);return e.push(...t.errors),e}class lt{constructor(a){h(this,"version");h(this,"previousVersion",null);h(this,"createdAt");h(this,"deleted",!1);h(this,"author");this.version=a.version,this.previousVersion=a.previousVersion,this.createdAt=E(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}function LJ(r){return r.listAdded.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_ADDED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,e,r))}),r.listUpdated.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_UPDATED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_UPDATED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED,e,r))}),r.listRemoved.forEach(a=>{const e=r.project.get(a.id);(e==null?void 0:e.type)===n.DefinitionEntity&&(r.project.emit(Bt.DEFINITION_ENTITY_REMOVED,e,r),gi(e,J.PERSISTED_ENTITY)?r.project.emit(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,e,r):gi(e,J.RELATIONAL_DATABASE)&&r.project.emit(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,e,r))}),r}var _c=(r=>(r.Manual="manual",r.Automatic="automatic",r))(_c||{}),A=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(A||{});class b{constructor(a,e,t,i,s=!1,l=""){h(this,"id",m.UUID.uuid());h(this,"seenEntities",[]);h(this,"added",{});h(this,"updated",{});h(this,"removed",{});h(this,"affected",{});h(this,"self",null);h(this,"author");h(this,"timestamp");h(this,"open",!0);h(this,"dirty",!0);h(this,"type","manual");h(this,"autoclose",!1);h(this,"autoCloseActionName","");h(this,"project");if(this.project=a,this.author=e||m.sessionAuthor||"",this.timestamp=t,this.self=i,this.autoclose=s,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get index(){const a=this.project.history.indexOf(this);return a===-1?null:a}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var a;return!(this.isEmpty&&this.self&&!this.affected[(a=this.self)==null?void 0:a.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const a=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=Gi(),i=e.filter(l=>!t.includes(l));a.filter(l=>!i.includes(l)).forEach(l=>{this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()})}async attemptAutocloseAsync(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return this.beforeClose(),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.open=!1,this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.project.closePendingChangeSets(),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:i,updated:s,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of i)this.add(d,"added");for(const d of s)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}sanitize(){this.listAdded.forEach(a=>{a.previousVersion=null})}beforeClose(){this.emitSideEffects()}emitSideEffects(){LJ(this)}close(){if(this.beforeClose(),!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.sanitize(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this.project.closePendingChangeSets(),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}addDependentsToAffected(a){Object.values(a.detachedDependents).forEach(e=>{const{entity:t,field:i}=e;this.has(t.id)||this.add(t,"affected")})}get(a){return this.added[a]?this.added[a]:this.updated[a]?this.updated[a]:this.removed[a]?this.removed[a]:null}remove(a){return this.has(a)&&(delete this.added[a],delete this.updated[a],delete this.removed[a],delete this.affected[a],this.seenEntities=this.seenEntities.filter(e=>e!==a)),this}add(a,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),...Gi()]));if(t.includes(a.id))return this;if(!nd(a,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(a.id)===-1&&this.seenEntities.push(a.id),e==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(f=>f!==a.id),delete this.project.deletedInstances[a.id],this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasRemoved(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:T,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of T)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.captureVersion();const u=(l=a.knownVersions)==null?void 0:l.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.removed[a.id]=u,this}if(e==="added"){if(this.removed[a.id])return this;if(this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],!this.hasAdded(a.id)){const{added:f,updated:c,removed:T,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of T)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.previousVersion=null,a.captureVersion();const u=(o=a.knownVersions)==null?void 0:o.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.added[a.id]=u,delete this.affected[a.id],this.addDependentsToAffected(a),this}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return a.captureVersion(),this.addDependentsToAffected(a),this;if(this.affected[a.id]&&delete this.affected[a.id],!this.hasUpdated(a.id)){a.increaseVersion(this.timestamp);const{added:f,updated:c,removed:T,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const D of f)this.add(D,"added");for(const D of c)this.add(D,"updated");for(const D of T)this.add(D,"removed");for(const D of I)this.add(D,"affected")}a.captureVersion();const u=(d=a.knownVersions)==null?void 0:d.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);return this.updated[a.id]=u,this.addDependentsToAffected(a),this}if(e==="affected"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.updated[a.id])return this;this.affected[a.id]=a}return this}toJSON(){const a={},e={},t={},i=new Set;for(const s of Object.values(this.added))a[s.id]=s.toShallowJSON();for(const s of Object.values(this.updated))e[s.id]=s.toShallowJSON();for(const s of Object.values(this.removed))t[s.id]=s.toShallowJSON();for(const s of Object.values(this.affected))i.add(s.id);return{added:a,updated:e,removed:t,affected:Array.from(i),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(a){return!!this.added[a]||!!this.removed[a]||!!this.updated[a]||!!this.affected[a]}hasAdded(a){return!!this.added[a]}hasUpdated(a){return!!this.updated[a]}hasRemoved(a){return!!this.removed[a]}hasAffected(a){return!!this.affected[a]}}function jJ(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var l1=(r=>(r.PropertyImplements="property-implements",r.PropertyExtends="property-extends",r.DataTypeEntity="data-type-entity",r))(l1||{});const be=class be extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"private");h(this,"abstract");h(this,"index");h(this,"static");h(this,"required");h(this,"constant",!1);h(this,"type",n.Property);h(this,"hidden",!1);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"implements",null);h(this,"extends",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,extends:null,private:!1,abstract:!1,static:!1,constant:!1,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;if(e.implements){const f=B(e.implements);l=t.get(f)}let o=null;if(e.extends){const f=B(e.extends);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:s.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,extends:o,dataType:null,parent:s},u=V(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=NJ(i,t),o=Pc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&!e.abstract}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.implements)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
|
|
44
44
|
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),(e.readsValue||e.writesValue)&&t.push(new w({id:`${this.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
|
|
45
|
-
${Zl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(null,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:T}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(e,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:T}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.subscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.extends=this.extends,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=B(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)}if(this.initialData.extends){const t=V(this.initialData.extends,this.project);this.setExtends(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,extends:((l=this.extends)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),extends:(()=>{var c;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((c=this.extends)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,extends:((d=this.extends)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e,t;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,extends:(t=this.extends)==null?void 0:t.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=a1(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,extends:this.extends,parent:d},f=st(u,l);s&&f.subscribe(),f.setParent(d,null),f.initChildren(e),e==null||e.add(f,A.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const T=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=T||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),f}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};h(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(be,"type",n.Property),h(be,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),h(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(be,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),h(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),h(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),h(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),h(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),h(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),h(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),h(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let xr=be;function d1(r){const a=Rq(),e=r.toJSON();a.safeParse(e).success;const i=UJ(r),s=$J(r),l=ci(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];return Ke(r.errors,o)}function UJ(r){const a=[];if(!r.calls.length&&!r.extends){const e=fe({id:`${r.id}--${x.ScopeWithoutLogic}`,message:`Action "${F(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:O.Warning,code:x.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function $J(r){const a=[];return r.implements,Ke(r.errors,a)}const GJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(u1||{});const Re=class Re extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"private");h(this,"index",null);h(this,"type",n.FunctionDeclaration);h(this,"implements",null);h(this,"extends",null);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=B(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=B(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=B(e.extends);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,extends:l,x:0,y:0,parent:i},d=V(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=Dc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const T=d,D=St(T).filter(P=>!P.interactive);if(D.length){let P=D.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${T.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.map(C=>F(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${T.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(D[0],D[0].project)}").`;P+=`
|
|
45
|
+
${Zl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(null,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:T}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="property-implements"&&(this.setImplements(e,i),s.push(this)),t==="property-extends"){const{updated:u,added:f,removed:c,affected:T}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"property-implements"}]),(s=(i=this.extends)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"property-extends"}]),(d=(o=(l=this.dataType)==null?void 0:l.entity)==null?void 0:o.subscribeDependents)==null||d.call(o,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.extends=this.extends,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=B(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)}if(this.initialData.extends){const t=V(this.initialData.extends,this.project);this.setExtends(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,extends:((l=this.extends)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),extends:(()=>{var c;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((c=this.extends)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,extends:((d=this.extends)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e,t;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,extends:(t=this.extends)==null?void 0:t.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=a1(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,extends:this.extends,parent:d},f=st(u,l);s&&f.subscribe(),f.setParent(d,null),f.initChildren(e),e==null||e.add(f,A.Added);const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const T=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=T||null,this.implements&&(f.implements=this.implements),f.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),f}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};h(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(be,"type",n.Property),h(be,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),h(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(be,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),h(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),h(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),h(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),h(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),h(be,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),h(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),h(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let xr=be;function d1(r){const a=Rq(),e=r.toJSON();a.safeParse(e).success;const i=UJ(r),s=$J(r),l=ci(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];return Ke(r.errors,o)}function UJ(r){const a=[];if(!r.calls.length&&!r.extends){const e=fe({id:`${r.id}--${x.ScopeWithoutLogic}`,message:`Action "${F(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:O.Warning,code:x.ScopeWithoutLogic,entity:r});a.push(e.error)}return Ke(r.errors,a)}function $J(r){const a=[];return r.implements,Ke(r.errors,a)}const GJ=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.FunctionDeclarationImplements="function-declaration-implements",r.FunctionDeclarationExtends="function-declaration-extends",r))(u1||{});const Re=class Re extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"private");h(this,"index",null);h(this,"type",n.FunctionDeclaration);h(this,"implements",null);h(this,"extends",null);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=B(e.parent);i=t.get(u)}let s=null;if(e.implements){const u=B(e.implements);s=t.get(u)}let l=null;if(e.extends){const u=B(e.extends);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,extends:l,x:0,y:0,parent:i},d=V(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=Dc(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const T=d,D=St(T).filter(P=>!P.interactive);if(D.length){let P=D.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${T.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(D.map(C=>F(C,C.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${T.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(D[0],D[0].project)}").`;P+=`
|
|
46
46
|
${sn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:P,issue:null}))}else{const P=T.methods.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===i.implements});P&&s.push(new w({id:`${i.id}--${$.MethodOverwritesOtherSiblingWithSameImplementation}`,code:$.MethodOverwritesOtherSiblingWithSameImplementation,severity:O.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is trying to implement the '${n.ActionDescriptor}' with id "${i.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${P.id}' that implements the same base method.
|
|
47
47
|
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.
|
|
48
48
|
${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
|
|
@@ -52,19 +52,19 @@ If you want to implement a new method, you can create a new 'function-declaratio
|
|
|
52
52
|
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(d&&d.type===n.Loop){const T=d.body;T&&((c=T.implements)==null?void 0:c.id)===i.implements&&s.push(new w({id:`${i.id}--${$.LoopBodyFunctionOverwrite}`,code:$.LoopBodyFunctionOverwrite,severity:O.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is being added as the 'body' of the ${n.Loop} with id "${d.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 u=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),f=u?ln(u):null;return f&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${F(f,t)}" with id '${f.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedMethod(){if(this.parent.type!==n.DefinitionEntity)return!1;const e=this.parent.allBaseMethodsFromExtendedAndImplementedEntities.find(t=>{var i;return t.id===((i=this.extends)==null?void 0:i.id)});return!!e&&e.id!==this.id&&e.type!==n.ActionDescriptor}get returnStatements(){return Te(this).filter(i=>i.type===n.ReturnStatement&&i.parent.id===this.id)}validateGeneratedUpdate(e){const t=[];return e.parent&&(this.parent.type===n.Project?t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
53
53
|
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 w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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
54
|
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.
|
|
55
|
-
Please consider than 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&this.setImplements(null,i),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:T}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&(this.setImplements(e,i),s.push(e)),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:T}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(e=this.implements)==null||e.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var e,t;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.subscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.extends=this.extends,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=B(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=V(t,this.project);return i.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.initialData.implements&&(this.implements=V(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=V(this.initialData.extends,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?s.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),ci(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.parent.type===n.DefinitionEntity&&!e&&(this.parent.removeMethod(this),t==null||t.add(this.parent,A.Affected),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),ci(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),this.parent.type===n.DefinitionEntity&&(this.parent.addMethod(this),e==null||e.add(this.parent,A.Affected),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ci(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,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(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,extends:((i=this.extends)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,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(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),extends:(()=>{var u;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(u=this.extends)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,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(o=>o.toReference(e)),calls:this.calls.map(o=>o.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,extends:((l=this.extends)==null?void 0:l.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(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t,i;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||void 0,extends:((i=this.extends)==null?void 0:i.id)||void 0,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=d1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ci(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var I;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[],d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const f=st(d,o);t?f.setParent(t,null):f.setParent(this.parent,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.inputs)==null?void 0:I.map(D=>D.clone(e,f,m.UUID.uuid(),s));return f.inputs=c,l?(ci(this).map(D=>D.clone(e,f,m.UUID.uuid(),s)),e==null||e.attemptAutoclose("clone-entity",this.id),f):(e==null||e.attemptAutoclose("clone-entity",this.id),f)}getVariableInstances(){return He(this).filter(i=>i.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-call")),t=this.project,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||E().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},l=V(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.add(l,A.Added),e==null||e.attemptAutoclose("create-call",this.id),l}createInternalCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-internal")),t,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||E().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.InternalCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},l=V(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),l}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=[],i=[...this.returnStatements].flatMap(s=>s.outputs);if(this.implements){const s=this.implements.outputs;return i.forEach(l=>{const o=s.find(u=>u===l.implements),d=e.find(u=>u.implements===l.implements);o&&!d&&e.push(l)}),p(e)}else return i.forEach(s=>{e.find(o=>o===s||F(o,this.project)===F(s,this.project)&&Ci(o.dataType,s.dataType))||e.push(s)}),p(e)}};h(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Re,"type",n.FunctionDeclaration),h(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),h(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),h(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),h(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),h(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),h(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),h(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),h(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),h(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),h(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let kr=Re;function p1(r){const a=CZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=fe({id:r.id+"--"+x.InvalidPropertiesCombination,message:`Data type with id "${r.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:O.Error,code:x.InvalidPropertiesCombination,entity:r});i.push(s.error)}return Ke(r.errors,i)}const gJ=Object.freeze(Object.defineProperty({__proto__:null,validate:p1},Symbol.toStringTag,{value:"Module"}));function FJ(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${se(t,"', '","' or '")}'`;if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const s=a.get(r.parent);s?t.includes(s.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type ${i}.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${i}.`,issue:null}));if(r.entity){if(r.id===r.entity)return e.push(new w({id:`${r.id}--${r.entity}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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 s=a.get(r.entity);s?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(s.type)||e.push(new w({id:`${r.id}--${r.entity}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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 w({id:`${r.id}--${r.entity}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.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 Bc=(r=>(r.Entity="entity",r))(Bc||{});const De=class De extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"isList",null);h(this,"asType",null);h(this,"type",n.DataType);h(this,"options",null);h(this,"parentRelationType",null);h(this,"like");h(this,"implementationChooseOne",!1);h(this,"inferred",!1);h(this,"staticEntities",null);h(this,"interactiveEntities",null);h(this,"actionEntities",null);h(this,"entity",null);h(this,"andChildrenGroup",null);h(this,"orChildrenGroup",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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,this.staticEntities=e.staticEntities,this.interactiveEntities=e.interactiveEntities,this.actionEntities=e.actionEntities}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;e.entity&&(l=t.get(e.entity));const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType||null,options:e.options||null,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,staticEntities:e.staticEntities??null,interactiveEntities:e.interactiveEntities??null,actionEntities:e.actionEntities??null,entity:l,asType:e.asType,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var u;let i=JSON.parse(JSON.stringify(e));const s=[],l=FJ(i,t);if(s.push(...l,...ut(i)),i.entity){const f=t.get(i.entity);if(f.type===n.DefinitionEntity){const T=St(f).filter(I=>!I.interactive);if(T.length){const I=T.length>1?`entities with ids '${se(T.map(D=>D.id),"', '","' and '")}'`:`entity with id '${T[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${i.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${I}.
|
|
55
|
+
Please consider than 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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&this.setImplements(null,i),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:T}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="function-declaration-implements"&&(this.setImplements(e,i),s.push(e)),t==="function-declaration-extends"){const{updated:u,added:f,removed:c,affected:T}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c),d.push(...T)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(e=this.implements)==null||e.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var e,t;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(t=this.extends)==null||t.subscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.extends=this.extends,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(this.initialData.extends){const l=B(this.initialData.extends),o=this.project.get(l);if(o)this.setExtends(o,null),e.push(o);else if(l)throw new Error(`${_t(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}setExtends(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-extends"))){var i;return((i=this.extends)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.extends=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-extends",this.id),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=V(t,this.project);return i.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.initialData.implements&&(this.implements=V(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=V(this.initialData.extends,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?s.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),ci(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.parent.type===n.DefinitionEntity&&!e&&(this.parent.removeMethod(this),t==null||t.add(this.parent,A.Affected),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),ci(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),this.parent.type===n.DefinitionEntity&&(this.parent.addMethod(this),e==null||e.add(this.parent,A.Affected),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ci(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,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(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,extends:((i=this.extends)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,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(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),extends:(()=>{var u;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(u=this.extends)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,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(o=>o.toReference(e)),calls:this.calls.map(o=>o.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,extends:((l=this.extends)==null?void 0:l.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(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t,i;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||void 0,extends:((i=this.extends)==null?void 0:i.id)||void 0,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=d1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ci(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var I;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[],d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const f=st(d,o);t?f.setParent(t,null):f.setParent(this.parent,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.inputs)==null?void 0:I.map(D=>D.clone(e,f,m.UUID.uuid(),s));return f.inputs=c,l?(ci(this).map(D=>D.clone(e,f,m.UUID.uuid(),s)),e==null||e.attemptAutoclose("clone-entity",this.id),f):(e==null||e.attemptAutoclose("clone-entity",this.id),f)}getVariableInstances(){return He(this).filter(i=>i.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-call")),t=this.project,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||E().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},l=V(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.add(l,A.Added),e==null||e.attemptAutoclose("create-call",this.id),l}createInternalCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-internal")),t,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||(e==null?void 0:e.timestamp)||E().toISOString(),author:i.author||m.sessionAuthor||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.InternalCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},l=V(s,this.project);return l.hydrateAncestors(),e==null||e.add(l,A.Added),l.addSelfToProject(e),l.setParent(t,e),l.initChildren(e),l.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),l}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=[],i=[...this.returnStatements].flatMap(s=>s.outputs);if(this.implements){const s=this.implements.outputs;return i.forEach(l=>{const o=s.find(u=>u===l.implements),d=e.find(u=>u.implements===l.implements);o&&!d&&e.push(l)}),p(e)}else return i.forEach(s=>{e.find(o=>o===s||F(o,this.project)===F(s,this.project)&&Ci(o.dataType,s.dataType))||e.push(s)}),p(e)}};h(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Re,"type",n.FunctionDeclaration),h(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),h(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),h(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),h(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),h(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),h(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),h(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),h(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),h(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),h(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),h(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),h(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let kr=Re;function p1(r){const a=CZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=fe({id:r.id+"--"+x.InvalidPropertiesCombination,message:`Data type with id "${r.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:O.Error,code:x.InvalidPropertiesCombination,entity:r});i.push(s.error)}return Ke(r.errors,i)}const gJ=Object.freeze(Object.defineProperty({__proto__:null,validate:p1},Symbol.toStringTag,{value:"Module"}));function FJ(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${se(t,"', '","' or '")}'`;if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const s=a.get(r.parent);s?t.includes(s.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type ${i}.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${i}.`,issue:null}));if(r.entity){if(r.id===r.entity)return e.push(new w({id:`${r.id}--${r.entity}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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 s=a.get(r.entity);s?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(s.type)||e.push(new w({id:`${r.id}--${r.entity}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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 w({id:`${r.id}--${r.entity}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.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 Bc=(r=>(r.Entity="entity",r))(Bc||{});const De=class De extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"isList",null);h(this,"asType",null);h(this,"type",n.DataType);h(this,"options",null);h(this,"parentRelationType",null);h(this,"like");h(this,"implementationChooseOne",!1);h(this,"inferred",!1);h(this,"staticEntities",null);h(this,"interactiveEntities",null);h(this,"actionEntities",null);h(this,"entity",null);h(this,"andChildrenGroup",null);h(this,"orChildrenGroup",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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,this.staticEntities=e.staticEntities,this.interactiveEntities=e.interactiveEntities,this.actionEntities=e.actionEntities}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;e.entity&&(l=t.get(e.entity));const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType||null,options:e.options||null,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,staticEntities:e.staticEntities??null,interactiveEntities:e.interactiveEntities??null,actionEntities:e.actionEntities??null,entity:l,asType:e.asType,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var u;let i=JSON.parse(JSON.stringify(e));const s=[],l=FJ(i,t);if(s.push(...l,...ut(i)),i.entity){const f=t.get(i.entity);if(f.type===n.DefinitionEntity){const T=St(f).filter(I=>!I.interactive);if(T.length){const I=T.length>1?`entities with ids '${se(T.map(D=>D.id),"', '","' and '")}'`:`entity with id '${T[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${i.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${I}.
|
|
56
56
|
${sn}`,issue:null}))}}}const o=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),d=o?ln(o):null;if(d)s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${F(d,t)}" with id '${d.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(o){const f=o.type,c=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(c.includes(f)&&(i.parentRelationType&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${f}'.
|
|
57
57
|
The entitities of type '${se(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const T=(u=o.dataType)==null?void 0:u.id;s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${i.parent}' and type '${f}', because it already has a 'data-type' child with id '${T}'.
|
|
58
58
|
The entitities of type '${se(c,"', '","' 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:
|
|
59
59
|
${rr({describe_entity:T})}
|
|
60
|
-
Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}f===n.DataType&&(!i.parentRelationType||!(i.parentRelationType===wt.AndDataTypeGroup||i.parentRelationType===wt.OrDataTypeGroup))&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.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:s,modifiedData:i}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const i of e)if(i.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||ln(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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(null),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),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&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const l=B(this.initialData.entity),o=this.project.get(l);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.type===n.DataType?this.parentRelationType===wt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===wt.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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){var t,i,s,l;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const o=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=o}else this.entity=V(this.initialData.entity,this.project),((i=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:i.id)===this.id&&this.entity.setParent(this,null),(l=(s=this.entity).initChildren)==null||l.call(s,e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(o=>{const d=V(o,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(o=>{const d=V(o,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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.options=e.options||s.options,this.parentRelationType=e.parentRelationType||s.parentRelationType,this.isList=e.isList!==void 0?e.isList:s.isList,this.inferred=e.inferred!==void 0?e.inferred:s.inferred,this.like=e.like!==void 0?e.like:s.like,this.asType=e.asType!==void 0?e.asType:s.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:s.implementationChooseOne,this.staticEntities=e.staticEntities!==void 0?e.staticEntities:s.staticEntities,this.interactiveEntities=e.interactiveEntities!==void 0?e.interactiveEntities:s.interactiveEntities,this.actionEntities=e.actionEntities!==void 0?e.actionEntities:s.actionEntities,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await De.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:u,removed:f}=this.entity.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(!e){((d=this.parent)==null?void 0:d.type)===n.DataType&&this.parent.removeChildGroup(this);const u=this.parent;if((u==null?void 0:u.type)===n.DataType){if(this.parentRelationType===wt.AndDataTypeGroup){if(Array.isArray(u.andChildrenGroup)){const f=u.andChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.andChildrenGroup.splice(f,1)}}else if(this.parentRelationType===wt.OrDataTypeGroup&&Array.isArray(u.orChildrenGroup)){const f=u.orChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.orChildrenGroup.splice(f,1)}}else{const f=this.parent;f==null||f.removeDataType()}u&&i.push(u)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);i.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===wt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===wt.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),i.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlat(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlat(e)))||[],...((l=this.entity)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatIds(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatIds(e)))||[],...((l=this.entity)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((i=this.orChildrenGroup)==null?void 0:i.map(o=>o.toJSON(e)))||null,entity:((s=this.entity)==null?void 0:s.parent)===this?this.entity.toJSON(e):((l=this.entity)==null?void 0:l.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((u=this.andChildrenGroup)==null?void 0:u.map(I=>I.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(I=>I.toJSONClone({...e,newId:null})))||null,entity:((c=this.entity)==null?void 0:c.parent)===this?this.entity.toJSONClone({...e,newId:null}):((T=this.entity)==null?void 0:T.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(d=>d.toReference(e)))||null,orChildrenGroup:((l=this.orChildrenGroup)==null?void 0:l.map(d=>d.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatJSON(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatJSON(e)))||[],...((l=this.entity)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,i,s;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(l=>l.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(l=>l.clearErrors()),this.inferred&&this.entity&&this.entity.type===n.DefinitionEntity&&((i=this.entity)==null?void 0:i.parent)===this&&((s=this.entity)==null||s.clearErrors()),this}validate(){const e=p1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D,P;let l=mt(t,this),o=t||this.parent;const u={id:i||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},f=st(u,l);t&&f.setParent(t,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.andChildrenGroup)==null?void 0:I.map(C=>C.clone(e,f,m.UUID.uuid(),s)),T=(D=this.orChildrenGroup)==null?void 0:D.map(C=>C.clone(e,f,m.UUID.uuid(),s));if(f.andChildrenGroup=c||null,f.orChildrenGroup=T||null,this.entity&&this.entity.type===n.DefinitionEntity&&((P=this.entity)==null?void 0:P.parent)===this){const C=this.entity.clone(e,f,m.UUID.uuid(),s);f.setEntity(C)}else this.entity&&f.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),f}merge(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"merge-entity"))){const i=[],s=[],l=[],o=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},t),t==null||t.add(this,A.Updated),i.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},t),t==null||t.add(this,A.Updated),i.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},t),t==null||t.add(this,A.Updated),i.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const d=e.entity.clone(t,this,m.UUID.uuid(),!0);this.setEntity(d),s.push(d)}else e.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));this.inferred||(this.metaSync({inferred:!0},t),t==null||t.add(this,A.Updated),i.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},t),t==null||t.add(this,A.Updated),i.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:d,removed:u}=this.entity.remove({ignoreUpstream:!0},t);l.push(...u),d.push(...d)}e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));return t==null||t.attemptAutoclose("merge-entity",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(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===N.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type-from-inputs"))){var d;const i=[],s=[],l=[],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 u=F(this.parent,this.project)+" data type definition",f={id:m.UUID.uuid(),type:n.DefinitionEntity,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:u,description:((d=this.parent)==null?void 0:d.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},c=V(f,this.project);c.setParent(this,t),c.initChildren(t),t==null||t.add(c,A.Added),c.metaSync(f,t),this.setEntity(c),t==null||t.add(this,A.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:u,added:f,removed:c,affected:T}=this.entity.inferFromInputs(e,t);s.push(...u),i.push(...f),l.push(...c),o.push(...T)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:this}}};h(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,...i)=>null}),h(De,"type",n.DataType),h(De,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),h(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),h(De,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),h(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),h(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"inferred"]),h(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),h(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),h(De,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),h(De,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),h(De,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),h(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),h(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let Zr=De;function c1(r){var o;const a=uZ(),e=r.toJSON();a.safeParse(e).success;const i=xJ(r),s=Rr(r),l=[...i,...s];if(r.id==="exec-sequentially-operation-call-id"){const d=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate(),Ke(r.errors,l)}function xJ(r){const a=[];return r.inputs.forEach(e=>{e.validate()}),Ke(r.errors,a)}const kJ=Object.freeze(Object.defineProperty({__proto__:null,validate:c1},Symbol.toStringTag,{value:"Module"}));var f1=(r=>(r.Parent="parent",r))(f1||{});const Oe=class Oe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Operation);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const T=B(e.parent);i=t.get(T)}const s=B(e.declaration),l=t.get(s),o=e.calledByEntry.map(T=>{const I=B(T);return t.get(I)}),d=e.calledBySuccess.map(T=>{const I=B(T);return t.get(I)}),u=e.calledByError.map(T=>{const I=B(T);return t.get(I)}),f={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},c=V(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=B(i.declaration);if(o){const d=iP(o,t);s.push(...d)}else{const d=`
|
|
60
|
+
Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}f===n.DataType&&(!i.parentRelationType||!(i.parentRelationType===wt.AndDataTypeGroup||i.parentRelationType===wt.OrDataTypeGroup))&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.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:s,modifiedData:i}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const i of e)if(i.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||ln(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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(null),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),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&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const l=B(this.initialData.entity),o=this.project.get(l);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.type===n.DataType?this.parentRelationType===wt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===wt.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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){var t,i,s,l;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const o=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=o}else this.entity=V(this.initialData.entity,this.project),((i=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:i.id)===this.id&&this.entity.setParent(this,null),(l=(s=this.entity).initChildren)==null||l.call(s,e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(o=>{const d=V(o,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(o=>{const d=V(o,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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.options=e.options||s.options,this.parentRelationType=e.parentRelationType||s.parentRelationType,this.isList=e.isList!==void 0?e.isList:s.isList,this.inferred=e.inferred!==void 0?e.inferred:s.inferred,this.like=e.like!==void 0?e.like:s.like,this.asType=e.asType!==void 0?e.asType:s.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:s.implementationChooseOne,this.staticEntities=e.staticEntities!==void 0?e.staticEntities:s.staticEntities,this.interactiveEntities=e.interactiveEntities!==void 0?e.interactiveEntities:s.interactiveEntities,this.actionEntities=e.actionEntities!==void 0?e.actionEntities:s.actionEntities,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await De.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:u,removed:f}=this.entity.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(!e){((d=this.parent)==null?void 0:d.type)===n.DataType&&this.parent.removeChildGroup(this);const u=this.parent;if((u==null?void 0:u.type)===n.DataType){if(this.parentRelationType===wt.AndDataTypeGroup){if(Array.isArray(u.andChildrenGroup)){const f=u.andChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.andChildrenGroup.splice(f,1)}}else if(this.parentRelationType===wt.OrDataTypeGroup&&Array.isArray(u.orChildrenGroup)){const f=u.orChildrenGroup.findIndex(c=>c.id===this.id);f!==-1&&u.orChildrenGroup.splice(f,1)}}else{const f=this.parent;f==null||f.removeDataType()}u&&i.push(u)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);i.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===wt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===wt.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),i.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlat(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlat(e)))||[],...((l=this.entity)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatIds(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatIds(e)))||[],...((l=this.entity)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,options:this.options,asType:this.asType,type:this.type}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((i=this.orChildrenGroup)==null?void 0:i.map(o=>o.toJSON(e)))||null,entity:((s=this.entity)==null?void 0:s.parent)===this?this.entity.toJSON(e):((l=this.entity)==null?void 0:l.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,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,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((u=this.andChildrenGroup)==null?void 0:u.map(I=>I.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((f=this.orChildrenGroup)==null?void 0:f.map(I=>I.toJSONClone({...e,newId:null})))||null,entity:((c=this.entity)==null?void 0:c.parent)===this?this.entity.toJSONClone({...e,newId:null}):((T=this.entity)==null?void 0:T.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(d=>d.toReference(e)))||null,orChildrenGroup:((l=this.orChildrenGroup)==null?void 0:l.map(d=>d.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatJSON(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatJSON(e)))||[],...((l=this.entity)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,i,s;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(l=>l.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(l=>l.clearErrors()),this.inferred&&this.entity&&this.entity.type===n.DefinitionEntity&&((i=this.entity)==null?void 0:i.parent)===this&&((s=this.entity)==null||s.clearErrors()),this}validate(){const e=p1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D,P;let l=mt(t,this),o=t||this.parent;const u={id:i||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,staticEntities:this.staticEntities,interactiveEntities:this.interactiveEntities,actionEntities:this.actionEntities,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},f=st(u,l);t&&f.setParent(t,null),s&&f.subscribe(),f.initChildren(e),e==null||e.add(f,A.Added);const c=(I=this.andChildrenGroup)==null?void 0:I.map(C=>C.clone(e,f,m.UUID.uuid(),s)),T=(D=this.orChildrenGroup)==null?void 0:D.map(C=>C.clone(e,f,m.UUID.uuid(),s));if(f.andChildrenGroup=c||null,f.orChildrenGroup=T||null,this.entity&&this.entity.type===n.DefinitionEntity&&((P=this.entity)==null?void 0:P.parent)===this){const C=this.entity.clone(e,f,m.UUID.uuid(),s);f.setEntity(C)}else this.entity&&f.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),f}merge(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"merge-entity"))){const i=[],s=[],l=[],o=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},t),t==null||t.add(this,A.Updated),i.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},t),t==null||t.add(this,A.Updated),i.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},t),t==null||t.add(this,A.Updated),i.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const d=e.entity.clone(t,this,m.UUID.uuid(),!0);this.setEntity(d),s.push(d)}else e.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));this.inferred||(this.metaSync({inferred:!0},t),t==null||t.add(this,A.Updated),i.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},t),t==null||t.add(this,A.Updated),i.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:d,removed:u}=this.entity.remove({ignoreUpstream:!0},t);l.push(...u),d.push(...d)}e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));return t==null||t.attemptAutoclose("merge-entity",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(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===N.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type-from-inputs"))){var d;const i=[],s=[],l=[],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 u=F(this.parent,this.project)+" data type definition",f={id:m.UUID.uuid(),type:n.DefinitionEntity,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:u,description:((d=this.parent)==null?void 0:d.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},c=V(f,this.project);c.setParent(this,t),c.initChildren(t),t==null||t.add(c,A.Added),c.metaSync(f,t),this.setEntity(c),t==null||t.add(this,A.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:u,added:f,removed:c,affected:T}=this.entity.inferFromInputs(e,t);s.push(...u),i.push(...f),l.push(...c),o.push(...T)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:this}}};h(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,...i)=>null}),h(De,"type",n.DataType),h(De,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),h(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),h(De,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like","implementationChooseOne","staticEntities","interactiveEntities","actionEntities"]),h(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),h(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"inferred"]),h(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),h(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),h(De,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),h(De,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),h(De,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),h(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),h(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let Zr=De;function c1(r){var o;const a=uZ(),e=r.toJSON();a.safeParse(e).success;const i=xJ(r),s=Rr(r),l=[...i,...s];if(r.id==="exec-sequentially-operation-call-id"){const d=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate(),Ke(r.errors,l)}function xJ(r){const a=[];return r.inputs.forEach(e=>{e.validate()}),Ke(r.errors,a)}const kJ=Object.freeze(Object.defineProperty({__proto__:null,validate:c1},Symbol.toStringTag,{value:"Module"}));var f1=(r=>(r.Parent="parent",r))(f1||{});const Oe=class Oe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Operation);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const T=B(e.parent);i=t.get(T)}const s=B(e.declaration),l=t.get(s),o=e.calledByEntry.map(T=>{const I=B(T);return t.get(I)}),d=e.calledBySuccess.map(T=>{const I=B(T);return t.get(I)}),u=e.calledByError.map(T=>{const I=B(T);return t.get(I)}),f={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},c=V(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=B(i.declaration);if(o){const d=iP(o,t);s.push(...d)}else{const d=`
|
|
61
61
|
All built-in 'action-descriptor' entity ids are:
|
|
62
62
|
- ${t.operationDeclarations.map(u=>`${u.id} (${F(u,t)})`).join(`
|
|
63
63
|
- `)}.
|
|
64
64
|
`;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:O.Error,message:`Entity of type "${n.Operation}" with id "${i.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'action-descriptor' entity.
|
|
65
65
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${d}`,issue:null}))}return{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
66
66
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
67
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:T}=this.syncMissingFixedOutputs(e),{updated:I,added:D,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...f,...I),i.push(...d,...c,...I),s.push(...u,...T,...I),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&i.setParent(this.parent,null);return i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=c1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===L.FixedArguments&&!this.inputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id}));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.outputs.filter(c=>c.parentRelationType===L.FixedReturns&&!this.outputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id}));this.outputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.outputs.forEach(D=>{D.index>=c.index&&D.index++});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:c.toJSON(),defaultValue:null,writesValues:[],index:c.index,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.outputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Oe,"type",n.Operation),h(Oe,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),h(Oe,"MUTABLE_BASE_PROPERTIES",[]),h(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),h(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),h(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let qr=Oe;function h1(r){var s;const a=B5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const ZJ=Object.freeze(Object.defineProperty({__proto__:null,validate:h1},Symbol.toStringTag,{value:"Module"}));var y1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(y1||{});const Pe=class Pe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"isError");h(this,"type",n.ReturnDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"readsValue",null);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=B(e.readsValue);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Cc(i,t);if(i=l.modifiedData,i.parent){const f=t.get(B(i.parent));if(f&&[n.BreakStatement,n.ContinueStatement].includes(f.type)){const c=f,T=c.parent,I=[...T.breakStatements.filter(P=>P.id!==f.id),...T.continueStatements.filter(P=>P.id!==f.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
|
|
67
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:T}=this.syncMissingFixedOutputs(e),{updated:I,added:D,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...f,...I),i.push(...d,...c,...I),s.push(...u,...T,...I),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&i.setParent(this.parent,null);return i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=c1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===L.FixedArguments&&!this.inputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id}));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.outputs.filter(c=>c.parentRelationType===L.FixedReturns&&!this.outputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id}));this.outputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.outputs.forEach(D=>{D.index>=c.index&&D.index++});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:c.toJSON(),defaultValue:null,writesValues:[],index:c.index,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.outputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Oe,"type",n.Operation),h(Oe,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),h(Oe,"MUTABLE_BASE_PROPERTIES",[]),h(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),h(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),h(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),h(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let qr=Oe;function h1(r){var s;const a=B5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const ZJ=Object.freeze(Object.defineProperty({__proto__:null,validate:h1},Symbol.toStringTag,{value:"Module"}));var y1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(y1||{});const Pe=class Pe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"isError");h(this,"type",n.ReturnDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"readsValue",null);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=B(e.readsValue);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Cc(i,t);if(i=l.modifiedData,i.parent){const f=t.get(B(i.parent));if(f&&[n.BreakStatement,n.ContinueStatement].includes(f.type)){const c=f,T=c.parent,I=[...T.breakStatements.filter(P=>P.id!==f.id),...T.continueStatements.filter(P=>P.id!==f.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
|
|
68
68
|
${Gc}`,issue:null}));else{const P=(u=(d=I[0])==null?void 0:d.outputs[0])==null?void 0:u.name;P!==i.name&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This new 'return-declaration' doesn't have the same name "${P}" as the return declarations on the other statements in the same scope.
|
|
69
69
|
${Gc}`,issue:null}))}}else if(f&&f.type===n.ReturnStatement){const c=f.parent;if(c&&rt.includes(c.type)){const T=c.implements;if(T){const I=T.outputs.find(_=>_.name===i.name),D=T.outputs.filter(_=>!f.outputs.find(q=>q.type===n.ReturnDeclaration&&q.name===_.name)),P=f.outputs.filter(_=>_.type===n.ReturnDeclaration),C=P.find(_=>_.name===i.name),M=P.length?`The parent entity already implements the following return declarations: ${se(P.map(_=>`'${_.id}' (${_.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",G=D.length?`The parent entity is still missing the following returns in the implementation: ${se(D.map(_=>`'${_.id}' (${_.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";I?C&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${f.type}' with id '${f.id}' that implements a ${n.ActionDescriptor} with fixed outputs.
|
|
70
70
|
Adding a new return would make the implementation invalid. An return with the same name already exists in the parent entity.
|
|
@@ -73,39 +73,39 @@ ${G}`,issue:null})):s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSigna
|
|
|
73
73
|
Adding a new return would make the implementation invalid. There are no returns in the descriptor with the same name.
|
|
74
74
|
${M}
|
|
75
75
|
${G}`,issue:null}))}}}}return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.implements)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=ja(i,this);return i=s.modifiedData,t.push(...s.errors),i.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
76
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}propagateChanges(){const e=[this],t=[],i=[],s=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const l=this.parent.parent,{updated:o,added:d,removed:u}=l.syncChildren();e.push(...o),t.push(...d),i.push(...u)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 Or.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.required=e.required!==void 0?e.required:this.required,this.isError=e.isError!==void 0?e.isError:this.isError,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Pe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.getCounterparts();d.length&&d.forEach(u=>{if((!(t!=null&&t.hasRemoved(u.id))||!t)&&!u.deleted){const{updated:f,removed:c,added:T,affected:I}=u.remove({ignoreUpstream:e},t);i.push(...f),s.push(...c),l.push(...T),o.push(...I)}})}if(!e&&this.parent&&(this.isError?(this.parent.throws=null,t==null||t.add(this.parent,A.Updated)):this.parent.removeOutputDeclaration(this,t)),!e&&this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===n.Loop&&(t==null?void 0:t.self)===this&&this.parent.parent.afterAllChildrenInitialized(t),this.isError&&this.parent.type===n.ReturnStatement){const{updated:d,added:u,removed:f,affected:c}=this.parent.syncReturnDeclarations(t);i.push(...d),l.push(...u),s.push(...f),o.push(...c)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);i.push(...o.updated)}return this.parent&&this.parent.addOutputDeclaration(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...((l=this.dataType)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatIds(e))||[],...((l=this.dataType)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,readsValue:((T=this.readsValue)==null?void 0:T.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatJSON(e))||[],...((l=this.dataType)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.dataType)==null?void 0:l.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=h1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var T,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(T=this.dataType)==null?void 0:T.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type"))){var i;const t=Ic(this,e);if(t&&t.parent===this)this.dataType&&this.dataType.merge(t,e);else if(t&&t.parent!==this)if(this.dataType)this.dataType.merge(t,e);else{const s=t.clone(e,this);e==null||e.add(s,A.Added),this.setDataType(s)}return(i=this.dataType)==null||i.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(l=>l.outputs).filter(l=>F(l,this.project)===F(this,this.project)&&l.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const i=this.parent.parent.returnStatements.flatMap(s=>s.outputs);this.implements?e=i.filter(l=>{var o;return this.implements.id===((o=l.implements)==null?void 0:o.id)}):e=i.filter(l=>F(l,this.project)===F(this,this.project)&&l.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var s,l,o;const t=this.getCounterparts(),i=t.find(d=>{var u;return(u=d.dataType)==null?void 0:u.isResolved});if(i)this.setDataType(i.dataType),e==null||e.add(this,A.Updated);else for(let d=0;d<t.length;d++){const u=t[d];if((!u.dataType||!u.dataType.isResolved||(s=u.dataType)!=null&&s.inferred)&&u.readsValue&&u.inferDataType(e),(l=u.dataType)!=null&&l.isResolved){this.setDataType(u.dataType),e==null||e.add(this,A.Updated);break}}return(o=this.dataType)==null||o.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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}};h(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Pe,"type",n.ReturnDeclaration),h(Pe,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),h(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES]),h(Pe,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),h(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),h(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,"index"]),h(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),h(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),h(Pe,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),h(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),h(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),h(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let ri=Pe;function m1(r){var s;const a=w5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const qJ=Object.freeze(Object.defineProperty({__proto__:null,validate:m1},Symbol.toStringTag,{value:"Module"}));function v1(r){var s;const a=R5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const JJ=Object.freeze(Object.defineProperty({__proto__:null,validate:v1},Symbol.toStringTag,{value:"Module"}));var E1=(r=>(r.Parent="parent",r))(E1||{});const xe=class xe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.ContinueStatement);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"throws",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),o=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),d=e.calledByError.map(c=>{const T=B(c);return t.get(T)}),u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},f=V(u,t);return f.setParent(s,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
76
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}propagateChanges(){const e=[this],t=[],i=[],s=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const l=this.parent.parent,{updated:o,added:d,removed:u}=l.syncChildren();e.push(...o),t.push(...d),i.push(...u)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 Or.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.required=e.required!==void 0?e.required:this.required,this.isError=e.isError!==void 0?e.isError:this.isError,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Pe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const d=this.getCounterparts();d.length&&d.forEach(u=>{if((!(t!=null&&t.hasRemoved(u.id))||!t)&&!u.deleted){const{updated:f,removed:c,added:T,affected:I}=u.remove({ignoreUpstream:e},t);i.push(...f),s.push(...c),l.push(...T),o.push(...I)}})}if(!e&&this.parent&&(this.isError?(this.parent.throws=null,t==null||t.add(this.parent,A.Updated)):this.parent.removeOutputDeclaration(this,t)),!e&&this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)&&this.parent.parent&&this.parent.parent.type===n.Loop&&(t==null?void 0:t.self)===this&&this.parent.parent.afterAllChildrenInitialized(t),this.isError&&this.parent.type===n.ReturnStatement){const{updated:d,added:u,removed:f,affected:c}=this.parent.syncReturnDeclarations(t);i.push(...d),l.push(...u),s.push(...f),o.push(...c)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);i.push(...o.updated)}return this.parent&&this.parent.addOutputDeclaration(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...((l=this.dataType)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatIds(e))||[],...((l=this.dataType)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,readsValue:((T=this.readsValue)==null?void 0:T.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatJSON(e))||[],...((l=this.dataType)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.dataType)==null?void 0:l.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=h1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var T,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(T=this.dataType)==null?void 0:T.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type"))){var i;const t=Ic(this,e);if(t&&t.parent===this)this.dataType&&this.dataType.merge(t,e);else if(t&&t.parent!==this)if(this.dataType)this.dataType.merge(t,e);else{const s=t.clone(e,this);e==null||e.add(s,A.Added),this.setDataType(s)}return(i=this.dataType)==null||i.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;e=[...t.breakStatements,...t.continueStatements].flatMap(l=>l.outputs).filter(l=>F(l,this.project)===F(this,this.project)&&l.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const i=this.parent.parent.returnStatements.flatMap(s=>s.outputs);this.implements?e=i.filter(l=>{var o;return this.implements.id===((o=l.implements)==null?void 0:o.id)}):e=i.filter(l=>F(l,this.project)===F(this,this.project)&&l.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var s,l,o;const t=this.getCounterparts(),i=t.find(d=>{var u;return(u=d.dataType)==null?void 0:u.isResolved});if(i)this.setDataType(i.dataType),e==null||e.add(this,A.Updated);else for(let d=0;d<t.length;d++){const u=t[d];if((!u.dataType||!u.dataType.isResolved||(s=u.dataType)!=null&&s.inferred)&&u.readsValue&&u.inferDataType(e),(l=u.dataType)!=null&&l.isResolved){this.setDataType(u.dataType),e==null||e.add(this,A.Updated);break}}return(o=this.dataType)==null||o.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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}};h(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Pe,"type",n.ReturnDeclaration),h(Pe,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),h(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES]),h(Pe,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),h(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),h(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,"index"]),h(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),h(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),h(Pe,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),h(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),h(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),h(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let ri=Pe;function m1(r){var s;const a=w5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const qJ=Object.freeze(Object.defineProperty({__proto__:null,validate:m1},Symbol.toStringTag,{value:"Module"}));function v1(r){var s;const a=R5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const JJ=Object.freeze(Object.defineProperty({__proto__:null,validate:v1},Symbol.toStringTag,{value:"Module"}));var E1=(r=>(r.Parent="parent",r))(E1||{});const xe=class xe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.ContinueStatement);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"throws",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),o=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),d=e.calledByError.map(c=>{const T=B(c);return t.get(T)}),u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},f=V(u,t);return f.setParent(s,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
77
77
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
78
78
|
You shouldn't have to manually update a 'parent' property.
|
|
79
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(u=>{u.addCall(this,e),t.push(u)}),this.calledBySuccess.forEach(u=>{u.addSuccessCall(this,e),t.push(u)}),this.calledByError.forEach(u=>{u.addErrorCall(this,e),t.push(u)}),this.parent.addContinueStatement(this),t.push(this),e==null||e.add(this.parent,A.Affected),(o=this.parent)==null||o.breakStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),(d=this.parent)==null||d.continueStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d,u;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(f=>{const{updated:c,removed:T,added:I}=f.entity.onDetachedDependencyRemoved(this,f.field,t);i.push(...c),s.push(...T),l.push(...I)}),this.outputs.forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!0},t);i.push(...c),s.push(...T)}),this.throws){const{updated:f,removed:c}=this.throws.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}return e||(this.parent.removeContinueStatement(this),this.calledBy.forEach(f=>{i.push(f),f.removeCall(this,t)})),t==null||t.add(this.parent,A.Affected),(d=this.parent)==null||d.breakStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),(u=this.parent)==null||u.continueStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),throws:((u=this.throws)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.calledBy.flatMap(s=>s.toFlatJSON(e)),...((i=this.throws)==null?void 0:i.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=v1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.outputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-return-declaration-"+P+"-id",s));return c.outputs=T,this.throws&&(c.throws=this.throws.clone(e,c,f+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(xe,"type",n.ContinueStatement),h(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),h(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),h(xe,"MUTABLE_BASE_PROPERTIES",[]),h(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),h(xe,"MUTABLE_META_PROPERTIES",["x","y"]),h(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),h(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),h(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),h(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),h(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Gt=xe;var Mc=(r=>(r.Parent="return-statement-parent",r))(Mc||{});const at=class at extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.ReturnStatement);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"throws",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),o=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),d=e.calledByError.map(c=>{const T=B(c);return t.get(T)}),u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},f=V(u,t);return f.setParent(s,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:ht}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
79
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(u=>{u.addCall(this,e),t.push(u)}),this.calledBySuccess.forEach(u=>{u.addSuccessCall(this,e),t.push(u)}),this.calledByError.forEach(u=>{u.addErrorCall(this,e),t.push(u)}),this.parent.addContinueStatement(this),t.push(this),e==null||e.add(this.parent,A.Affected),(o=this.parent)==null||o.breakStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),(d=this.parent)==null||d.continueStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d,u;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(f=>{const{updated:c,removed:T,added:I}=f.entity.onDetachedDependencyRemoved(this,f.field,t);i.push(...c),s.push(...T),l.push(...I)}),this.outputs.forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!0},t);i.push(...c),s.push(...T)}),this.throws){const{updated:f,removed:c}=this.throws.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}return e||(this.parent.removeContinueStatement(this),this.calledBy.forEach(f=>{i.push(f),f.removeCall(this,t)})),t==null||t.add(this.parent,A.Affected),(d=this.parent)==null||d.breakStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),(u=this.parent)==null||u.continueStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),throws:((u=this.throws)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.calledBy.flatMap(s=>s.toFlatJSON(e)),...((i=this.throws)==null?void 0:i.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=v1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.outputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-return-declaration-"+P+"-id",s));return c.outputs=T,this.throws&&(c.throws=this.throws.clone(e,c,f+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(xe,"type",n.ContinueStatement),h(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),h(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),h(xe,"MUTABLE_BASE_PROPERTIES",[]),h(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),h(xe,"MUTABLE_META_PROPERTIES",["x","y"]),h(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),h(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),h(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),h(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),h(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let Gt=xe;var Mc=(r=>(r.Parent="return-statement-parent",r))(Mc||{});const at=class at extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.ReturnStatement);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"throws",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),o=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),d=e.calledByError.map(c=>{const T=B(c);return t.get(T)}),u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},f=V(u,t);return f.setParent(s,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:ht}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
80
80
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
81
81
|
You shouldn't have to manually update a 'parent' property.
|
|
82
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="return-statement-parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="return-statement-parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"return-statement-parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"return-statement-parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new at(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new at(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:f}=this.syncReturnDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),l.push(...f),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.parent.addReturnStatement(this),t.push(this.parent),e==null||e.add(this.parent,A.Affected),(o=this.parent)==null||o.returnStatements.forEach(d=>{d.id!==this.id&&(l.push(d),e==null||e.add(d,A.Affected))}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await at.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await at.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await at.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await at.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await at.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await at.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.throws){const{updated:u,removed:f}=this.throws.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return e||(this.parent.removeReturnStatement(this),this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)})),t==null||t.add(this.parent,A.Affected),(d=this.parent)==null||d.returnStatements.forEach(u=>{u.id!==this.id&&(o.push(u),t==null||t.add(u,A.Affected))}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=m1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.outputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-return-declaration-"+P+"-id",s));return c.outputs=T,this.throws&&(c.throws=this.throws.clone(e,c,f+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncReturnDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-return-declarations"))){const t=[],i=[],s=[],l=[],o=It(this,this.project);if(!o.implements)return this.throws&&this.outputs.length&&this.outputs.forEach(T=>{var I;if(T.id!==((I=this.throws)==null?void 0:I.id)){const{updated:D,removed:P}=T.remove({ignoreUpstream:!0},e);t.push(...D),s.push(...P),this.removeOutputDeclaration(T,e)}}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};const d=o.implements.outputs.find(T=>T.parentRelationType===L.ReturnedError),u=o.implements.outputs.filter(T=>T.parentRelationType!==L.ReturnedError);if(d&&!this.throws){const T=d.implementAsReturnDeclaration(e,this);return i.push(T),this.outputs.forEach(I=>{if(I.id!==T.id){const{updated:D,removed:P}=I.remove({ignoreUpstream:!0},e);t.push(...D),s.push(...P),this.removeOutputDeclaration(I,e)}}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}if(!d&&this.throws){const{updated:T,removed:I}=this.throws.remove({ignoreUpstream:!0},e);t.push(...T),s.push(...I)}return u.filter(T=>!this.outputs.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===T.id&&!I.isError})).forEach(T=>{const I=T.implementAsReturnDeclaration(e,this);i.push(I)}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(at,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(at,"type",n.ReturnStatement),h(at,"USER_MANAGED_PARENT_TYPES",[...ht]),h(at,"PARENT_TYPES",[...at.USER_MANAGED_PARENT_TYPES]),h(at,"MUTABLE_BASE_PROPERTIES",[]),h(at,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(at,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),h(at,"MUTABLE_META_PROPERTIES",["x","y"]),h(at,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),h(at,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),h(at,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(at,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(at,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),h(at,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),h(at,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(at,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(at,"PROPERTIES",[...ri.META_PROPERTIES,...ri.UPSTREAM_PROPERTIES,...ri.DOWNSTREAM_PROPERTIES]);let Jr=at;function T1(r){const a=zZ(),e=r.toJSON();a.safeParse(e).success;const i=ci(r);r.inputs.forEach(l=>l.validate()),i.forEach(l=>l.validate());const s=[];return Ke(r.errors,s)}const WJ=Object.freeze(Object.defineProperty({__proto__:null,validate:T1},Symbol.toStringTag,{value:"Module"})),we=class we extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"type",n.GlobalEvent);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"implements");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.collapsed=e.collapsed}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=B(e.parent);i=t.get(d)}let s;e.implements&&(s=t.getBuiltIn(e.implements));const l={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=V(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{},t);if(i=l.modifiedData,s.push(...l.errors,...ut(i)),!e.implements)s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="return-statement-parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="return-statement-parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"return-statement-parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"return-statement-parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new at(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new at(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:f}=this.syncReturnDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),l.push(...f),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.parent.addReturnStatement(this),t.push(this.parent),e==null||e.add(this.parent,A.Affected),(o=this.parent)==null||o.returnStatements.forEach(d=>{d.id!==this.id&&(l.push(d),e==null||e.add(d,A.Affected))}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await at.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await at.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await at.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await at.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await at.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await at.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.throws){const{updated:u,removed:f}=this.throws.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return e||(this.parent.removeReturnStatement(this),this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)})),t==null||t.add(this.parent,A.Affected),(d=this.parent)==null||d.returnStatements.forEach(u=>{u.id!==this.id&&(o.push(u),t==null||t.add(u,A.Affected))}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=m1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.outputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-return-declaration-"+P+"-id",s));return c.outputs=T,this.throws&&(c.throws=this.throws.clone(e,c,f+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncReturnDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-return-declarations"))){const t=[],i=[],s=[],l=[],o=It(this,this.project);if(!o.implements)return this.throws&&this.outputs.length&&this.outputs.forEach(T=>{var I;if(T.id!==((I=this.throws)==null?void 0:I.id)){const{updated:D,removed:P}=T.remove({ignoreUpstream:!0},e);t.push(...D),s.push(...P),this.removeOutputDeclaration(T,e)}}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};const d=o.implements.outputs.find(T=>T.parentRelationType===L.ReturnedError),u=o.implements.outputs.filter(T=>T.parentRelationType!==L.ReturnedError);if(d&&!this.throws){const T=d.implementAsReturnDeclaration(e,this);return i.push(T),this.outputs.forEach(I=>{if(I.id!==T.id){const{updated:D,removed:P}=I.remove({ignoreUpstream:!0},e);t.push(...D),s.push(...P),this.removeOutputDeclaration(I,e)}}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}if(!d&&this.throws){const{updated:T,removed:I}=this.throws.remove({ignoreUpstream:!0},e);t.push(...T),s.push(...I)}return u.filter(T=>!this.outputs.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===T.id&&!I.isError})).forEach(T=>{const I=T.implementAsReturnDeclaration(e,this);i.push(I)}),e==null||e.attemptAutoclose("sync-return-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(at,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(at,"type",n.ReturnStatement),h(at,"USER_MANAGED_PARENT_TYPES",[...ht]),h(at,"PARENT_TYPES",[...at.USER_MANAGED_PARENT_TYPES]),h(at,"MUTABLE_BASE_PROPERTIES",[]),h(at,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(at,"BASE_PROPERTIES",[...Gt.MUTABLE_BASE_PROPERTIES,...Gt.INMUTABLE_BASE_PROPERTIES]),h(at,"MUTABLE_META_PROPERTIES",["x","y"]),h(at,"INMUTABLE_META_PROPERTIES",[...Gt.INMUTABLE_BASE_PROPERTIES]),h(at,"META_PROPERTIES",[...Gt.MUTABLE_META_PROPERTIES,...Gt.INMUTABLE_META_PROPERTIES]),h(at,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(at,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(at,"UPSTREAM_PROPERTIES",[...Gt.MUTABLE_UPSTREAM_PROPERTIES,...Gt.INMUTABLE_UPSTREAM_PROPERTIES]),h(at,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),h(at,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(at,"DOWNSTREAM_PROPERTIES",[...Gt.MUTABLE_DOWNSTREAM_PROPERTIES,...Gt.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(at,"PROPERTIES",[...ri.META_PROPERTIES,...ri.UPSTREAM_PROPERTIES,...ri.DOWNSTREAM_PROPERTIES]);let Jr=at;function T1(r){const a=zZ(),e=r.toJSON();a.safeParse(e).success;const i=ci(r);r.inputs.forEach(l=>l.validate()),i.forEach(l=>l.validate());const s=[];return Ke(r.errors,s)}const WJ=Object.freeze(Object.defineProperty({__proto__:null,validate:T1},Symbol.toStringTag,{value:"Module"})),we=class we extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"collapsed");h(this,"type",n.GlobalEvent);h(this,"inputs",[]);h(this,"calls",[]);h(this,"parent");h(this,"implements");h(this,"detachedChildren",[]);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.collapsed=e.collapsed}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=B(e.parent);i=t.get(d)}let s;e.implements&&(s=t.getBuiltIn(e.implements));const l={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=V(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{},t);if(i=l.modifiedData,s.push(...l.errors,...ut(i)),!e.implements)s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'implements' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
|
|
83
83
|
${Jl(t)}`,issue:null}));else if(!t.get(e.implements))s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that isn't found in the project. The 'implements' property must point to one of the built-in action descriptors reserved for 'global-event' entities.
|
|
84
84
|
${Jl(t)}`,issue:null}));else if(!t.globalEventActionDescriptors.find(u=>u.id===e.implements))s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that isn't pointing to an action descriptor reserved for 'global-event' entities.
|
|
85
85
|
${Jl(t)}`,issue:null}));else{const u=t.events.find(f=>f.implements.id===e.implements);u&&s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that points to an action descriptor that is already implemented by another global event with id '${u.id}' in the project. Each global event must implement a unique action descriptor.
|
|
86
|
-
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Mc.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new we(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=V(t,this.project);if(i.addEntryCaller(this,null),i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e));return i}),this.implements=V(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await we.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await we.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),ci(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),ci(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ci(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),calls:this.calls.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=T1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ci(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[];const f=u.split("-id"),c=f[f.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const T=st(d,o);t?T.setParent(t,null):T.setParent(this.parent,null),s&&T.subscribe(),T.initChildren(e),e==null||e.add(T,A.Added);const I=(P=this.inputs)==null?void 0:P.map((C,M)=>C.clone(e,T,c+"-argument-declaration-"+M+"-id",s));return T.inputs=I,l?(ci(this).map((C,M)=>C.clone(e,T,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),T):(e==null||e.attemptAutoclose("clone-entity",this.id),T)}getVariableInstances(){return He(this).filter(i=>i.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};h(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(we,"type",n.GlobalEvent),h(we,"USER_MANAGED_PARENT_TYPES",[n.Project]),h(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),h(we,"MUTABLE_BASE_PROPERTIES",["description"]),h(we,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(we,"BASE_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,...we.INMUTABLE_BASE_PROPERTIES]),h(we,"MUTABLE_META_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),h(we,"INMUTABLE_META_PROPERTIES",[...we.INMUTABLE_BASE_PROPERTIES]),h(we,"META_PROPERTIES",[...we.MUTABLE_META_PROPERTIES,...we.INMUTABLE_META_PROPERTIES]),h(we,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(we,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),h(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),h(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),h(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Wr=we;function Nc(r){var l,o;const a=T5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(l=r.error)==null||l.validate(),(o=r.body)==null||o.validate();const s=[...Rr(r)];return Ke(r.errors,s)}function SJ(r){return Nc(r)}const zJ=Object.freeze(Object.defineProperty({__proto__:null,validate:Nc,validateListLoop:SJ},Symbol.toStringTag,{value:"Module"}));function I1(r){const a=RD(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return Ke(r.errors,i)}const YJ=Object.freeze(Object.defineProperty({__proto__:null,validate:I1},Symbol.toStringTag,{value:"Module"}));var A1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(A1||{});const Ce=class Ce extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"implementation",null);h(this,"parent",null);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=B(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},l=V(s,t);return i&&l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=l.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const d=o,f=St(d).filter(c=>!c.interactive);if(f.length){let c=f.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(f.map(T=>F(T,T.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(f[0],f[0].project)}").`;c+=`
|
|
86
|
+
You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Mc.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new we(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new we(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=V(t,this.project);if(i.addEntryCaller(this,null),i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e));return i}),this.implements=V(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await we.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await we.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await we.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await we.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await we.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await we.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),ci(this).forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRestored(this,d.field,e);i.push(...u),s.push(...f),t.push(...c)}),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),ci(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=ci(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),calls:this.calls.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=T1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=ci(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[];const f=u.split("-id"),c=f[f.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const T=st(d,o);t?T.setParent(t,null):T.setParent(this.parent,null),s&&T.subscribe(),T.initChildren(e),e==null||e.add(T,A.Added);const I=(P=this.inputs)==null?void 0:P.map((C,M)=>C.clone(e,T,c+"-argument-declaration-"+M+"-id",s));return T.inputs=I,l?(ci(this).map((C,M)=>C.clone(e,T,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),T):(e==null||e.attemptAutoclose("clone-entity",this.id),T)}getVariableInstances(){return He(this).filter(i=>i.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};h(we,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(we,"type",n.GlobalEvent),h(we,"USER_MANAGED_PARENT_TYPES",[n.Project]),h(we,"PARENT_TYPES",[...we.USER_MANAGED_PARENT_TYPES]),h(we,"MUTABLE_BASE_PROPERTIES",["description"]),h(we,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(we,"BASE_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,...we.INMUTABLE_BASE_PROPERTIES]),h(we,"MUTABLE_META_PROPERTIES",[...we.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),h(we,"INMUTABLE_META_PROPERTIES",[...we.INMUTABLE_BASE_PROPERTIES]),h(we,"META_PROPERTIES",[...we.MUTABLE_META_PROPERTIES,...we.INMUTABLE_META_PROPERTIES]),h(we,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(we,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),h(we,"UPSTREAM_PROPERTIES",[...we.MUTABLE_UPSTREAM_PROPERTIES,...we.INMUTABLE_UPSTREAM_PROPERTIES]),h(we,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),h(we,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(we,"DOWNSTREAM_PROPERTIES",[...we.MUTABLE_DOWNSTREAM_PROPERTIES,...we.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(we,"PROPERTIES",[...we.META_PROPERTIES,...we.UPSTREAM_PROPERTIES,...we.DOWNSTREAM_PROPERTIES]);let Wr=we;function Nc(r){var l,o;const a=T5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(l=r.error)==null||l.validate(),(o=r.body)==null||o.validate();const s=[...Rr(r)];return Ke(r.errors,s)}function SJ(r){return Nc(r)}const zJ=Object.freeze(Object.defineProperty({__proto__:null,validate:Nc,validateListLoop:SJ},Symbol.toStringTag,{value:"Module"}));function I1(r){const a=RD(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return Ke(r.errors,i)}const YJ=Object.freeze(Object.defineProperty({__proto__:null,validate:I1},Symbol.toStringTag,{value:"Module"}));var A1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(A1||{});const Ce=class Ce extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"implementation",null);h(this,"parent",null);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=B(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},l=V(s,t);return i&&l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=l.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const d=o,f=St(d).filter(c=>!c.interactive);if(f.length){let c=f.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${se(f.map(T=>F(T,T.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${F(f[0],f[0].project)}").`;c+=`
|
|
87
87
|
${sn}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:O.Error,message:c,issue:null}))}}else if(o&&o.type===n.DataType){const d=o;d.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
88
88
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
89
89
|
${rr({describe_entity:d.entity.id})}
|
|
90
90
|
Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}syncOperationInstance(e,t){return{updated:[],added:[],removed:[],affected:[],self:e}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-input-map-data-type"))){const i=Tc(e);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:i}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-output-map-data-type"))){const i=Ac(e);return t==null||t.attemptAutoclose("infer-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
91
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];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),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this})}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ce.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);i.push(...u.updated),s.push(...u.removed)}),this.outputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);i.push(...u.updated),s.push(...u.removed)}),this.error){const d=this.error.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.inputs.forEach(o=>{const d=o.restore({},e);i.push(...d.updated)}),this.outputs.forEach(o=>{const d=o.restore({},e);i.push(...d.updated)}),this.error){const o=this.error.restore({},e);i.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(s=>s.toJSON()),outputs:this.outputs.map(s=>s.toJSON()),parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((s=this.error)==null?void 0:s.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e))])}asFunctionDeclarationTransfer(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-function-declaration"))){var d;const i=e||m.UUID.uuid(),s=m.UUID.uuid(),l=this.inputs.map((u,f)=>{var T;const c={id:m.UUID.uuid(),type:n.GenericReference,version:s,entityType:n.FunctionDeclaration,entityId:i};return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:u.name,required:u.required,implements:u.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:u.description,index:f,dataType:((T=u.dataType)==null?void 0:T.toJSONClone({timestamp:(t==null?void 0:t.timestamp)||E().toISOString()}))||null,parent:c}}),o=[];if(this.outputs.length){const u=this.outputs.map((I,D)=>{var C;const P={id:m.UUID.uuid(),type:n.GenericReference,entityId:i,version:s,entityType:n.ReturnStatement};return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:I.name,description:I.description,readsValue:null,constant:!0,required:I.required,defaultValue:null,implements:I.toJSON(),isError:!1,index:D,dataType:((C=I.dataType)==null?void 0:C.toJSONClone())||null,parent:P}}),f={id:m.UUID.uuid(),type:n.GenericReference,version:s,entityType:n.FunctionDeclaration,entityId:i},c={id:m.UUID.uuid(),type:n.GenericReference,version:s,entityType:n.FunctionDeclaration,entityId:i},T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:u,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[c],parent:f,x:0,y:0};o.push(T)}return t==null||t.attemptAutoclose("implement-as-function-declaration",this.id),{id:i,version:s,createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:l,calls:o,collapsed:!1,private:!1,implements:this.toJSON(),extends:null,index:0,parent:((d=this.parent)==null?void 0:d.toReference())||null,x:0,y:0}}implementAsGlobalEvent(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-global-event")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,implements:this.toJSON(),parent:(s==null?void 0:s.toReference())||null,x:0,y:0},u=V(d,this.project);if(u.setParent(s,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((f,c)=>{var C;const T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:f.name,required:f.required,implements:f.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:f.description,index:c,dataType:null,parent:T},D=V(I,this.project);D.setParent(u,e),D.initChildren(e),e==null||e.add(D,A.Added),D.hydrateAncestors(),D.addSelfToProject(e);const P=((C=f.dataType)==null?void 0:C.clone(e,D))||null;P&&(e==null||e.add(P,A.Added)),D.setDataType(P)}),this.outputs.length){const f=m.UUID.uuid(),c=m.UUID.uuid(),T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},I={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},D={id:f,version:c,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[I],parent:T,x:0,y:0},P=V(D,this.project);P.setParent(u,e),P.initChildren(e),e==null||e.add(P,A.Added),P.hydrateAncestors(),P.addSelfToProject(e),this.outputs.map((C,M)=>{var S;const G={id:m.UUID.uuid(),type:n.GenericReference,entityId:f,version:c,entityType:n.ReturnStatement},_={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:C.name,description:C.description,readsValue:null,constant:!0,required:C.required,defaultValue:null,implements:C.toJSON(),isError:!1,index:M,dataType:null,parent:G},g=V(_,this.project);g.setParent(P,e),g.initChildren(e),e==null||e.add(g,A.Added),g.hydrateAncestors(),g.addSelfToProject(e);const q=((S=C.dataType)==null?void 0:S.clone(e,g))||null;q&&(e==null||e.add(q,A.Added)),g.setDataType(q)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsFunctionDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-function-declaration")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={extends:null,id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:(s==null?void 0:s.toReference())||null,x:0,y:0},u=V(d,this.project);if(u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),this.inputs.map((f,c)=>{var M,G;const T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:f.name,required:f.required,implements:f.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:f.description,index:c,dataType:null,parent:T},D=V(I,this.project);D.setParent(u,e),D.initChildren(e),e==null||e.add(D,A.Added),D.hydrateAncestors(),D.addSelfToProject(e);const P=((M=f.dataType)==null?void 0:M.clone(e,D))||null;P&&(e==null||e.add(P,A.Added)),D.setDataType(P);const C=((G=f.defaultValue)==null?void 0:G.clone(e,D))||null;C&&(e==null||e.add(C,A.Added)),D.setDataType(P)}),this.outputs.length){const f=m.UUID.uuid(),c=m.UUID.uuid(),T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},I={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},D={id:f,version:c,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[I],parent:T,x:0,y:0},P=V(D,this.project);P.hydrateAncestors(),P.setParent(u,e),P.addSelfToProject(e),e==null||e.add(P,A.Added),P.initChildren(e)}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsLoop(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-loop")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,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:s.toReference()},u=V(d,this.project);return u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),s===this.project&&this.project.addLoop(u),e==null||e.attemptAutoclose("implement-as-loop",this.id),u}implementAsOperation(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-operation")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:s.toReference()},u=V(d,this.project);return u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),s===this.project&&this.project.addOperation(u),e==null||e.attemptAutoclose("implement-as-operation",this.id),u}implementAsCondition(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-condition")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:this.toJSON(),inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:s.toReference()},u=V(d,this.project);return u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),s===this.project&&this.project.addCondition(u),e==null||e.attemptAutoclose("implement-as-condition",this.id),u}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=I1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C;if(Array.from(new Set([...Gi(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const f=u.split("-id"),c=f[f.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const T=st(d,o);e==null||e.add(T,A.Added),t?T.setParent(t,null):this.parent&&T.setParent(this.parent,null),s&&T.subscribe(),T.initChildren(e);const I=(P=this.inputs)==null?void 0:P.map((M,G)=>M.clone(e,T,c+"-argument-value-descriptor-"+G+"-id",s));T.inputs=I;const D=(C=this.outputs)==null?void 0:C.map((M,G)=>M.clone(e,T,c+"-return-value-descriptor-"+G+"-id",s));return T.outputs=D,this.error&&(T.error=this.error.clone(e,T,c+"-error-action-descriptor-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),T}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.find(i=>i.id===e.id)||(this.inputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-input",this.id),this}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){return this.inputs.find(i=>i.id===e.id)&&(this.inputs=this.inputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output",this.id),this}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output",this.id),this}};h(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ce,"type",n.ActionDescriptor),h(Ce,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),h(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(Ce,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),h(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES]),h(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),h(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),h(Ce,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),h(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let We=Ce;var b1=(r=>(r.Parent="parent",r))(b1||{});const le=class le extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Loop);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"outputsDeclarations",[]);h(this,"body");h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"currentIterationNumberArgumentDeclaration");h(this,"currentValueArgumentDeclaration",null);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:null,inputs:[],outputs:[],outputsDeclarations:[],process:null,error:null,body:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const T=B(e.parent);i=t.get(T)}const s=B(e.declaration),l=t.get(s),o=e.calledByEntry.map(T=>{const I=B(T);return t.get(I)}),d=e.calledBySuccess.map(T=>{const I=B(T);return t.get(I)}),u=e.calledByError.map(T=>{const I=B(T);return t.get(I)}),f={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:i},c=V(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.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.
|
|
91
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];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),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}):(this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this})}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ce.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);i.push(...u.updated),s.push(...u.removed)}),this.outputs.forEach(d=>{const u=d.remove({ignoreUpstream:!0},t);i.push(...u.updated),s.push(...u.removed)}),this.error){const d=this.error.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.inputs.forEach(o=>{const d=o.restore({},e);i.push(...d.updated)}),this.outputs.forEach(o=>{const d=o.restore({},e);i.push(...d.updated)}),this.error){const o=this.error.restore({},e);i.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((t=this.error)==null?void 0:t.toJSON())||null,inputs:this.inputs.map(s=>s.toJSON()),outputs:this.outputs.map(s=>s.toJSON()),parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((f=this.parent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,error:((s=this.error)==null?void 0:s.toReference(e))||null,inputs:this.inputs.map(o=>o.toReference(e)),outputs:this.outputs.map(o=>o.toReference(e)),parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.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(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e))])}asFunctionDeclarationTransfer(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-function-declaration"))){var d;const i=e||m.UUID.uuid(),s=m.UUID.uuid(),l=this.inputs.map((u,f)=>{var T;const c={id:m.UUID.uuid(),type:n.GenericReference,version:s,entityType:n.FunctionDeclaration,entityId:i};return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:u.name,required:u.required,implements:u.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:u.description,index:f,dataType:((T=u.dataType)==null?void 0:T.toJSONClone({timestamp:(t==null?void 0:t.timestamp)||E().toISOString()}))||null,parent:c}}),o=[];if(this.outputs.length){const u=this.outputs.map((I,D)=>{var C;const P={id:m.UUID.uuid(),type:n.GenericReference,entityId:i,version:s,entityType:n.ReturnStatement};return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:I.name,description:I.description,readsValue:null,constant:!0,required:I.required,defaultValue:null,implements:I.toJSON(),isError:!1,index:D,dataType:((C=I.dataType)==null?void 0:C.toJSONClone())||null,parent:P}}),f={id:m.UUID.uuid(),type:n.GenericReference,version:s,entityType:n.FunctionDeclaration,entityId:i},c={id:m.UUID.uuid(),type:n.GenericReference,version:s,entityType:n.FunctionDeclaration,entityId:i},T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:u,throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[c],parent:f,x:0,y:0};o.push(T)}return t==null||t.attemptAutoclose("implement-as-function-declaration",this.id),{id:i,version:s,createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:l,calls:o,collapsed:!1,private:!1,implements:this.toJSON(),extends:null,index:0,parent:((d=this.parent)==null?void 0:d.toReference())||null,x:0,y:0}}implementAsGlobalEvent(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-global-event")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,implements:this.toJSON(),parent:(s==null?void 0:s.toReference())||null,x:0,y:0},u=V(d,this.project);if(u.setParent(s,e),u.initChildren(e),e==null||e.add(u,A.Added),u.hydrateAncestors(),u.addSelfToProject(e),this.inputs.map((f,c)=>{var C;const T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:f.name,required:f.required,implements:f.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:f.description,index:c,dataType:null,parent:T},D=V(I,this.project);D.setParent(u,e),D.initChildren(e),e==null||e.add(D,A.Added),D.hydrateAncestors(),D.addSelfToProject(e);const P=((C=f.dataType)==null?void 0:C.clone(e,D))||null;P&&(e==null||e.add(P,A.Added)),D.setDataType(P)}),this.outputs.length){const f=m.UUID.uuid(),c=m.UUID.uuid(),T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},I={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.GlobalEvent,entityId:l},D={id:f,version:c,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[I],parent:T,x:0,y:0},P=V(D,this.project);P.setParent(u,e),P.initChildren(e),e==null||e.add(P,A.Added),P.hydrateAncestors(),P.addSelfToProject(e),this.outputs.map((C,M)=>{var S;const G={id:m.UUID.uuid(),type:n.GenericReference,entityId:f,version:c,entityType:n.ReturnStatement},_={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:C.name,description:C.description,readsValue:null,constant:!0,required:C.required,defaultValue:null,implements:C.toJSON(),isError:!1,index:M,dataType:null,parent:G},g=V(_,this.project);g.setParent(P,e),g.initChildren(e),e==null||e.add(g,A.Added),g.hydrateAncestors(),g.addSelfToProject(e);const q=((S=C.dataType)==null?void 0:S.clone(e,g))||null;q&&(e==null||e.add(q,A.Added)),g.setDataType(q)})}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsFunctionDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-function-declaration")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={extends:null,id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:this.name,description:this.description,inputs:[],calls:[],collapsed:!1,private:!1,implements:this.toJSON(),index:0,parent:(s==null?void 0:s.toReference())||null,x:0,y:0},u=V(d,this.project);if(u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),this.inputs.map((f,c)=>{var M,G;const T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:f.name,required:f.required,implements:f.toJSON(),constant:!0,writesValues:[],defaultValue:null,description:f.description,index:c,dataType:null,parent:T},D=V(I,this.project);D.setParent(u,e),D.initChildren(e),e==null||e.add(D,A.Added),D.hydrateAncestors(),D.addSelfToProject(e);const P=((M=f.dataType)==null?void 0:M.clone(e,D))||null;P&&(e==null||e.add(P,A.Added)),D.setDataType(P);const C=((G=f.defaultValue)==null?void 0:G.clone(e,D))||null;C&&(e==null||e.add(C,A.Added)),D.setDataType(P)}),this.outputs.length){const f=m.UUID.uuid(),c=m.UUID.uuid(),T={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},I={id:m.UUID.uuid(),type:n.GenericReference,version:o,entityType:n.FunctionDeclaration,entityId:l},D={id:f,version:c,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,calledBySuccess:[],calledByError:[],calledByEntry:[I],parent:T,x:0,y:0},P=V(D,this.project);P.hydrateAncestors(),P.setParent(u,e),P.addSelfToProject(e),e==null||e.add(P,A.Added),P.initChildren(e)}return e==null||e.attemptAutoclose("implement-as-function-declaration",this.id),u}implementAsLoop(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-loop")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,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:s.toReference()},u=V(d,this.project);return u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),s===this.project&&this.project.addLoop(u),e==null||e.attemptAutoclose("implement-as-loop",this.id),u}implementAsOperation(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-operation")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:this.toJSON(),inputs:[],outputs:[],error:null,process:null,successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:s.toReference()},u=V(d,this.project);return u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),s===this.project&&this.project.addOperation(u),e==null||e.attemptAutoclose("implement-as-operation",this.id),u}implementAsCondition(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-condition")),t,i){const s=t||this.project,l=i||m.UUID.uuid(),o=m.UUID.uuid(),d={id:l,version:o,createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:this.toJSON(),inputs:[],successCalls:[],errorCalls:[],calledByEntry:[],calledByError:[],calledBySuccess:[],x:0,y:0,parent:s.toReference()},u=V(d,this.project);return u.hydrateAncestors(),u.setParent(s,e),e==null||e.add(u,A.Added),u.addSelfToProject(e),u.initChildren(e),s===this.project&&this.project.addCondition(u),e==null||e.attemptAutoclose("implement-as-condition",this.id),u}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=I1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C;if(Array.from(new Set([...Gi(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.outputs=[],d.error=null;const f=u.split("-id"),c=f[f.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const T=st(d,o);e==null||e.add(T,A.Added),t?T.setParent(t,null):this.parent&&T.setParent(this.parent,null),s&&T.subscribe(),T.initChildren(e);const I=(P=this.inputs)==null?void 0:P.map((M,G)=>M.clone(e,T,c+"-argument-value-descriptor-"+G+"-id",s));T.inputs=I;const D=(C=this.outputs)==null?void 0:C.map((M,G)=>M.clone(e,T,c+"-return-value-descriptor-"+G+"-id",s));return T.outputs=D,this.error&&(T.error=this.error.clone(e,T,c+"-error-action-descriptor-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),T}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.find(i=>i.id===e.id)||(this.inputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-input",this.id),this}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){return this.inputs.find(i=>i.id===e.id)&&(this.inputs=this.inputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output",this.id),this}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output",this.id),this}};h(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ce,"type",n.ActionDescriptor),h(Ce,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity,n.DataType]),h(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),h(Ce,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),h(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES]),h(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),h(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),h(Ce,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs"]),h(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let We=Ce;var b1=(r=>(r.Parent="parent",r))(b1||{});const le=class le extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Loop);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"process",null);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"error",null);h(this,"outputsDeclarations",[]);h(this,"body");h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"parent");h(this,"detachedChildren",[]);h(this,"currentIterationNumberArgumentDeclaration");h(this,"currentValueArgumentDeclaration",null);h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:null,inputs:[],outputs:[],outputsDeclarations:[],process:null,error:null,body:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const T=B(e.parent);i=t.get(T)}const s=B(e.declaration),l=t.get(s),o=e.calledByEntry.map(T=>{const I=B(T);return t.get(I)}),d=e.calledBySuccess.map(T=>{const I=B(T);return t.get(I)}),u=e.calledByError.map(T=>{const I=B(T);return t.get(I)}),f={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Loop,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,process:null,errorCalls:[],successCalls:[],inputs:[],outputs:[],body:null,outputsDeclarations:[],error:null,x:0,y:0,parent:i},c=V(f,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0},declaration:{list:!1,types:[n.ActionDescriptor]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.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.
|
|
92
92
|
${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.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.
|
|
93
93
|
${Wl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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.
|
|
94
94
|
${Wl(t)}`,issue:null})),{errors:s,modifiedData:i}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${F(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 '${F(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(){return Te(this.body).filter(i=>i.type===n.ContinueStatement&&i.parent.id===this.id)}get breakStatements(){return Te(this.body).filter(i=>i.type===n.BreakStatement&&i.parent.id===this.id)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
95
95
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
96
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new le(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await le.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await le.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Nc(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.body&&(c.body=this.body.clone(e,c,f+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?He(this.body).filter(i=>i.type===n.VariableInstance):[]}addReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||F(d,this.project)===F(l,this.project)&&Ci(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const f=u.outputs,c=o.filter(T=>!f.find(I=>F(T,this.project)===F(I,this.project)&&Ci(T.dataType,I.dataType)));c.length&&(t.push(u),e==null||e.add(u,A.Updated)),c.forEach(T=>{const I=T.clone(e,u);e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const f=this.getUniqueReturnDeclarations(),c=this.body.inputs;f.sort((P,C)=>P.index-C.index),f.forEach(P=>{const C=P.getDataType(e);let G=c.find(de=>F(de,this.project)===le.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&Ci(de.dataType,P.dataType));if(!G){const de=le.fromReturnDeclarationToBodyArgumentDeclarationName(P),me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:de,description:`Aggretated list of all previously outputted values from each iteration by the output '${F(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},z=V(me,this.project);z.setParent(this.body,e),z.initChildren(e),e==null||e.add(z,A.Added),z.addSelfToProject(e),i.push(z),G=z}const _=this.body.inputs.find(de=>de.index===G.index&&de!==G),g=this.body.inputs.filter(de=>de!==G);let q=G.index;_&&(q=Math.max(...g.map(de=>de.index))+1),G.index!==q&&(G.metaSync({index:q},e),t.push(G));const S=G.getDataType(e);let K=S;if(C)if(!S||!Ci(S,C)){if(!K){const me=C.clone(e,G);e==null||e.add(me,A.Added),me.addSelfToProject(e),K=me,i.push(me),t.push(G)}const de=K.merge(C,e);de.self===K?C.remove({ignoreUpstream:!1},e):de.self===C&&(K.remove({ignoreUpstream:!1},e),K=C),K.metaSync({isList:!0},e)}else K.isList||(K.metaSync({isList:!0},e),t.push(K));if(!C&&!K){const de={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},me=V(de,this.project);me.metaSync({isList:!0},e),me.setParent(G,e),me.initChildren(e),e==null||e.add(me,A.Added),me.addSelfToProject(e),i.push(me)}});const{updated:T,added:I,removed:D}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...T),i.push(...I),s.push(...D),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;return o.forEach((f,c)=>{f.index!==c&&(f.metaSync({index:c},e),t.push(f))}),o.forEach(f=>{const c=f.getDataType(e);let I=d.find(C=>F(C,this.project)===le.fromReturnDeclarationToLoopOutputDeclarationName(f)&&Ci(C.dataType,f.dataType));if(!I){const C=le.fromReturnDeclarationToLoopOutputDeclarationName(f),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:C,description:`Aggretated list of all previously outputted values from each iteration by the output '${F(f,this.project)}'`,defaultValue:null,dataType:null,index:f.index,required:f.required,parentRelationType:L.FixedReturns,parent:this.toReference()},G=V(M,this.project);G.setParent(this,e),G.initChildren(e),e==null||e.add(G,A.Added),G.addSelfToProject(e),i.push(G),I=G}I.index!==f.index&&(I.metaSync({index:f.index},e),t.push(I));let P=I.getDataType(e);if(c)if(!P||!Ci(P,c)){if(!P){const M=c.clone(e,I);e==null||e.add(M,A.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(I)}const C=P.merge(c,e);C.self===P?c.remove({ignoreUpstream:!1},e):C.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const C={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:I.toReference()},M=V(C,this.project);M.metaSync({isList:!0},e),M.setParent(I,e),M.initChildren(e),e==null||e.add(M,A.Added),M.addSelfToProject(e),i.push(M)}}),d.filter(f=>!o.find(T=>F(f,this.project)===le.fromReturnDeclarationToLoopOutputDeclarationName(T))).forEach(f=>{if(!(e!=null&&e.hasRemoved(f.id))&&!f.deleted){const{updated:c,removed:T}=f.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...T)}}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(f=>{var I;let T=d.find(D=>{var P,C;return((P=D.declaration)==null?void 0:P.id)===f.id&&Ci((C=D.declaration)==null?void 0:C.dataType,f.dataType)});if(T)((I=T.declaration)==null?void 0:I.id)!==f.id&&(T.setDeclaration(f),t.push(T));else{const D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:f.index,declaration:f.toJSON(),writesValues:[],parent:this.toReference()},P=V(D,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,A.Added),P.addSelfToProject(e),i.push(P),T=P}T.index!==f.index&&(T.metaSync({index:f.index},e),t.push(T))}),d.filter(f=>!o.find(T=>{var I;return((I=f.declaration)==null?void 0:I.id)===T.id})).forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...T)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(T=>{var I;return T.name===le.CURRENT_ITERATION_NUMBER_ARG_NAME||T.id===((I=this.currentIterationNumberArgumentDeclaration)==null?void 0:I.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},I=V(T,this.project);I.setParent(this.body,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),d=I}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},I=V(T,this.project);I.setParent(d,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),c=I}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==N.Number||c.entity.id!==k["primitive-entity"].number.id){const T=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(T),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(f=>f===this.currentIterationNumberArgumentDeclaration||f===this.currentValueArgumentDeclaration?!1:!d.find(T=>F(f,this.project)===le.fromReturnDeclarationToBodyArgumentDeclarationName(T))).forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...T)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var f,c,T,I,D;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.List].body.inputs.currentValue.id}),C=this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.List].inputs.list.id});if(!C)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][ee.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let g=P.getDataType(e);if(!g){const S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},K=V(S,this.project);K.setParent(G,e),K.initChildren(e),e==null||e.add(K,A.Added),K.addSelfToProject(e),i.push(K),g=K}const q=C.getDataType(e);g.merge(q,e),g.metaSync({isList:!1},e)}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}case ee.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case ee.Counted:{this.currentValueArgumentDeclaration=null;break}case ee.ObjectKeys:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][ee.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let g=P.getDataType(e);if(g){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((f=g.entity)==null?void 0:f.id)!==q.id&&(g.setEntity(q),t.push(g))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},S=V(q,this.project);S.setParent(G,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),g=S}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}case ee.ObjectValues:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.ObjectValues].body.inputs.currentValue.id}),C=this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.ObjectValues].inputs.object.id});if(!C)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][ee.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let g=P.getDataType(e);if(g){const q=C.getDataType(e),S=((T=q==null?void 0:q.entity)==null?void 0:T.properties)||[];(I=g.orChildrenGroup)==null||I.forEach(K=>{const{updated:de,removed:me}=K.remove({ignoreUpstream:!1},e);t.push(...de),s.push(...me)}),S.forEach(K=>{if(!K.getDataType(e)){const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:wt.OrDataTypeGroup,parent:g.toReference()},z=V(me,this.project);z.setParent(g,e),z.initChildren(e),e==null||e.add(z,A.Added),z.addSelfToProject(e),i.push(z)}})}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},S=V(q,this.project);S.setParent(G,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),g=S;const K=C.getDataType(e);(((c=K==null?void 0:K.entity)==null?void 0:c.properties)||[]).forEach(me=>{if(!me.getDataType(e)){const oe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:wt.OrDataTypeGroup,parent:S.toReference()},Ft=V(oe,this.project);Ft.setParent(S,e),Ft.initChildren(e),e==null||e.add(Ft,A.Added),Ft.addSelfToProject(e),i.push(Ft)}})}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}case ee.String:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.String].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let g=P.getDataType(e);if(g){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((D=g.entity)==null?void 0:D.id)!==q.id&&(g.setEntity(q),t.push(g))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},S=V(q,this.project);S.setParent(G,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),i.push(S),g=S}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:f,added:c,removed:T}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...f),i.push(...c),s.push(...T),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case ee.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const f={extends:null,id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=V(f,this.project);c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:f,added:c,removed:T}=this.syncInputMaps(e);t.push(...f),i.push(...c),s.push(...T);const{updated:I,added:D,removed:P}=this.syncTerminationStatements(e);t.push(...I),i.push(...D),s.push(...P);const{updated:C,added:M,removed:G}=this.syncBodyArgumentsDeclarations(e);t.push(...C),i.push(...M),s.push(...G);const{updated:_,added:g,removed:q}=this.syncBodyInputIndexes(e);t.push(..._),i.push(...g),s.push(...q);const{updated:S,added:K,removed:de}=this.syncOutputsDeclarations(e);t.push(...S),i.push(...K),s.push(...de);const{updated:me,added:z,removed:oe}=this.syncOutputMaps(e);return t.push(...me),i.push(...z),s.push(...oe),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};h(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,...i)=>null}),h(le,"type",n.Loop),h(le,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(le,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),h(le,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),h(le,"CURRENT_VALUE_ARG_NAME","Current value"),h(le,"MUTABLE_BASE_PROPERTIES",[]),h(le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(le,"BASE_PROPERTIES",[...le.MUTABLE_BASE_PROPERTIES,...le.INMUTABLE_BASE_PROPERTIES]),h(le,"MUTABLE_META_PROPERTIES",[...le.MUTABLE_BASE_PROPERTIES,"x","y"]),h(le,"INMUTABLE_META_PROPERTIES",[...le.INMUTABLE_BASE_PROPERTIES]),h(le,"META_PROPERTIES",[...le.MUTABLE_META_PROPERTIES,...le.INMUTABLE_META_PROPERTIES]),h(le,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(le,"UPSTREAM_PROPERTIES",[...le.MUTABLE_UPSTREAM_PROPERTIES,...le.INMUTABLE_UPSTREAM_PROPERTIES]),h(le,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),h(le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(le,"DOWNSTREAM_PROPERTIES",[...le.MUTABLE_DOWNSTREAM_PROPERTIES,...le.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(le,"PROPERTIES",[...le.META_PROPERTIES,...le.UPSTREAM_PROPERTIES,...le.DOWNSTREAM_PROPERTIES]);let Sr=le;function R1(r){const a=z5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...Rr(r)];return Ke(r.errors,s)}const HJ=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"}));var D1=(r=>(r.Parent="parent",r))(D1||{});const ke=class ke extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Condition);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"declaration");h(this,"inputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=B(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),l=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),o=e.calledByError.map(c=>{const T=B(c);return t.get(T)});let d;if(e.declaration){const c=B(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},f=V(u,t);return f.setParent(i,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.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.
|
|
96
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new le(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await le.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await le.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Nc(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.body&&(c.body=this.body.clone(e,c,f+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?He(this.body).filter(i=>i.type===n.VariableInstance):[]}addReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return rt.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||F(d,this.project)===F(l,this.project)&&Ci(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const f=u.outputs,c=o.filter(T=>!f.find(I=>F(T,this.project)===F(I,this.project)&&Ci(T.dataType,I.dataType)));c.length&&(t.push(u),e==null||e.add(u,A.Updated)),c.forEach(T=>{const I=T.clone(e,u);e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const f=this.getUniqueReturnDeclarations(),c=this.body.inputs;f.sort((P,C)=>P.index-C.index),f.forEach(P=>{const C=P.getDataType(e);let G=c.find(de=>F(de,this.project)===le.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&Ci(de.dataType,P.dataType));if(!G){const de=le.fromReturnDeclarationToBodyArgumentDeclarationName(P),me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:de,description:`Aggretated list of all previously outputted values from each iteration by the output '${F(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},z=V(me,this.project);z.setParent(this.body,e),z.initChildren(e),e==null||e.add(z,A.Added),z.addSelfToProject(e),i.push(z),G=z}const _=this.body.inputs.find(de=>de.index===G.index&&de!==G),g=this.body.inputs.filter(de=>de!==G);let q=G.index;_&&(q=Math.max(...g.map(de=>de.index))+1),G.index!==q&&(G.metaSync({index:q},e),t.push(G));const S=G.getDataType(e);let K=S;if(C)if(!S||!Ci(S,C)){if(!K){const me=C.clone(e,G);e==null||e.add(me,A.Added),me.addSelfToProject(e),K=me,i.push(me),t.push(G)}const de=K.merge(C,e);de.self===K?C.remove({ignoreUpstream:!1},e):de.self===C&&(K.remove({ignoreUpstream:!1},e),K=C),K.metaSync({isList:!0},e)}else K.isList||(K.metaSync({isList:!0},e),t.push(K));if(!C&&!K){const de={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},me=V(de,this.project);me.metaSync({isList:!0},e),me.setParent(G,e),me.initChildren(e),e==null||e.add(me,A.Added),me.addSelfToProject(e),i.push(me)}});const{updated:T,added:I,removed:D}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...T),i.push(...I),s.push(...D),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;return o.forEach((f,c)=>{f.index!==c&&(f.metaSync({index:c},e),t.push(f))}),o.forEach(f=>{const c=f.getDataType(e);let I=d.find(C=>F(C,this.project)===le.fromReturnDeclarationToLoopOutputDeclarationName(f)&&Ci(C.dataType,f.dataType));if(!I){const C=le.fromReturnDeclarationToLoopOutputDeclarationName(f),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:C,description:`Aggretated list of all previously outputted values from each iteration by the output '${F(f,this.project)}'`,defaultValue:null,dataType:null,index:f.index,required:f.required,parentRelationType:L.FixedReturns,parent:this.toReference()},G=V(M,this.project);G.setParent(this,e),G.initChildren(e),e==null||e.add(G,A.Added),G.addSelfToProject(e),i.push(G),I=G}I.index!==f.index&&(I.metaSync({index:f.index},e),t.push(I));let P=I.getDataType(e);if(c)if(!P||!Ci(P,c)){if(!P){const M=c.clone(e,I);e==null||e.add(M,A.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(I)}const C=P.merge(c,e);C.self===P?c.remove({ignoreUpstream:!1},e):C.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const C={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:I.toReference()},M=V(C,this.project);M.metaSync({isList:!0},e),M.setParent(I,e),M.initChildren(e),e==null||e.add(M,A.Added),M.addSelfToProject(e),i.push(M)}}),d.filter(f=>!o.find(T=>F(f,this.project)===le.fromReturnDeclarationToLoopOutputDeclarationName(T))).forEach(f=>{if(!(e!=null&&e.hasRemoved(f.id))&&!f.deleted){const{updated:c,removed:T}=f.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...T)}}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(f=>{var I;let T=d.find(D=>{var P,C;return((P=D.declaration)==null?void 0:P.id)===f.id&&Ci((C=D.declaration)==null?void 0:C.dataType,f.dataType)});if(T)((I=T.declaration)==null?void 0:I.id)!==f.id&&(T.setDeclaration(f),t.push(T));else{const D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:f.index,declaration:f.toJSON(),writesValues:[],parent:this.toReference()},P=V(D,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,A.Added),P.addSelfToProject(e),i.push(P),T=P}T.index!==f.index&&(T.metaSync({index:f.index},e),t.push(T))}),d.filter(f=>!o.find(T=>{var I;return((I=f.declaration)==null?void 0:I.id)===T.id})).forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...T)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(T=>{var I;return T.name===le.CURRENT_ITERATION_NUMBER_ARG_NAME||T.id===((I=this.currentIterationNumberArgumentDeclaration)==null?void 0:I.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},I=V(T,this.project);I.setParent(this.body,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),d=I}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},I=V(T,this.project);I.setParent(d,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I),c=I}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==N.Number||c.entity.id!==k["primitive-entity"].number.id){const T=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(T),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(f=>f===this.currentIterationNumberArgumentDeclaration||f===this.currentValueArgumentDeclaration?!1:!d.find(T=>F(f,this.project)===le.fromReturnDeclarationToBodyArgumentDeclarationName(T))).forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...T)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var f,c,T,I,D;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.List].body.inputs.currentValue.id}),C=this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.List].inputs.list.id});if(!C)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][ee.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let g=P.getDataType(e);if(!g){const S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},K=V(S,this.project);K.setParent(G,e),K.initChildren(e),e==null||e.add(K,A.Added),K.addSelfToProject(e),i.push(K),g=K}const q=C.getDataType(e);g.merge(q,e),g.metaSync({isList:!1},e)}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}case ee.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case ee.Counted:{this.currentValueArgumentDeclaration=null;break}case ee.ObjectKeys:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][ee.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let g=P.getDataType(e);if(g){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((f=g.entity)==null?void 0:f.id)!==q.id&&(g.setEntity(q),t.push(g))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},S=V(q,this.project);S.setParent(G,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),g=S}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}case ee.ObjectValues:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.ObjectValues].body.inputs.currentValue.id}),C=this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.ObjectValues].inputs.object.id});if(!C)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][ee.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let g=P.getDataType(e);if(g){const q=C.getDataType(e),S=((T=q==null?void 0:q.entity)==null?void 0:T.properties)||[];(I=g.orChildrenGroup)==null||I.forEach(K=>{const{updated:de,removed:me}=K.remove({ignoreUpstream:!1},e);t.push(...de),s.push(...me)}),S.forEach(K=>{if(!K.getDataType(e)){const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:wt.OrDataTypeGroup,parent:g.toReference()},z=V(me,this.project);z.setParent(g,e),z.initChildren(e),e==null||e.add(z,A.Added),z.addSelfToProject(e),i.push(z)}})}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},S=V(q,this.project);S.setParent(G,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),g=S;const K=C.getDataType(e);(((c=K==null?void 0:K.entity)==null?void 0:c.properties)||[]).forEach(me=>{if(!me.getDataType(e)){const oe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:wt.OrDataTypeGroup,parent:S.toReference()},Ft=V(oe,this.project);Ft.setParent(S,e),Ft.initChildren(e),e==null||e.add(Ft,A.Added),Ft.addSelfToProject(e),i.push(Ft)}})}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}case ee.String:{const P=this.body.inputs.find(G=>{var _;return((_=G.implements)==null?void 0:_.id)===k[n.Loop][ee.String].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var _;return((_=G.declaration)==null?void 0:_.id)===k[n.Loop][ee.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let g=P.getDataType(e);if(g){const q=this.project.getBuiltIn(k["primitive-entity"].string.id);((D=g.entity)==null?void 0:D.id)!==q.id&&(g.setEntity(q),t.push(g))}else{const q={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},S=V(q,this.project);S.setParent(G,e),S.initChildren(e),e==null||e.add(S,A.Added),S.addSelfToProject(e),i.push(S),g=S}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:le.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},_=V(G,this.project);_.setParent(this.body,e),_.initChildren(e),e==null||e.add(_,A.Added),_.addSelfToProject(e),M&&(!_.implements||_.implements.id!==M.id)&&(_.setImplements(M,e),t.push(_)),i.push(_),this.currentValueArgumentDeclaration=_}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:f,added:c,removed:T}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...f),i.push(...c),s.push(...T),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case ee.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case ee.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}case ee.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),i.push(f)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const f={extends:null,id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=V(f,this.project);c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:f,added:c,removed:T}=this.syncInputMaps(e);t.push(...f),i.push(...c),s.push(...T);const{updated:I,added:D,removed:P}=this.syncTerminationStatements(e);t.push(...I),i.push(...D),s.push(...P);const{updated:C,added:M,removed:G}=this.syncBodyArgumentsDeclarations(e);t.push(...C),i.push(...M),s.push(...G);const{updated:_,added:g,removed:q}=this.syncBodyInputIndexes(e);t.push(..._),i.push(...g),s.push(...q);const{updated:S,added:K,removed:de}=this.syncOutputsDeclarations(e);t.push(...S),i.push(...K),s.push(...de);const{updated:me,added:z,removed:oe}=this.syncOutputMaps(e);return t.push(...me),i.push(...z),s.push(...oe),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};h(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,...i)=>null}),h(le,"type",n.Loop),h(le,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(le,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),h(le,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),h(le,"CURRENT_VALUE_ARG_NAME","Current value"),h(le,"MUTABLE_BASE_PROPERTIES",[]),h(le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(le,"BASE_PROPERTIES",[...le.MUTABLE_BASE_PROPERTIES,...le.INMUTABLE_BASE_PROPERTIES]),h(le,"MUTABLE_META_PROPERTIES",[...le.MUTABLE_BASE_PROPERTIES,"x","y"]),h(le,"INMUTABLE_META_PROPERTIES",[...le.INMUTABLE_BASE_PROPERTIES]),h(le,"META_PROPERTIES",[...le.MUTABLE_META_PROPERTIES,...le.INMUTABLE_META_PROPERTIES]),h(le,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(le,"UPSTREAM_PROPERTIES",[...le.MUTABLE_UPSTREAM_PROPERTIES,...le.INMUTABLE_UPSTREAM_PROPERTIES]),h(le,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),h(le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(le,"DOWNSTREAM_PROPERTIES",[...le.MUTABLE_DOWNSTREAM_PROPERTIES,...le.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(le,"PROPERTIES",[...le.META_PROPERTIES,...le.UPSTREAM_PROPERTIES,...le.DOWNSTREAM_PROPERTIES]);let Sr=le;function R1(r){const a=z5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...Rr(r)];return Ke(r.errors,s)}const HJ=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"}));var D1=(r=>(r.Parent="parent",r))(D1||{});const ke=class ke extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.Condition);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"declaration");h(this,"inputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=B(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),l=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),o=e.calledByError.map(c=>{const T=B(c);return t.get(T)});let d;if(e.declaration){const c=B(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},f=V(u,t);return f.setParent(i,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.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.
|
|
97
97
|
${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.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.
|
|
98
98
|
${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.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.
|
|
99
99
|
${Sl(t)}`,issue:null})),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
100
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await ke.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),this.parent.type===n.Project&&this.project.addCondition(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=R1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.inputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-input-map-"+P+"-id",s));return c.inputs=T,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===L.FixedArguments&&!this.inputs.find(T=>T.declaration.id===c.id));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(ke,"type",n.Condition),h(ke,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),h(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),h(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"MUTABLE_META_PROPERTIES",["x","y"]),h(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),h(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),h(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),h(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let zr=ke;function O1(r){var o;const a=NZ(),e=r.toJSON();a.safeParse(e).success,(o=r.dataType)==null||o.validate(),r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),r.internalCalls.forEach(d=>d.validate());const s=[...Rr(r)];if(r.id==="random-company-employee-test-variable-id"){const d=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=qc(r);return s.push(...l),Ke(r.errors,s)}const KJ=Object.freeze(Object.defineProperty({__proto__:null,validate:O1},Symbol.toStringTag,{value:"Module"}));function P1(r){const a=GZ(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),r.internalCalls.forEach(o=>o.validate());const s=[...Rr(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=qc(r);return s.push(...l),Ke(r.errors,s)}const XJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"}));var Lc=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(Lc||{});const Ve=class Ve extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.VariableInstance);h(this,"defaultValue",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const I=B(e.parent);i=t.get(I)}const s=B(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const D=B(I);return t.get(D)}),d=e.calledBySuccess.map(I=>{const D=B(I);return t.get(D)}),u=e.calledByError.map(I=>{const D=B(I);return t.get(D)});let f=null;if(e.readsValue){const I=B(e.readsValue);f=t.get(I)}const c={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:f,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},T=V(c,t);return T.setParent(i,null),T.initChildren(null),T}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=ja(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
100
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${_t(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${_t(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await ke.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),this.parent.type===n.Project&&this.project.addCondition(this),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=R1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.inputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-input-map-"+P+"-id",s));return c.inputs=T,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===L.FixedArguments&&!this.inputs.find(T=>T.declaration.id===c.id));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(ke,"type",n.Condition),h(ke,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),h(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),h(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"MUTABLE_META_PROPERTIES",["x","y"]),h(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),h(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),h(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),h(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),h(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let zr=ke;function O1(r){var o;const a=NZ(),e=r.toJSON();a.safeParse(e).success,(o=r.dataType)==null||o.validate(),r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),r.internalCalls.forEach(d=>d.validate());const s=[...Rr(r)];if(r.id==="random-company-employee-test-variable-id"){const d=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=qc(r);return s.push(...l),Ke(r.errors,s)}const KJ=Object.freeze(Object.defineProperty({__proto__:null,validate:O1},Symbol.toStringTag,{value:"Module"}));function P1(r){const a=GZ(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),r.internalCalls.forEach(o=>o.validate());const s=[...Rr(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=qc(r);return s.push(...l),Ke(r.errors,s)}const XJ=Object.freeze(Object.defineProperty({__proto__:null,validate:P1},Symbol.toStringTag,{value:"Module"}));var Lc=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(Lc||{});const Ve=class Ve extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.VariableInstance);h(this,"defaultValue",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"declaration");h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const I=B(e.parent);i=t.get(I)}const s=B(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const D=B(I);return t.get(D)}),d=e.calledBySuccess.map(I=>{const D=B(I);return t.get(D)}),u=e.calledByError.map(I=>{const D=B(I);return t.get(D)});let f=null;if(e.readsValue){const I=B(e.readsValue);f=t.get(I)}const c={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:f,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},T=V(c,t);return T.setParent(i,null),T.initChildren(null),T}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=ja(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
101
101
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
102
102
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
103
|
-
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.parent)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"parent"}]),(l=(s=(i=this.declaration.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),(d=(o=this.declaration)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){var _;const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:T,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...T),s.push(...I),l.push(...D);const{added:P,updated:C,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...C),s.push(...M),l.push(...G),!this.declaration.dataType||(_=this.declaration.dataType)!=null&&_.inferred){const{added:g,updated:q,removed:S,affected:K}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...g),t.push(...q),s.push(...S),l.push(...K)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(i=>!(e.find(o=>o.id===i.id)||e.find(o=>o.declaration===i.declaration)))}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 qa.initWritesValues(this,this.parent),Or.initReadsValue(this),this.initialData.inputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,e),i}),this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.internalCalls=this.initialData.internalCalls.reduce((t,i)=>{if(i.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(i);if(!s)return t;const l=s;return l.setParent(this,null),[...t,l]}else{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(e),[...t,s]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e))])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(s=>s.toFlatIds(e)),...this.successCalls.flatMap(s=>s.toFlatIds(e)),...this.errorCalls.flatMap(s=>s.toFlatIds(e)),...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.outputs.flatMap(s=>s.toFlatIds(e)),...this.internalCalls.flatMap(s=>s.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((i=this.readsValue)==null?void 0:i.toReference())||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),internalCalls:this.internalCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((f=this.readsValue)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.declaration)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e)),...this.calledBy.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.declaration)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.readsValue)==null?void 0:l.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=P1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(s=>s.getErrors()),...this.internalCalls.flatMap(s=>s.getErrors()),...this.outputs.flatMap(s=>s.getErrors()),...((i=this.readsValue)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P,C,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(D=this.defaultValue)==null?void 0:D.clone(e,u,m.UUID.uuid(),s);u.defaultValue=f||null;const c=(P=this.inputs)==null?void 0:P.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const T=(C=this.outputs)==null?void 0:C.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=T;const I=(M=this.internalCalls)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=I,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const T=this.inputs.find(P=>F(P,this.project)===F(c,this.project));if(!T)return;const I=this.declaration.getMasterInputWithValueWritterFromAllInstances(T);if(!I)return;const D=$i(I);c.setDataType(D),T.setDeclaration(c)}),o.filter(c=>!this.inputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=V(T,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const T=o.find(I=>F(I,this.project)===F(c,this.project));T&&c.setDeclaration(T)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(u=>!this.outputs.find(f=>f.declaration===u)).map(u=>{const f={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=V(f,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,D,P,C,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.declaration)==null?void 0:P.entityId)||((M=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:M.id))===u.id})).map(u=>{const f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)}};h(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ve,"type",n.VariableInstance),h(Ve,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),h(Ve,"MUTABLE_BASE_PROPERTIES",[]),h(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),h(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),h(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),h(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Yr=Ve;var w1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(w1||{});const _e=class _e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"required",!1);h(this,"constant",!1);h(this,"x");h(this,"y");h(this,"type",n.VariableDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:"",description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=B(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),l=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),o=e.calledByError.map(c=>{const T=B(c);return t.get(T)});let d=null;if(e.readsValue){const c=B(e.readsValue);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:s,calledBySuccess:l,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},f=V(u,t);return f.setParent(i,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData;const o=Oc(i,t);return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Lc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=ja(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l,o,d;return(t=(e=this.parent)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"parent"}]),(l=(s=(i=this.declaration.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),(d=(o=this.declaration)==null?void 0:o.unsubscribeDependents)==null||d.call(o,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){var _;const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:T,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...T),s.push(...I),l.push(...D);const{added:P,updated:C,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...C),s.push(...M),l.push(...G),!this.declaration.dataType||(_=this.declaration.dataType)!=null&&_.inferred){const{added:g,updated:q,removed:S,affected:K}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...g),t.push(...q),s.push(...S),l.push(...K)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(i=>!(e.find(o=>o.id===i.id)||e.find(o=>o.declaration===i.declaration)))}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 qa.initWritesValues(this,this.parent),Or.initReadsValue(this),this.initialData.inputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,e),i}),this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.internalCalls=this.initialData.internalCalls.reduce((t,i)=>{if(i.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(i);if(!s)return t;const l=s;return l.setParent(this,null),[...t,l]}else{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(e),[...t,s]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e))])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(s=>s.toFlatIds(e)),...this.successCalls.flatMap(s=>s.toFlatIds(e)),...this.errorCalls.flatMap(s=>s.toFlatIds(e)),...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.outputs.flatMap(s=>s.toFlatIds(e)),...this.internalCalls.flatMap(s=>s.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((i=this.readsValue)==null?void 0:i.toReference())||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),internalCalls:this.internalCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((f=this.readsValue)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.declaration)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e)),...this.calledBy.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.declaration)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.readsValue)==null?void 0:l.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=P1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(s=>s.getErrors()),...this.internalCalls.flatMap(s=>s.getErrors()),...this.outputs.flatMap(s=>s.getErrors()),...((i=this.readsValue)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P,C,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(D=this.defaultValue)==null?void 0:D.clone(e,u,m.UUID.uuid(),s);u.defaultValue=f||null;const c=(P=this.inputs)==null?void 0:P.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const T=(C=this.outputs)==null?void 0:C.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=T;const I=(M=this.internalCalls)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=I,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const T=this.inputs.find(P=>F(P,this.project)===F(c,this.project));if(!T)return;const I=this.declaration.getMasterInputWithValueWritterFromAllInstances(T);if(!I)return;const D=$i(I);c.setDataType(D),T.setDeclaration(c)}),o.filter(c=>!this.inputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=V(T,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const T=o.find(I=>F(I,this.project)===F(c,this.project));T&&c.setDeclaration(T)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(u=>!this.outputs.find(f=>f.declaration===u)).map(u=>{const f={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=V(f,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,D,P,C,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.declaration)==null?void 0:P.entityId)||((M=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:M.id))===u.id})).map(u=>{const f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)}};h(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ve,"type",n.VariableInstance),h(Ve,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),h(Ve,"MUTABLE_BASE_PROPERTIES",[]),h(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),h(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),h(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),h(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let Yr=Ve;var w1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(w1||{});const _e=class _e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"required",!1);h(this,"constant",!1);h(this,"x");h(this,"y");h(this,"type",n.VariableDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"readsValue",null);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"internalCalls",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:"",description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=B(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),l=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),o=e.calledByError.map(c=>{const T=B(c);return t.get(T)});let d=null;if(e.readsValue){const c=B(e.readsValue);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:s,calledBySuccess:l,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},f=V(u,t);return f.setParent(i,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);i=l.modifiedData;const o=Oc(i,t);return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Lc.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=ja(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
104
104
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
105
105
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
106
|
-
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:T,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...T),s.push(...I),l.push(...D);const{added:P,updated:C,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...C),s.push(...M),l.push(...G),!this.dataType||this.dataType.inferred){const{added:_,updated:g,removed:q,affected:S}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(..._),t.push(...g),s.push(...q),l.push(...S)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)),qa.initWritesValues(this,this.parent),Or.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.initialData.inputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>F(s,this.project)===F(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,G,_,g;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=V({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,A.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const S=(G=this.dataType)==null?void 0:G.merge(q,e);this.dataType&&(S==null?void 0:S.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((_=S==null?void 0:S.self)==null?void 0:_.id)&&q.remove({ignoreUpstream:!1},e),S!=null&&S.self&&(S.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(S.self,A.Added),this.setDataType(S.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(K=>F(K,this.project)===F(q,this.project))||d.push(q)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if((g=this.dataType)==null||g.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:f,removed:c,affected:T}=this.generateUnusedInputs(e);t.push(...f),i.push(...u),s.push(...c),l.push(...T);const{updated:I,added:D,removed:P,affected:C}=this.generateUnusedOutputs(e);return t.push(...D),i.push(...I),s.push(...P),l.push(...C),this.variableInstances.forEach(q=>{const{updated:S,added:K,removed:de,affected:me}=q.generateUnusedInputs(e);t.push(...K),i.push(...S),s.push(...de),l.push(...me);const{updated:z,added:oe,removed:Ft,affected:nr}=q.generateUnusedOutputs(e);t.push(...oe),i.push(...z),s.push(...Ft),l.push(...nr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await _e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=W){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(T=>T.toJSONClone({...e,newId:null})),inputs:this.inputs.map(T=>T.toJSONClone({...e,newId:null})),outputs:this.outputs.map(T=>T.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(T=>T.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(T=>T.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(T=>this.calledBy.length||this.readsValue?T.toJSONClone({...e,newId:null}):T.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(T=>T.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(T=>T.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(T=>T.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=O1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C,M,G,_;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(C=this.defaultValue)==null?void 0:C.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const T=(M=this.inputs)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=T;const I=(G=this.outputs)==null?void 0:G.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const D=(_=this.internalCalls)==null?void 0:_.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=D,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toReference(),x:0,y:0},l=V(s,this.project);return l.hydrateAncestors(),l.setParent(e,t),t==null||t.add(l,A.Added),l.addSelfToProject(t),l.initChildren(t),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const T=this.inputs.find(P=>F(P,this.project)===F(c,this.project));if(!T)return;const I=this.getMasterInputWithValueWritterFromAllInstances(T);if(!I)return;const D=$i(I);c.setDataType(D),T.setDeclaration(c)}),o.filter(c=>!this.inputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=V(T,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const T=o.find(I=>F(I,this.project)===F(c,this.project));T&&c.setDeclaration(T)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(f=>f.declaration===u)).map(u=>{const f={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=V(f,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,D,P,C,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.declaration)==null?void 0:P.entityId)||((M=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:M.id))===u.id})).map(u=>{const f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)}};h(_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,...i)=>null}),h(_e,"type",n.VariableDeclaration),h(_e,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),h(_e,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),h(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"x","y"]),h(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),h(_e,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),h(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),h(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Hr=_e;function C1(r){var l;const a=X5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Rr(r)];return Ke(r.errors,s)}const QJ=Object.freeze(Object.defineProperty({__proto__:null,validate:C1},Symbol.toStringTag,{value:"Module"}));var V1=(r=>(r.Parent="parent",r))(V1||{});const Se=class Se extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"query","");h(this,"type",n.Search);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"inputsDeclarations",[]);h(this,"inputs",[]);h(this,"outputsDeclarations",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"error",null);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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,this.onPersistedEntityAdded=this.onPersistedEntityAdded.bind(this),this.onPersistedEntityRemoved=this.onPersistedEntityRemoved.bind(this),this.onRelationalDatabaseEntityAdded=this.onRelationalDatabaseEntityAdded.bind(this),this.onRelationalDatabaseEntityRemoved=this.onRelationalDatabaseEntityRemoved.bind(this)}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const f=B(e.parent);i=t.get(f)}const s=e.calledByEntry.map(f=>{const c=B(f);return t.get(c)}),l=e.calledBySuccess.map(f=>{const c=B(f);return t.get(c)}),o=e.calledByError.map(f=>{const c=B(f);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=V(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}onPersistedEntityAdded(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-persisted-entity-added"))){return t==null||t.attemptAutoclose("on-persisted-entity-added",this.id),this}onPersistedEntityRemoved(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-persisted-entity-removed"))){return t==null||t.attemptAutoclose("on-persisted-entity-removed",this.id),this}onRelationalDatabaseEntityAdded(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-relational-database-entity-added"))){return t==null||t.attemptAutoclose("on-relational-database-entity-added",this.id),this}onRelationalDatabaseEntityRemoved(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-relational-database-entity-removed"))){return t==null||t.attemptAutoclose("on-relational-database-entity-removed",this.id),this}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
106
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.unsubscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{added:o,updated:d,removed:u,affected:f}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...f);const{added:c,updated:T,removed:I,affected:D}=this.generateUnusedOutputs(e);i.push(...c),t.push(...T),s.push(...I),l.push(...D);const{added:P,updated:C,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...C),s.push(...M),l.push(...G),!this.dataType||this.dataType.inferred){const{added:_,updated:g,removed:q,affected:S}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(..._),t.push(...g),s.push(...q),l.push(...S)}return this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)),qa.initWritesValues(this,this.parent),Or.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.initialData.inputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>F(s,this.project)===F(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,G,_,g;const t=[],i=[],s=[],l=[];if(!this.dataType){const q=V({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:!1,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(q),q.setParent(this,e),q.initChildren(e),e==null||e.add(q,A.Added),q.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const q=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(q){const S=(G=this.dataType)==null?void 0:G.merge(q,e);this.dataType&&(S==null?void 0:S.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),q.id!==((_=S==null?void 0:S.self)==null?void 0:_.id)&&q.remove({ignoreUpstream:!1},e),S!=null&&S.self&&(S.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(S.self,A.Added),this.setDataType(S.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(q=>q.inputs)]),d=[];if(o.forEach(q=>{d.find(K=>F(K,this.project)===F(q,this.project))||d.push(q)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if((g=this.dataType)==null||g.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:f,removed:c,affected:T}=this.generateUnusedInputs(e);t.push(...f),i.push(...u),s.push(...c),l.push(...T);const{updated:I,added:D,removed:P,affected:C}=this.generateUnusedOutputs(e);return t.push(...D),i.push(...I),s.push(...P),l.push(...C),this.variableInstances.forEach(q=>{const{updated:S,added:K,removed:de,affected:me}=q.generateUnusedInputs(e);t.push(...K),i.push(...S),s.push(...de),l.push(...me);const{updated:z,added:oe,removed:Ft,affected:nr}=q.generateUnusedOutputs(e);t.push(...oe),i.push(...z),s.push(...Ft),l.push(...nr)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await _e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=W){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(T=>T.toJSONClone({...e,newId:null})),inputs:this.inputs.map(T=>T.toJSONClone({...e,newId:null})),outputs:this.outputs.map(T=>T.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(T=>T.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(T=>T.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(T=>this.calledBy.length||this.readsValue?T.toJSONClone({...e,newId:null}):T.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(T=>T.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(T=>T.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(T=>T.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=O1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C,M,G,_;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(C=this.defaultValue)==null?void 0:C.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const T=(M=this.inputs)==null?void 0:M.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.inputs=T;const I=(G=this.outputs)==null?void 0:G.map(g=>g.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const D=(_=this.internalCalls)==null?void 0:_.map(g=>g.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=D,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toReference(),x:0,y:0},l=V(s,this.project);return l.hydrateAncestors(),l.setParent(e,t),t==null||t.add(l,A.Added),l.addSelfToProject(t),l.initChildren(t),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const T=this.inputs.find(P=>F(P,this.project)===F(c,this.project));if(!T)return;const I=this.getMasterInputWithValueWritterFromAllInstances(T);if(!I)return;const D=$i(I);c.setDataType(D),T.setDeclaration(c)}),o.filter(c=>!this.inputs.find(T=>{var I;return((I=T.declaration)==null?void 0:I.id)===c.id})).forEach(c=>{const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},I=V(T,this.project);return I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.suggestion=!0,this.addInput(I,e),I}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const T=o.find(I=>F(I,this.project)===F(c,this.project));T&&c.setDeclaration(T)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(f=>f.declaration===u)).map(u=>{const f={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=V(f,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var I,D,P,C,M;return(((I=c.declaration)==null?void 0:I.id)||((P=(D=c.initialData)==null?void 0:D.declaration)==null?void 0:P.entityId)||((M=(C=c.initialData)==null?void 0:C.declaration)==null?void 0:M.id))===u.id})).map(u=>{const f=u.createInternalCall(e,this);return e==null||e.add(f,A.Added),f.suggestion=!0,this.addInternalCall(f),f});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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)}};h(_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,...i)=>null}),h(_e,"type",n.VariableDeclaration),h(_e,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),h(_e,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),h(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"x","y"]),h(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),h(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),h(_e,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),h(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),h(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),h(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),h(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Hr=_e;function C1(r){var l;const a=X5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...Rr(r)];return Ke(r.errors,s)}const QJ=Object.freeze(Object.defineProperty({__proto__:null,validate:C1},Symbol.toStringTag,{value:"Module"}));var V1=(r=>(r.Parent="parent",r))(V1||{});const Se=class Se extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"query","");h(this,"type",n.Search);h(this,"successCalls",[]);h(this,"errorCalls",[]);h(this,"inputsDeclarations",[]);h(this,"inputs",[]);h(this,"outputsDeclarations",[]);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"error",null);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(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,this.onPersistedEntityAdded=this.onPersistedEntityAdded.bind(this),this.onPersistedEntityRemoved=this.onPersistedEntityRemoved.bind(this),this.onRelationalDatabaseEntityAdded=this.onRelationalDatabaseEntityAdded.bind(this),this.onRelationalDatabaseEntityRemoved=this.onRelationalDatabaseEntityRemoved.bind(this)}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const f=B(e.parent);i=t.get(f)}const s=e.calledByEntry.map(f=>{const c=B(f);return t.get(c)}),l=e.calledBySuccess.map(f=>{const c=B(f);return t.get(c)}),o=e.calledByError.map(f=>{const c=B(f);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=V(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...ht,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}onPersistedEntityAdded(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-persisted-entity-added"))){return t==null||t.attemptAutoclose("on-persisted-entity-added",this.id),this}onPersistedEntityRemoved(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-persisted-entity-removed"))){return t==null||t.attemptAutoclose("on-persisted-entity-removed",this.id),this}onRelationalDatabaseEntityAdded(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-relational-database-entity-added"))){return t==null||t.attemptAutoclose("on-relational-database-entity-added",this.id),this}onRelationalDatabaseEntityRemoved(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,new Date().toISOString(),this,!0,"on-relational-database-entity-removed"))){return t==null||t.attemptAutoclose("on-relational-database-entity-removed",this.id),this}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this.project.off(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,this.onPersistedEntityAdded),this.project.off(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,this.onPersistedEntityRemoved),this.project.off(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,this.onRelationalDatabaseEntityAdded),this.project.off(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,this.onRelationalDatabaseEntityRemoved),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.project.on(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,this.onPersistedEntityAdded),this.project.on(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,this.onPersistedEntityRemoved),this.project.on(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,this.onRelationalDatabaseEntityAdded),this.project.on(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,this.onRelationalDatabaseEntityRemoved),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Se(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,A.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Se.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(f=>f.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(f=>f.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),inputs:this.inputs.map(f=>f.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),outputs:this.outputs.map(f=>f.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=C1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var C,M,G,_;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(C=this.inputsDeclarations)==null?void 0:C.map((g,q)=>g.clone(e,this,f+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=T;const I=(M=this.outputsDeclarations)==null?void 0:M.map((g,q)=>g.clone(e,this,f+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const D=(G=this.inputs)==null?void 0:G.map((g,q)=>g.clone(e,c,f+"-input-map-"+q+"-id",s));c.inputs=D;const P=(_=this.outputs)==null?void 0:_.map((g,q)=>g.clone(e,c,f+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var f;return((f=u.declaration)==null?void 0:f.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),t.push(this),i.push(f)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const{updated:u,removed:f}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...f)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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,...i)=>null}),h(Se,"type",n.Search),h(Se,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),h(Se,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),h(Se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"MUTABLE_META_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),h(Se,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),h(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),h(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Se,"PROPERTIES",[...ri.META_PROPERTIES,...ri.UPSTREAM_PROPERTIES,...ri.DOWNSTREAM_PROPERTIES]);let Kr=Se;function _1(r){const a=ZZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const eW=Object.freeze(Object.defineProperty({__proto__:null,validate:_1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"type",n.InstalledProject);h(this,"implements");h(this,"functions",[]);h(this,"events",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.implements=e.implements}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=V(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ze.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),this.events.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=_1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.functions)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-exported-function-declaration-"+M+"-id",s));c.functions=T;const I=(P=this.events)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ze,"type",n.InstalledProject),h(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),h(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),h(Ze,"MUTABLE_BASE_PROPERTIES",[]),h(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),h(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),h(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),h(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),h(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),h(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Xr=Ze;function B1(r){var o;const a=iZ(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=Rr(r),s=M1(r),l=[...i,...s];return Ke(r.errors,l)}function M1(r){const a=[],e=Ul(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(fe({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(fe({id:`${r.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
|
|
108
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this.project.off(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,this.onPersistedEntityAdded),this.project.off(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,this.onPersistedEntityRemoved),this.project.off(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,this.onRelationalDatabaseEntityAdded),this.project.off(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,this.onRelationalDatabaseEntityRemoved),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.project.on(Bt.PERSISTED_DEFINITION_ENTITY_ADDED,this.onPersistedEntityAdded),this.project.on(Bt.PERSISTED_DEFINITION_ENTITY_REMOVED,this.onPersistedEntityRemoved),this.project.on(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED,this.onRelationalDatabaseEntityAdded),this.project.on(Bt.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED,this.onRelationalDatabaseEntityRemoved),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Se(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,A.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if([n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Se.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputs.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(f=>f.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(f=>f.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(f=>f.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),inputs:this.inputs.map(f=>f.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(f=>f.toJSONClone({...e,newId:null})),outputs:this.outputs.map(f=>f.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=C1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var C,M,G,_;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(C=this.inputsDeclarations)==null?void 0:C.map((g,q)=>g.clone(e,this,f+"-input-declaration-"+q+"-id",s));c.inputsDeclarations=T;const I=(M=this.outputsDeclarations)==null?void 0:M.map((g,q)=>g.clone(e,this,f+"-output-declaration-"+q+"-id",s));c.outputsDeclarations=I;const D=(G=this.inputs)==null?void 0:G.map((g,q)=>g.clone(e,c,f+"-input-map-"+q+"-id",s));c.inputs=D;const P=(_=this.outputs)==null?void 0:_.map((g,q)=>g.clone(e,c,f+"-output-map-"+q+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var f;return((f=u.declaration)==null?void 0:f.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},f=V(u,this.project);f.setParent(this,e),f.initChildren(e),e==null||e.add(f,A.Added),f.addSelfToProject(e),t.push(this),i.push(f)}}),this.inputs.forEach(o=>{if(o.declaration){if(!this.inputsDeclarations.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const{updated:u,removed:f}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...f)}}else{const{updated:d,removed:u}=o.remove({ignoreUpstream:!1},e);t.push(...d),s.push(...u)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(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,...i)=>null}),h(Se,"type",n.Search),h(Se,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),h(Se,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),h(Se,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"MUTABLE_META_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,"x","y"]),h(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),h(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),h(Se,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),h(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),h(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Se,"PROPERTIES",[...ri.META_PROPERTIES,...ri.UPSTREAM_PROPERTIES,...ri.DOWNSTREAM_PROPERTIES]);let Kr=Se;function _1(r){const a=ZZ(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return Ke(r.errors,i)}const eW=Object.freeze(Object.defineProperty({__proto__:null,validate:_1},Symbol.toStringTag,{value:"Module"})),Ze=class Ze extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"type",n.InstalledProject);h(this,"implements");h(this,"functions",[]);h(this,"events",[]);h(this,"parent");h(this,"errors",[]);h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.implements=e.implements}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=V(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ze.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),this.events.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.entity.onDetachedDependencyRestored(this,o.field,e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.functions.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),this.events.forEach(o=>{const{updated:d,removed:u,added:f,affected:c}=o.restore({},e);t.push(...d),i.push(...u),s.push(...f),l.push(...c)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=_1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.functions)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-exported-function-declaration-"+M+"-id",s));c.functions=T;const I=(P=this.events)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-exported-event-"+M+"-id",s));return c.events=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ze,"type",n.InstalledProject),h(Ze,"USER_MANAGED_PARENT_TYPES",[n.Project]),h(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),h(Ze,"MUTABLE_BASE_PROPERTIES",[]),h(Ze,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),h(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),h(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),h(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),h(Ze,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),h(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),h(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let Xr=Ze;function B1(r){var o;const a=iZ(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=Rr(r),s=M1(r),l=[...i,...s];return Ke(r.errors,l)}function M1(r){const a=[],e=Ul(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(fe({id:`${r.id}--${$.InternalCallParentMissingDataType}`,code:$.InternalCallParentMissingDataType,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(fe({id:`${r.id}--${$.InternalCallParentDeclarationEntityInvalidType}`,code:$.InternalCallParentDeclarationEntityInvalidType,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
|
|
109
109
|
This variable's data-type has an 'entity' field that references an entity with id '${t.id}' and of type '${t.type}'.`,issue:null,entity:r}).error);else{const i=Fa(t),s=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&s.push(...t.getAllInteractiveMethods());let l="";i?t.methods.length?l=`
|
|
110
110
|
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:
|
|
111
111
|
- ${t.methods.map(u=>u.id).join(`
|
|
@@ -134,7 +134,7 @@ ${sn}`);const I=i.declaration;if(!t.get(I))s.push(new w({id:`${i.id}--${R.Refere
|
|
|
134
134
|
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.${T}`,issue:null})):s.push(new w({id:`${i.id}--${$.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:$.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:O.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${i.declaration}".${T}`,issue:null}))}}(d.inputs.length||d.outputs.length||d.internalCalls.length)&&s.push(new w({id:`${i.id}--${R.InvalidInternalCallParentRelation}`,code:R.InvalidInternalCallParentRelation,severity:O.Error,message:`Entity of type "${i.type}" with id "${i.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
|
|
135
135
|
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.
|
|
136
136
|
The you can attach the new internal-call to it.`,issue:null}))}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
137
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:T}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...T),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=this.calledBy.find(s=>!!s.parent&&ht.includes(s.parent.type));if(i){const s=V(i.parent,this.project);this.parent.setParent(s,null)}else if(!i&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=B1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(T=>T.declaration.id===c.id));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(T=>{const I=V(T,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(T=>!this.outputs.find(I=>I.declaration.id===T.id));this.outputs.sort((T,I)=>T.index-I.index),d.forEach((T,I)=>{this.outputs.forEach(M=>{M.index>=T.index&&M.index++});const D=o.includes(T.index)?this.outputs.length-1+I:T.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:T.toJSON(),defaultValue:null,writesValues:[],index:D,parent:this.toReference()},C=V(P,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,A.Added),C.addSelfToProject(e)}),this.outputs.sort((T,I)=>T.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Be,"type",n.InternalCall),h(Be,"USER_MANAGED_PARENT_TYPES",[...it]),h(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),h(Be,"MUTABLE_BASE_PROPERTIES",[]),h(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),h(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),h(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),h(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let Qr=Be;function L1(r){const a=aZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const iW=Object.freeze(Object.defineProperty({__proto__:null,validate:L1},Symbol.toStringTag,{value:"Module"}));var j1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(j1||{});const Me=class Me extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"name",null);h(this,"description",null);h(this,"type",n.InputMap);h(this,"defaultValue",null);h(this,"readsValue",null);h(this,"dataType",null);h(this,"declaration",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:"",description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;if(e.declaration){const f=B(e.declaration);l=t.get(f)}let o=null;if(e.readsValue){const f=B(e.readsValue);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(s.inputs||[]).length,description:e.description||null,declaration:l,readsValue:o,defaultValue:null,parent:s},u=V(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){var f;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...dt,n.InputMap]}},t);i=l.modifiedData;const o=t.get(i.parent),d=i.declaration&&(t.get(i.declaration)||t.getBuiltIn(i.declaration)),u=((o==null?void 0:o.inputs)||[]).find(c=>{var T;return i.declaration&&((T=c.declaration)==null?void 0:T.id)===i.declaration});if(i.declaration?d?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(d.type)?o&&d.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:O.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${i.declaration}'.
|
|
137
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),this}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:T}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...T),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 i=this.calledBy.find(s=>!!s.parent&&ht.includes(s.parent.type));if(i){const s=V(i.parent,this.project);this.parent.setParent(s,null)}else if(!i&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=V(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this.parent,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=B1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(T=>T.declaration.id===c.id));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(T=>{const I=V(T,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(T=>!this.outputs.find(I=>I.declaration.id===T.id));this.outputs.sort((T,I)=>T.index-I.index),d.forEach((T,I)=>{this.outputs.forEach(M=>{M.index>=T.index&&M.index++});const D=o.includes(T.index)?this.outputs.length-1+I:T.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:T.toJSON(),defaultValue:null,writesValues:[],index:D,parent:this.toReference()},C=V(P,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,A.Added),C.addSelfToProject(e)}),this.outputs.sort((T,I)=>T.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Be,"type",n.InternalCall),h(Be,"USER_MANAGED_PARENT_TYPES",[...it]),h(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),h(Be,"MUTABLE_BASE_PROPERTIES",[]),h(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),h(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),h(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),h(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),h(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),h(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let Qr=Be;function L1(r){const a=aZ(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const iW=Object.freeze(Object.defineProperty({__proto__:null,validate:L1},Symbol.toStringTag,{value:"Module"}));var j1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(j1||{});const Me=class Me extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"name",null);h(this,"description",null);h(this,"type",n.InputMap);h(this,"defaultValue",null);h(this,"readsValue",null);h(this,"dataType",null);h(this,"declaration",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:"",description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null;if(e.declaration){const f=B(e.declaration);l=t.get(f)}let o=null;if(e.readsValue){const f=B(e.readsValue);o=t.get(f)}const d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(s.inputs||[]).length,description:e.description||null,declaration:l,readsValue:o,defaultValue:null,parent:s},u=V(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){var f;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[...dt,n.InputMap]}},t);i=l.modifiedData;const o=t.get(i.parent),d=i.declaration&&(t.get(i.declaration)||t.getBuiltIn(i.declaration)),u=((o==null?void 0:o.inputs)||[]).find(c=>{var T;return i.declaration&&((T=c.declaration)==null?void 0:T.id)===i.declaration});if(i.declaration?d?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(d.type)?o&&d.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:O.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${i.declaration}'.
|
|
138
138
|
The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
|
|
139
139
|
Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`,issue:null})):o&&d.type===n.Property&&!it.includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:O.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.Property}' with id '${i.declaration}'.
|
|
140
140
|
The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
|
|
@@ -152,7 +152,7 @@ Input maps can only be added to variables which hold an entity with properties.`
|
|
|
152
152
|
The entity of the data-type has the following properties that can be reads as input maps, ids: '${se(D.properties.map(C=>C.id),"', '","' and '")}'`,issue:null})))}else if(dt.filter(c=>it.includes(c)).includes(o.type)){const T=Xc(o),I=T.find(P=>P.id===i.declaration),D=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${se(T.map(P=>P.id),"', '","' and '")}'`;I||s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.InputMap}' with id '${i.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 '${i.declaration}'.
|
|
153
153
|
You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
|
|
154
154
|
${D}`,issue:null}))}}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=ja(i,this);return i=s.modifiedData,t.push(...s.errors),i.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
155
|
-
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];if(this.parent.addInput(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),it.includes(this.parent.type)&&((d=this.parent.getDataType(e))!=null&&d.inferred)){const u=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:f,added:c,removed:T,affected:I}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...f),i.push(...c),s.push(...T),l.push(...I),t.push(u,...u.variableInstances)}return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.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 b(this.project,m.sessionAuthor,E().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)),Or.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Me.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.defaultValue){const{updated:u,removed:f}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),this.declaration){if(this.declaration.type===n.Property&&this.declaration.parent.type===n.DefinitionEntity&&this.declaration.parent.parent.type===n.DataType&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}else if(this.declaration.type===n.ValueDescriptor&&((d=this.declaration.parent)==null?void 0:d.type)===n.Search&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}}return e||(i.push(this.parent),this.parent.removeInput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.restore({},e)),i.push(this.parent),this.parent.addInput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){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):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T,I,D;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(T=this.declaration)==null?void 0:T.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,readsValue:((D=this.readsValue)==null?void 0:D.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,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=L1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var c;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.defaultValue=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=f||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){var i;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this,e).self;if(it.includes(this.parent.type)){const s=Gn(this.parent),l=s.getDataType(e);(!l||l.inferred)&&s.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(i=this.declaration)==null?void 0:i.getDataType(e);if(!t){const s=$i(this,e);if(s)return s}return t||null}};h(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,...i)=>null}),h(Me,"type",n.InputMap),h(Me,"USER_MANAGED_PARENT_TYPES",[...dt]),h(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),h(Me,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),h(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),h(Me,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),h(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),h(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),h(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let er=Me;class rW extends er{constructor(e,t){super(e,t);h(this,"declaration",null);h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class nW extends er{constructor(e,t){super(e,t);h(this,"name",null);h(this,"description",null);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function U1(r){const a=g5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const sW=Object.freeze(Object.defineProperty({__proto__:null,validate:U1},Symbol.toStringTag,{value:"Module"}));var $1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))($1||{});const Ne=class Ne extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"type",n.OutputMap);h(this,"parentRelationType");h(this,"defaultValue",null);h(this,"declaration");h(this,"writesValues",[]);h(this,"dataType",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:null,writesValues:[],index:0,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l;if(e.declaration){const u=B(e.declaration);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,index:(s.outputs||[]).length,defaultValue:null,declaration:l,writesValues:[],parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:dt.filter(u=>u!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);i=l.modifiedData;const o=t.get(i.parent);if(o&&dt.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(f=>f.declaration.id===(i.declaration?B(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:O.Error,message:`Entity of type '${n.OutputMap}' with id '${i.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 '${u.id}' that points to the same base 'return-declaration'.
|
|
155
|
+
This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=B(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return Or.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];if(this.parent.addInput(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),it.includes(this.parent.type)&&((d=this.parent.getDataType(e))!=null&&d.inferred)){const u=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:f,added:c,removed:T,affected:I}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...f),i.push(...c),s.push(...T),l.push(...I),t.push(u,...u.variableInstances)}return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.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 b(this.project,m.sessionAuthor,E().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)),Or.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Me.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.defaultValue){const{updated:u,removed:f}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),this.declaration){if(this.declaration.type===n.Property&&this.declaration.parent.type===n.DefinitionEntity&&this.declaration.parent.parent.type===n.DataType&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}else if(this.declaration.type===n.ValueDescriptor&&((d=this.declaration.parent)==null?void 0:d.type)===n.Search&&!(t!=null&&t.hasRemoved(this.declaration.id))&&!this.declaration.deleted){const{updated:u,removed:f}=this.declaration.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...f)}}return e||(i.push(this.parent),this.parent.removeInput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.restore({},e)),i.push(this.parent),this.parent.addInput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){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):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T,I,D;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(T=this.declaration)==null?void 0:T.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,readsValue:((D=this.readsValue)==null?void 0:D.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,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=L1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var c;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.defaultValue=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=f||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){var i;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this,e).self;if(it.includes(this.parent.type)){const s=Gn(this.parent),l=s.getDataType(e);(!l||l.inferred)&&s.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(i=this.declaration)==null?void 0:i.getDataType(e);if(!t){const s=$i(this,e);if(s)return s}return t||null}};h(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,...i)=>null}),h(Me,"type",n.InputMap),h(Me,"USER_MANAGED_PARENT_TYPES",[...dt]),h(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),h(Me,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),h(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),h(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),h(Me,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),h(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),h(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),h(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let er=Me;class rW extends er{constructor(e,t){super(e,t);h(this,"declaration",null);h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class nW extends er{constructor(e,t){super(e,t);h(this,"name",null);h(this,"description",null);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function U1(r){const a=g5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return Ke(r.errors,i)}const sW=Object.freeze(Object.defineProperty({__proto__:null,validate:U1},Symbol.toStringTag,{value:"Module"}));var $1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))($1||{});const Ne=class Ne extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"index");h(this,"type",n.OutputMap);h(this,"parentRelationType");h(this,"defaultValue",null);h(this,"declaration");h(this,"writesValues",[]);h(this,"dataType",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:null,writesValues:[],index:0,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l;if(e.declaration){const u=B(e.declaration);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,index:(s.outputs||[]).length,defaultValue:null,declaration:l,writesValues:[],parent:s},d=V(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d;let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:dt.filter(u=>u!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);i=l.modifiedData;const o=t.get(i.parent);if(o&&dt.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(f=>f.declaration.id===(i.declaration?B(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:O.Error,message:`Entity of type '${n.OutputMap}' with id '${i.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 '${u.id}' that points to the same base 'return-declaration'.
|
|
156
156
|
Any value reads can be done with that output-map instead.
|
|
157
157
|
You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}));else{const f=i.declaration?t.get(i.declaration):null;if(f&&it.includes(o.type)){const c=Gn(o),T=c.dataType,I=(d=c.dataType)==null?void 0:d.entity;T?I?I.type===n.ActionDescriptor?s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.OutputMap}' with id '${i.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.
|
|
158
158
|
This means it can hold a function-call or operation as its value, to be executed programatically.
|
|
@@ -162,14 +162,14 @@ ${gc}`,issue:null})):s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSign
|
|
|
162
162
|
${gc}`,issue:null}))}else if(f){const c=o.outputs.find(T=>T.declaration.id===i.declaration);c&&s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:O.Error,message:`Entity of type '${n.OutputMap}' with id '${i.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 declaration.
|
|
163
163
|
Any value reads can be done with that output-map instead.
|
|
164
164
|
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 s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.declaration)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
165
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);if(o)this.setDeclaration(o),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parentRelationType===Zn.Error?it.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===k["value-descriptor"][Jn.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this,e),this.writesValues.forEach(d=>{d.setValueWriter(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.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 b(this.project,m.sessionAuthor,E().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)),qa.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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ne.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ne.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parentRelationType===Zn.Error?it.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parentRelationType===Zn.Error?it.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(D=>D.toJSONClone({...e,newId:null})),declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(T=this.declaration)==null?void 0:T.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:(l=this.declaration)==null?void 0:l.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=U1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var T,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(T=this.dataType)==null?void 0:T.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){var i;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this,e).self:((i=this.declaration)==null?void 0:i.getDataType(e))||null}};h(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,...i)=>null}),h(Ne,"type",n.OutputMap),h(Ne,"USER_MANAGED_PARENT_TYPES",[...uf]),h(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),h(Ne,"MUTABLE_BASE_PROPERTIES",[]),h(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),h(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),h(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),h(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let tr=Ne;class aW extends tr{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class oW extends tr{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function G1(r){var s;const a=Tq(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="company-dto-func-declaration-argument-dcl-id"){const l=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}if(r.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const l=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const lW=Object.freeze(Object.defineProperty({__proto__:null,validate:G1},Symbol.toStringTag,{value:"Module"}));var g1=(r=>(r.DataTypeEntity="data-type-entity",r.Implements="implements",r))(g1||{});const Le=class Le extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"type",n.ArgumentDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"",description:"",index:0,required:!1,constant:!0,implements:null,dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:s.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:s},o=V(l,t);return o.setParent(s,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);i=l.modifiedData;const o=wc(i,t);if(i.parent){const d=t.get(B(i.parent));if(d&&rt.includes(d.type)){const u=d.implements;if(u){const f=u.inputs.find(C=>C.name===i.name),c=u.inputs.filter(C=>!d.inputs.find(G=>G.type===n.ArgumentDeclaration&&G.name===C.name)),T=d.inputs.filter(C=>C.type===n.ArgumentDeclaration),I=T.find(C=>C.name===i.name),D=T.length?`The parent entity already implements the following arguments: ${se(T.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",P=c.length?`The parent entity is still missing the following arguments in the implementation: ${se(c.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";f?I&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${d.type}' with id '${d.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
|
|
165
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);if(o)this.setDeclaration(o),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parentRelationType===Zn.Error?it.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===k["value-descriptor"][Jn.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this,e),this.writesValues.forEach(d=>{d.setValueWriter(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.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 b(this.project,m.sessionAuthor,E().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)),qa.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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ne.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ne.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parentRelationType===Zn.Error?it.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parentRelationType===Zn.Error?it.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f,c,T,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(D=>D.toJSONClone({...e,newId:null})),declaration:(f=this.declaration)!=null&&f.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(T=this.declaration)==null?void 0:T.toJSON(e.seenEntities):((I=this.declaration)==null?void 0:I.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:(l=this.declaration)==null?void 0:l.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=U1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var T,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(T=this.dataType)==null?void 0:T.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){var i;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this,e).self:((i=this.declaration)==null?void 0:i.getDataType(e))||null}};h(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,...i)=>null}),h(Ne,"type",n.OutputMap),h(Ne,"USER_MANAGED_PARENT_TYPES",[...uf]),h(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),h(Ne,"MUTABLE_BASE_PROPERTIES",[]),h(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),h(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),h(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),h(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),h(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),h(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let tr=Ne;class aW extends tr{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class oW extends tr{constructor(e,t){super(e,t);h(this,"declaration");h(this,"parent");h(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function G1(r){var s;const a=Tq(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="company-dto-func-declaration-argument-dcl-id"){const l=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}if(r.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const l=fe({id:`${r.id}--${x.PropertyImplementsNonAbstact}`,message:`Property "${F(r,r.project)}" with id "${r.id}" implements a non-abstract property "${F(r,r.project)}" with id "${r.id}".`,issue:null,severity:O.Error,code:x.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return Ke(r.errors,i)}const lW=Object.freeze(Object.defineProperty({__proto__:null,validate:G1},Symbol.toStringTag,{value:"Module"}));var g1=(r=>(r.DataTypeEntity="data-type-entity",r.Implements="implements",r))(g1||{});const Le=class Le extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"constant",!0);h(this,"type",n.ArgumentDeclaration);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"writesValues",[]);h(this,"implements",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);h(this,"_codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"",description:"",index:0,required:!1,constant:!0,implements:null,dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:s.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:s},o=V(l,t);return o.setParent(s,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);i=l.modifiedData;const o=wc(i,t);if(i.parent){const d=t.get(B(i.parent));if(d&&rt.includes(d.type)){const u=d.implements;if(u){const f=u.inputs.find(C=>C.name===i.name),c=u.inputs.filter(C=>!d.inputs.find(G=>G.type===n.ArgumentDeclaration&&G.name===C.name)),T=d.inputs.filter(C=>C.type===n.ArgumentDeclaration),I=T.find(C=>C.name===i.name),D=T.length?`The parent entity already implements the following arguments: ${se(T.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",P=c.length?`The parent entity is still missing the following arguments in the implementation: ${se(c.map(C=>`'${C.id}' (${C.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";f?I&&s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${d.type}' with id '${d.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
|
|
166
166
|
Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
|
|
167
167
|
${D}
|
|
168
168
|
${P}`,issue:null})):s.push(new w({id:`${i.id}--${$.NoOverlapWithImplementedSignature}`,code:$.NoOverlapWithImplementedSignature,severity:O.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${d.type}' with id '${d.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
|
|
169
169
|
Adding a new argument would make the implementation invalid. There are no arguments in the descriptor with the same name.
|
|
170
170
|
${D}
|
|
171
171
|
${P}`,issue:null}))}}}return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get codeNativeValueValidation(){var e;return this._codeNativeValueValidation||((e=this.implements)==null?void 0:e.codeNativeValueValidation)||null}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
172
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Le(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.implements=this.implements,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.writesValues=this.writesValues,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Le(u,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:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addInputDeclaration(this,e),t.push(this.parent),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 qa.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.required=e.required!==void 0?e.required:this.required,this.constant=!0,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Le.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Le.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parent.removeInputDeclaration(this,t)),this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parent.addInputDeclaration(this,e),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.dataType)==null?void 0:s.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:!0,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;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:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),parent:this.parent.toReference()}):(console.error("ArgumentDeclarationState.toJSON was called without a valid Set of seenEntities.",`
|
|
172
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.unsubscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.unsubscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Le(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.implements=this.implements,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.writesValues=this.writesValues,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.implements=o.implements,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.writesValues=o.writesValues,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const l=B(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addInputDeclaration(this,e),t.push(this.parent),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-implements",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 qa.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.required=e.required!==void 0?e.required:this.required,this.constant=!0,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Le.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Le.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parent.removeInputDeclaration(this,t)),this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parent.addInputDeclaration(this,e),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.dataType)==null?void 0:s.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:!0,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;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:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),parent:this.parent.toReference()}):(console.error("ArgumentDeclarationState.toJSON was called without a valid Set of seenEntities.",`
|
|
173
173
|
Received type: ${typeof e}
|
|
174
174
|
`,e),{})}toJSONClone(e=W){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(T=>T.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),implements:((l=this.implements)==null?void 0:l.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...((s=this.dataType)==null?void 0:s.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 i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=G1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var T,I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const f=(T=this.dataType)==null?void 0:T.clone(e,u,m.UUID.uuid(),s);u.dataType=f||null;const c=(I=this.defaultValue)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};h(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,...i)=>null}),h(Le,"type",n.ArgumentDeclaration),h(Le,"USER_MANAGED_PARENT_TYPES",[...rt]),h(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),h(Le,"MUTABLE_BASE_PROPERTIES",["name","description","required","constant"]),h(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),h(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,"index"]),h(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),h(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),h(Le,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),h(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),h(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),h(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let br=Le;function F1(r){const a=Lp(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const dW=Object.freeze(Object.defineProperty({__proto__:null,validate:F1},Symbol.toStringTag,{value:"Module"}));function uW(r,a){var t,i;const e=[];if(r.parent)if(r.parent){const s=a.get(r.parent);s?[n.InputMap,n.DataType].includes(s.type)?s.type===n.DataType&&s.entity?e.push(new w({id:`${r.id}--${r.parent}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a 'parent' of type 'data-type' which already has an existing default value entity with id "${s.entity.id}".
|
|
175
175
|
Data types can only have one 'literal-value' entity as 'entity'.
|
|
@@ -196,15 +196,15 @@ You can update the existing 'literal-value' with the 'update' action, for exampl
|
|
|
196
196
|
}
|
|
197
197
|
}\`\`\`
|
|
198
198
|
Or 'delete' and then 'post' actions to replace it.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'input-map' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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 w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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(r.valueAsTypeSingle){const s=[],l=[],o=r.valueAsTypeSingle;Array.isArray(o)?o.forEach(d=>{typeof d=="string"?l.push(d):s.push(d)}):typeof o=="string"?l.push(o):s.push(o),s.forEach(d=>{const u=xl(d);e.push(...u),u.length===0&&l.push(d.entityId)}),l.forEach(d=>{const u=a.get(d);u?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(u.type)||e.push(new w({id:`${r.id}--${d}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.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 w({id:`${r.id}--${d}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${d}" 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 x1=(r=>(r.ValueAsTypeSingle="value-as-type-single",r.ValueAsTypeList="value-as-type-list",r))(x1||{});const je=class je extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"type",n.LiteralValue);h(this,"id");h(this,"name");h(this,"autogeneration",null);h(this,"value",null);h(this,"valueAsTypeSingle",null);h(this,"valueAsTypeList",null);h(this,"errors",[]);h(this,"parent");h(this,"standaloneParent");h(this,"project");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:"",autogeneration:null,value:null,valueAsTypeSingle:null,valueAsTypeList:null,parent:null}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i);let l=null,o=null;e.valueAsTypeList?Array.isArray(e.valueAsTypeList)&&(o=e.valueAsTypeList.map(f=>t.get(f)||t.getBuiltIn(f))):e.valueAsTypeSingle&&(l=t.get(e.valueAsTypeSingle)||t.getBuiltIn(e.valueAsTypeSingle));const d={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:e.name,autogeneration:e.autogeneration,valueAsTypeSingle:l,valueAsTypeList:o,value:e.value||null,parent:s},u=V(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=uW(i,t);return s.push(...l,...ut(i)),{errors:s,modifiedData:i}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}get isFinal(){var e;return!!(this.parent.type===n.Property&&(this.parent.constant||(e=this.parent.implements)!=null&&e.constant)||this.parent.type===n.Property&&this.parent.parent.type===n.DefinitionEntity&&!Fa(this.parent.parent))}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
199
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(u=>u.id!==e.id),i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==n.BuiltInBaseEntity&&this.valueAsTypeSingle.unsubscribeDependents([{entity:this,field:"value-as-type-single"}]),this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)&&this.valueAsTypeList.forEach(e=>{e.type!==n.BuiltInBaseEntity&&e.unsubscribeDependents([{entity:this,field:"value-as-type-list"}])}),this}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>{e.type!==n.BuiltInBaseEntity&&e.subscribeDependents([{entity:this,field:"value-as-type-list"}])}):this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==n.BuiltInBaseEntity&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new je(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new je(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else if(this.initialData.standaloneParent){const l=B(this.initialData.standaloneParent),o=this.project.get(l);if(o)this.setStandaloneParent(o);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(l=>{const o=B(l),d=this.project.get(o);d&&this.valueAsTypeList.push(d)});else if(this.initialData.valueAsTypeSingle){const l=B(this.initialData.valueAsTypeSingle),o=this.project.get(l);o&&(this.valueAsTypeSingle=o)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(d=this.parent)==null||d.setDefaultValue(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsTypeSingle(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-as-type-single"))){return this.valueAsTypeSingle!==e&&(this.valueAsTypeSingle=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-as-type-single",this.id),this}setValueAsTypeList(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-as-type-list"))){var i,s;return!e&&this.valueAsTypeList?(this.valueAsTypeList=null,t==null||t.add(this,A.Updated)):e&&!this.valueAsTypeList?(this.valueAsTypeList=e,t==null||t.add(this,A.Updated)):e&&this.valueAsTypeList&&((i=this.valueAsTypeList)==null?void 0:i.length)!==e.length?(this.valueAsTypeList=e,t==null||t.add(this,A.Updated)):e&&this.valueAsTypeList&&((s=this.valueAsTypeList)!=null&&s.every((l,o)=>l!==e[o]))&&(this.valueAsTypeList=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-as-type-list",this.id),this}setValueAsType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-as-type"))){return e?(Array.isArray(e)?this.setValueAsTypeList(e,t):this.setValueAsTypeSingle(e,t),t==null||t.attemptAutoclose("set-value-as-type",this.id),this):(this.setValueAsTypeSingle(null,t),this.setValueAsTypeList(null,t),this)}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)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 s}const i=this.project.get(t.id);if(!i)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 i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!i)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=i,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 s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)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 s}const i=this.project.get(t.id);if(!i)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 i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=B(this.initialData.valueAsTypeSingle),s=i?this.project.get(i):null;if(!s)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=s,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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.autogeneration=e.autogeneration!==void 0?e.autogeneration:s.autogeneration,this.value=e.value!==void 0?e.value:s.value,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await je.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await je.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.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(i=>i.toFlatIds(e)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,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(l=>l.toJSON(e)):null,parent:(i=this.parent)==null?void 0:i.toReference(),standaloneParent:(s=this.standaloneParent)==null?void 0:s.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,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(c=>this.project.getBuiltIn(c.id)?c.toJSON():c.toJSONClone({...e,newId:null})):null,parent:(u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}),standaloneParent:(f=this.standaloneParent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((s=this.valueAsTypeSingle)==null?void 0:s.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(d=>d.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(l=this.parent)==null?void 0:l.toReference(e),standaloneParent:(o=this.standaloneParent)==null?void 0:o.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(i=>i.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t,i;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(s=>s.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id,standaloneParent:(i=this.standaloneParent)==null?void 0:i.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(i=>i.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=F1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);return u.initChildren(e),t&&u.setParent(t,null),e==null||e.add(u,A.Added),s&&u.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),u}merge(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"merge-literal-value"))){const i=[],s=[],l=[],o=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle,t),i.push(this)),this.value!==e.value&&(this.metaSync({value:e.value},t),i.push(this)),this.autogeneration!==e.autogeneration&&(this.metaSync({autogeneration:e.autogeneration},t),i.push(this)),this.name!==e.name&&(this.metaSync({name:e.name},t),i.push(this)),t==null||t.attemptAutoclose("merge-literal-value",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:this}}};h(je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(je,"type",n.LiteralValue),h(je,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),h(je,"PARENT_TYPES",[...je.USER_MANAGED_PARENT_TYPES]),h(je,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),h(je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(je,"BASE_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES,...je.INMUTABLE_BASE_PROPERTIES]),h(je,"MUTABLE_META_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES]),h(je,"INMUTABLE_META_PROPERTIES",[...je.INMUTABLE_BASE_PROPERTIES]),h(je,"META_PROPERTIES",[...je.MUTABLE_META_PROPERTIES,...je.INMUTABLE_META_PROPERTIES]),h(je,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(je,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(je,"UPSTREAM_PROPERTIES",[...je.MUTABLE_UPSTREAM_PROPERTIES,...je.INMUTABLE_UPSTREAM_PROPERTIES]),h(je,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),h(je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(je,"DOWNSTREAM_PROPERTIES",[...je.MUTABLE_DOWNSTREAM_PROPERTIES,...je.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(je,"PROPERTIES",[...je.META_PROPERTIES,...je.UPSTREAM_PROPERTIES,...je.DOWNSTREAM_PROPERTIES]);let en=je;function k1(r){var s;const a=j5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const pW=Object.freeze(Object.defineProperty({__proto__:null,validate:k1},Symbol.toStringTag,{value:"Module"}));var Z1=(r=>(r.Parent="parent",r))(Z1||{});const qe=class qe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.BreakStatement);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"throws",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),o=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),d=e.calledByError.map(c=>{const T=B(c);return t.get(T)}),u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},f=V(u,t);return f.setParent(s,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
199
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(u=>u.id!==e.id),i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==n.BuiltInBaseEntity&&this.valueAsTypeSingle.unsubscribeDependents([{entity:this,field:"value-as-type-single"}]),this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)&&this.valueAsTypeList.forEach(e=>{e.type!==n.BuiltInBaseEntity&&e.unsubscribeDependents([{entity:this,field:"value-as-type-list"}])}),this}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>{e.type!==n.BuiltInBaseEntity&&e.subscribeDependents([{entity:this,field:"value-as-type-list"}])}):this.valueAsTypeSingle&&this.valueAsTypeSingle.type!==n.BuiltInBaseEntity&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new je(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new je(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent&&this.initialData.standaloneParent)throw new Error(`Entity with id '${this.id}' cannot have both 'parent' and 'standaloneParent' properties set.`);if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else if(this.initialData.standaloneParent){const l=B(this.initialData.standaloneParent),o=this.project.get(l);if(o)this.setStandaloneParent(o);else throw new Error(`${this.type} with id '${this.id}' has a 'standaloneParent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(l=>{const o=B(l),d=this.project.get(o);d&&this.valueAsTypeList.push(d)});else if(this.initialData.valueAsTypeSingle){const l=B(this.initialData.valueAsTypeSingle),o=this.project.get(l);o&&(this.valueAsTypeSingle=o)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(d=this.parent)==null||d.setDefaultValue(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsTypeSingle(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-as-type-single"))){return this.valueAsTypeSingle!==e&&(this.valueAsTypeSingle=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-as-type-single",this.id),this}setValueAsTypeList(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-as-type-list"))){var i,s;return!e&&this.valueAsTypeList?(this.valueAsTypeList=null,t==null||t.add(this,A.Updated)):e&&!this.valueAsTypeList?(this.valueAsTypeList=e,t==null||t.add(this,A.Updated)):e&&this.valueAsTypeList&&((i=this.valueAsTypeList)==null?void 0:i.length)!==e.length?(this.valueAsTypeList=e,t==null||t.add(this,A.Updated)):e&&this.valueAsTypeList&&((s=this.valueAsTypeList)!=null&&s.every((l,o)=>l!==e[o]))&&(this.valueAsTypeList=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-as-type-list",this.id),this}setValueAsType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-value-as-type"))){return e?(Array.isArray(e)?this.setValueAsTypeList(e,t):this.setValueAsTypeSingle(e,t),t==null||t.attemptAutoclose("set-value-as-type",this.id),this):(this.setValueAsTypeSingle(null,t),this.setValueAsTypeList(null,t),this)}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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 s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)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 s}const i=this.project.get(t.id);if(!i)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 i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!i)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=i,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 s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)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 s}const i=this.project.get(t.id);if(!i)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 i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=B(this.initialData.valueAsTypeSingle),s=i?this.project.get(i):null;if(!s)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=s,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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.autogeneration=e.autogeneration!==void 0?e.autogeneration:s.autogeneration,this.value=e.value!==void 0?e.value:s.value,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await je.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await je.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.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(i=>i.toFlatIds(e)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,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(l=>l.toJSON(e)):null,parent:(i=this.parent)==null?void 0:i.toReference(),standaloneParent:(s=this.standaloneParent)==null?void 0:s.toReference()})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,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(c=>this.project.getBuiltIn(c.id)?c.toJSON():c.toJSONClone({...e,newId:null})):null,parent:(u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}),standaloneParent:(f=this.standaloneParent)==null?void 0:f.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((s=this.valueAsTypeSingle)==null?void 0:s.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(d=>d.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(l=this.parent)==null?void 0:l.toReference(e),standaloneParent:(o=this.standaloneParent)==null?void 0:o.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(i=>i.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t,i;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(s=>s.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id,standaloneParent:(i=this.standaloneParent)==null?void 0:i.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(i=>i.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=F1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=st(o,l);return u.initChildren(e),t&&u.setParent(t,null),e==null||e.add(u,A.Added),s&&u.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),u}merge(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"merge-literal-value"))){const i=[],s=[],l=[],o=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle,t),i.push(this)),this.value!==e.value&&(this.metaSync({value:e.value},t),i.push(this)),this.autogeneration!==e.autogeneration&&(this.metaSync({autogeneration:e.autogeneration},t),i.push(this)),this.name!==e.name&&(this.metaSync({name:e.name},t),i.push(this)),t==null||t.attemptAutoclose("merge-literal-value",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:this}}};h(je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(je,"type",n.LiteralValue),h(je,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),h(je,"PARENT_TYPES",[...je.USER_MANAGED_PARENT_TYPES]),h(je,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),h(je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(je,"BASE_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES,...je.INMUTABLE_BASE_PROPERTIES]),h(je,"MUTABLE_META_PROPERTIES",[...je.MUTABLE_BASE_PROPERTIES]),h(je,"INMUTABLE_META_PROPERTIES",[...je.INMUTABLE_BASE_PROPERTIES]),h(je,"META_PROPERTIES",[...je.MUTABLE_META_PROPERTIES,...je.INMUTABLE_META_PROPERTIES]),h(je,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(je,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(je,"UPSTREAM_PROPERTIES",[...je.MUTABLE_UPSTREAM_PROPERTIES,...je.INMUTABLE_UPSTREAM_PROPERTIES]),h(je,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),h(je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(je,"DOWNSTREAM_PROPERTIES",[...je.MUTABLE_DOWNSTREAM_PROPERTIES,...je.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(je,"PROPERTIES",[...je.META_PROPERTIES,...je.UPSTREAM_PROPERTIES,...je.DOWNSTREAM_PROPERTIES]);let en=je;function k1(r){var s;const a=j5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return Ke(r.errors,i)}const pW=Object.freeze(Object.defineProperty({__proto__:null,validate:k1},Symbol.toStringTag,{value:"Module"}));var Z1=(r=>(r.Parent="parent",r))(Z1||{});const qe=class qe extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"x");h(this,"y");h(this,"type",n.BreakStatement);h(this,"outputs",[]);h(this,"calledBySuccess",[]);h(this,"calledByError",[]);h(this,"calledByEntry",[]);h(this,"throws",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(e,t){const i=B(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const T=B(c);return t.get(T)}),o=e.calledBySuccess.map(c=>{const T=B(c);return t.get(T)}),d=e.calledByError.map(c=>{const T=B(c);return t.get(T)}),u={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},f=V(u,t);return f.setParent(s,null),f.initChildren(null),f}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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.
|
|
200
200
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
201
201
|
You shouldn't have to manually update a 'parent' property.
|
|
202
|
-
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new qe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new qe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(u=>{u.addCall(this,e),t.push(u)}),this.calledBySuccess.forEach(u=>{u.addSuccessCall(this,e),t.push(u)}),this.calledByError.forEach(u=>{u.addErrorCall(this,e),t.push(u)}),this.parent.addBreakStatement(this),t.push(this.parent),e==null||e.add(this.parent,A.Affected),(o=this.parent)==null||o.breakStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),(d=this.parent)==null||d.continueStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await qe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await qe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await qe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await qe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await qe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await qe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d,u;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(f=>{const{updated:c,removed:T,added:I}=f.entity.onDetachedDependencyRemoved(this,f.field,t);i.push(...c),s.push(...T),l.push(...I)}),this.outputs.forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!0},t);i.push(...c),s.push(...T)}),this.throws){const{updated:f,removed:c}=this.throws.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}return e||(this.parent.removeBreakStatement(this),this.calledBy.forEach(f=>{i.push(f),f.removeCall(this,t)})),t==null||t.add(this.parent,A.Affected),(d=this.parent)==null||d.breakStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),(u=this.parent)==null||u.continueStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=k1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.outputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-return-declaration-"+P+"-id",s));return c.outputs=T,this.throws&&(c.throws=this.throws.clone(e,c,f+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(qe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(qe,"type",n.BreakStatement),h(qe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),h(qe,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),h(qe,"MUTABLE_BASE_PROPERTIES",[]),h(qe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(qe,"BASE_PROPERTIES",[...qe.MUTABLE_BASE_PROPERTIES,...qe.INMUTABLE_BASE_PROPERTIES]),h(qe,"MUTABLE_META_PROPERTIES",["x","y"]),h(qe,"INMUTABLE_META_PROPERTIES",[...qe.INMUTABLE_BASE_PROPERTIES]),h(qe,"META_PROPERTIES",[...qe.MUTABLE_META_PROPERTIES,...qe.INMUTABLE_META_PROPERTIES]),h(qe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(qe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(qe,"UPSTREAM_PROPERTIES",[...qe.MUTABLE_UPSTREAM_PROPERTIES,...qe.INMUTABLE_UPSTREAM_PROPERTIES]),h(qe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),h(qe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(qe,"DOWNSTREAM_PROPERTIES",[...qe.MUTABLE_DOWNSTREAM_PROPERTIES,...qe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(qe,"PROPERTIES",[...qe.META_PROPERTIES,...qe.UPSTREAM_PROPERTIES,...qe.DOWNSTREAM_PROPERTIES]);let tn=qe;function q1(r){var s;const a=Q3(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];return Ke(r.errors,i)}const cW=Object.freeze(Object.defineProperty({__proto__:null,validate:q1},Symbol.toStringTag,{value:"Module"}));var J1=(r=>(r.DataTypeEntity="data-type-entity",r))(J1||{});const Ue=class Ue extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"parentRelationType");h(this,"type",n.ValueDescriptor);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:"",description:"",dataType:null,index:0,required:!1,parentRelationType:L.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=e.parent?B(e.parent):null,s=i?t.get(i):null,l=e.parentRelationType===L.FixedArguments?s==null?void 0:s.inputs.length:s==null?void 0:s.outputs.length,o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:l||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:s},d=V(o,t);return s&&d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.ActionDescriptor]}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=i.parent&&t.get(i.parent),d=o&&ln(o);return d&&d.type===n.ActionDescriptor&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${d.name}" of type '${d.type}' with id '${d.id}'.
|
|
202
|
+
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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new qe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new qe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.parent.syncTerminationStatements(e),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(u=>{u.addCall(this,e),t.push(u)}),this.calledBySuccess.forEach(u=>{u.addSuccessCall(this,e),t.push(u)}),this.calledByError.forEach(u=>{u.addErrorCall(this,e),t.push(u)}),this.parent.addBreakStatement(this),t.push(this.parent),e==null||e.add(this.parent,A.Affected),(o=this.parent)==null||o.breakStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),(d=this.parent)==null||d.continueStatements.forEach(u=>{u.id!==this.id&&(l.push(u),e==null||e.add(u,A.Affected))}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),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.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await qe.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await qe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await qe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await qe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await qe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await qe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d,u;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(f=>{const{updated:c,removed:T,added:I}=f.entity.onDetachedDependencyRemoved(this,f.field,t);i.push(...c),s.push(...T),l.push(...I)}),this.outputs.forEach(f=>{const{updated:c,removed:T}=f.remove({ignoreUpstream:!0},t);i.push(...c),s.push(...T)}),this.throws){const{updated:f,removed:c}=this.throws.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}return e||(this.parent.removeBreakStatement(this),this.calledBy.forEach(f=>{i.push(f),f.removeCall(this,t)})),t==null||t.add(this.parent,A.Affected),(d=this.parent)==null||d.breakStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),(u=this.parent)==null||u.continueStatements.forEach(f=>{f.id!==this.id&&(o.push(f),t==null||t.add(f,A.Affected))}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((f=this.throws)==null?void 0:f.toJSONClone({...e,newId:null}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=k1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(I=this.outputs)==null?void 0:I.map((D,P)=>D.clone(e,c,f+"-return-declaration-"+P+"-id",s));return c.outputs=T,this.throws&&(c.throws=this.throws.clone(e,c,f+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};h(qe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(qe,"type",n.BreakStatement),h(qe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),h(qe,"PARENT_TYPES",[...qe.USER_MANAGED_PARENT_TYPES]),h(qe,"MUTABLE_BASE_PROPERTIES",[]),h(qe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(qe,"BASE_PROPERTIES",[...qe.MUTABLE_BASE_PROPERTIES,...qe.INMUTABLE_BASE_PROPERTIES]),h(qe,"MUTABLE_META_PROPERTIES",["x","y"]),h(qe,"INMUTABLE_META_PROPERTIES",[...qe.INMUTABLE_BASE_PROPERTIES]),h(qe,"META_PROPERTIES",[...qe.MUTABLE_META_PROPERTIES,...qe.INMUTABLE_META_PROPERTIES]),h(qe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),h(qe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),h(qe,"UPSTREAM_PROPERTIES",[...qe.MUTABLE_UPSTREAM_PROPERTIES,...qe.INMUTABLE_UPSTREAM_PROPERTIES]),h(qe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),h(qe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(qe,"DOWNSTREAM_PROPERTIES",[...qe.MUTABLE_DOWNSTREAM_PROPERTIES,...qe.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(qe,"PROPERTIES",[...qe.META_PROPERTIES,...qe.UPSTREAM_PROPERTIES,...qe.DOWNSTREAM_PROPERTIES]);let tn=qe;function q1(r){var s;const a=Q3(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];return Ke(r.errors,i)}const cW=Object.freeze(Object.defineProperty({__proto__:null,validate:q1},Symbol.toStringTag,{value:"Module"}));var J1=(r=>(r.DataTypeEntity="data-type-entity",r))(J1||{});const Ue=class Ue extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"index");h(this,"required");h(this,"parentRelationType");h(this,"type",n.ValueDescriptor);h(this,"defaultValue",null);h(this,"dataType",null);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"codeNativeValueValidation",null);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 new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:"",description:"",dataType:null,index:0,required:!1,parentRelationType:L.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=e.parent?B(e.parent):null,s=i?t.get(i):null,l=e.parentRelationType===L.FixedArguments?s==null?void 0:s.inputs.length:s==null?void 0:s.outputs.length,o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:l||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:s},d=V(o,t);return s&&d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=bt(i,{parent:{list:!1,types:[n.ActionDescriptor]}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=i.parent&&t.get(i.parent),d=o&&ln(o);return d&&d.type===n.ActionDescriptor&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:O.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${d.name}" of type '${d.type}' with id '${d.id}'.
|
|
203
203
|
You can't modify system entities that are built-in.`,issue:null})),o&&o.type===n.ActionDescriptor&&(!i.parentRelationType||!(i.parentRelationType===L.FixedArguments||i.parentRelationType===L.FixedReturns||i.parentRelationType===L.ReturnedError||i.parentRelationType===L.DynamicArgument||i.parentRelationType===L.DynamicReturn)?s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:O.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either '${L.FixedArguments}', '${L.FixedReturns}', or '${L.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`,issue:null})):i.parentRelationType===L.ReturnedError&&o.error&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.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
|
-
${rr({describe_entity:o.error.id})}`,issue:null}))),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.unsubscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw console.warn("No parent found for entity",this.initialData),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d,u,f,c,T,I,D;const t=[this],i=[],s=[],l=[];return this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((d=this.parent)==null?void 0:d.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((f=(u=this.parent)==null?void 0:u.addInput)==null||f.call(u,this,e),t.push(this.parent)):this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?((c=this.parent)==null?void 0:c.type)===n.Search||((T=this.parent)==null?void 0:T.type)===n.Loop?(this.parent.addOutputDeclaration(this,e),t.push(this.parent)):((D=(I=this.parent)==null?void 0:I.addOutput)==null||D.call(I,this,e),t.push(this.parent)):this.parentRelationType===L.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.index=e.index||(e.index!==0?s.index:0),this.required=e.required!==void 0?e.required:this.required,this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var u,f,c,T,I,D,P;const i=[],s=[],l=[],o=[];if(Array.from(new Set([...Gi(),...this.project.getAllBuiltInIds()])).includes(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),console.log("Built-in entity, cannot remove: ",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(C=>{const{updated:M,removed:G,added:_}=C.entity.onDetachedDependencyRemoved(this,C.field,t);i.push(...M),s.push(...G),l.push(..._)}),this.defaultValue){const{updated:C,removed:M}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}if(this.dataType){const{updated:C,removed:M}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}return e||(((u=this.parent)==null?void 0:u.type)===n.Search?this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(f=this.parent)==null||f.removeOutputDeclaration(this,t):this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument?(c=this.parent)==null||c.removeInputDeclaration(this,t):this.parentRelationType===L.ReturnedError&&(this.parent.error=null):((T=this.parent)==null?void 0:T.type)===n.Loop?this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(I=this.parent)==null||I.removeOutputDeclaration(this,t):this.parentRelationType===L.ReturnedError&&(this.parent.error=null):this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(D=this.parent)==null||D.removeOutput(this,t):(this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this,t))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){var o,d,u,f,c,T,I;const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(D=>{const{updated:P,removed:C,added:M}=D.entity.onDetachedDependencyRestored(this,D.field,e);i.push(...P),s.push(...C),t.push(...M)}),this.defaultValue){const{updated:D}=this.defaultValue.restore({},e);i.push(...D)}if(this.dataType){const{updated:D}=this.dataType.restore({},e);i.push(...D)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(d=this.parent)==null||d.addOutputDeclaration(this,e):(this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument)&&((u=this.parent)==null||u.addInputDeclaration(this,e)):((f=this.parent)==null?void 0:f.type)===n.Loop?(this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn)&&((c=this.parent)==null||c.addOutputDeclaration(this,e)):this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(T=this.parent)==null||T.addOutput(this,e):(this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument)&&((I=this.parent)==null||I.addInput(this,e)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,parent:((s=this.parent)==null?void 0:s.toReference())||null})}toJSONClone(e=W){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=q1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D;if(Array.from(new Set([...Gi(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=i||m.UUID.uuid(),u=this.toJSON();u.id=d,u.version=m.UUID.uuid(),u.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),u.author=(e==null?void 0:e.author)||"1",u.previousVersion=null,u.deleted=!1;const f=st(u,o);t&&f.setParent(t,null),e==null||e.add(f,A.Added),s&&f.subscribe();const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const T=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=T||null,e==null||e.attemptAutoclose("clone-entity",this.id),f}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}implementAsReturnDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-return-declaration")),t,i){const s=ri.new(e);s.id=i||s.id,s.name=this.name,s.description=this.description,s.parent=t.toReference(),s.implements=this.toJSON(),s.isError=this.parentRelationType===L.ReturnedError;const l=st(s,this.project);if(l.hydrateAncestors(),l.addSelfToProject(e),e==null||e.add(l,A.Added),l.initChildren(e),this.dataType){const o=this.dataType.clone(e,l);l.setDataType(o)}if(this.defaultValue){const o=this.defaultValue.clone(e,l);l.setDefaultValue(o)}return e==null||e.attemptAutoclose("implement-as-return-declaration",this.id),l}implementAsArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-return-declaration")),t,i){const s=br.new(e);s.id=i||s.id,s.name=this.name,s.description=this.description,s.parent=t.toReference(),s.implements=this.toJSON();const l=st(s,this.project);if(l.hydrateAncestors(),l.addSelfToProject(e),e==null||e.add(l,A.Added),l.initChildren(e),this.dataType){const o=this.dataType.clone(e,l);l.setDataType(o)}if(this.defaultValue){const o=this.defaultValue.clone(e,l);l.setDefaultValue(o)}return e==null||e.attemptAutoclose("implement-as-return-declaration",this.id),l}};h(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ue,"type",n.ValueDescriptor),h(Ue,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),h(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),h(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),h(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),h(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),h(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"index"]),h(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),h(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),h(Ue,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),h(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let ir=Ue;function fW(r,a){if(!r.type&&!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:O.Error,code:R.MissingTypeProperty,issue:null}),new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:O.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null};if(r.type){if(!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:`Last generated entity, with type "${r.type}" is missing an 'id' property.`,severity:O.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new w({id:`${r.id}--${R.MissingTypeProperty}`,message:`Entity with id "${r.id}" is missing a 'type' property.`,severity:O.Error,code:R.MissingTypeProperty,issue:null})],modifiedData:null};if(r.type===n.GenericReference)return{errors:[new w({id:`${r.id}--${R.RootReference}`,message:`Generic reference entity with id "${r.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:O.Error,code:R.RootReference,issue:null})],modifiedData:null};const e=r,t=a.instances[e.id],i=a.builtInInstances[e.id];if(t&&!i&&e.type!==n.GenericReference){let s=`A previously generated entity with id "${e.id}" already exists in the project state.
|
|
207
|
+
${rr({describe_entity:o.error.id})}`,issue:null}))),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.unsubscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw console.warn("No parent found for entity",this.initialData),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o,d,u,f,c,T,I,D;const t=[this],i=[],s=[],l=[];return this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((d=this.parent)==null?void 0:d.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((f=(u=this.parent)==null?void 0:u.addInput)==null||f.call(u,this,e),t.push(this.parent)):this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?((c=this.parent)==null?void 0:c.type)===n.Search||((T=this.parent)==null?void 0:T.type)===n.Loop?(this.parent.addOutputDeclaration(this,e),t.push(this.parent)):((D=(I=this.parent)==null?void 0:I.addOutput)==null||D.call(I,this,e),t.push(this.parent)):this.parentRelationType===L.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=V(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=V(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.index=e.index||(e.index!==0?s.index:0),this.required=e.required!==void 0?e.required:this.required,this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var u,f,c,T,I,D,P;const i=[],s=[],l=[],o=[];if(Array.from(new Set([...Gi(),...this.project.getAllBuiltInIds()])).includes(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),console.log("Built-in entity, cannot remove: ",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(C=>{const{updated:M,removed:G,added:_}=C.entity.onDetachedDependencyRemoved(this,C.field,t);i.push(...M),s.push(...G),l.push(..._)}),this.defaultValue){const{updated:C,removed:M}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}if(this.dataType){const{updated:C,removed:M}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...C),s.push(...M)}return e||(((u=this.parent)==null?void 0:u.type)===n.Search?this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(f=this.parent)==null||f.removeOutputDeclaration(this,t):this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument?(c=this.parent)==null||c.removeInputDeclaration(this,t):this.parentRelationType===L.ReturnedError&&(this.parent.error=null):((T=this.parent)==null?void 0:T.type)===n.Loop?this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(I=this.parent)==null||I.removeOutputDeclaration(this,t):this.parentRelationType===L.ReturnedError&&(this.parent.error=null):this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(D=this.parent)==null||D.removeOutput(this,t):(this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this,t))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){var o,d,u,f,c,T,I;const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(D=>{const{updated:P,removed:C,added:M}=D.entity.onDetachedDependencyRestored(this,D.field,e);i.push(...P),s.push(...C),t.push(...M)}),this.defaultValue){const{updated:D}=this.defaultValue.restore({},e);i.push(...D)}if(this.dataType){const{updated:D}=this.dataType.restore({},e);i.push(...D)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(d=this.parent)==null||d.addOutputDeclaration(this,e):(this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument)&&((u=this.parent)==null||u.addInputDeclaration(this,e)):((f=this.parent)==null?void 0:f.type)===n.Loop?(this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn)&&((c=this.parent)==null||c.addOutputDeclaration(this,e)):this.parentRelationType===L.FixedReturns||this.parentRelationType===L.DynamicReturn?(T=this.parent)==null||T.addOutput(this,e):(this.parentRelationType===L.FixedArguments||this.parentRelationType===L.DynamicArgument)&&((I=this.parent)==null||I.addInput(this,e)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,parent:((s=this.parent)==null?void 0:s.toReference())||null})}toJSONClone(e=W){var i,s,l,o,d,u,f,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((f=this.dataType)==null?void 0:f.toJSONClone({...e,newId:null}))||null,parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=q1(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,D;if(Array.from(new Set([...Gi(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=i||m.UUID.uuid(),u=this.toJSON();u.id=d,u.version=m.UUID.uuid(),u.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),u.author=(e==null?void 0:e.author)||"1",u.previousVersion=null,u.deleted=!1;const f=st(u,o);t&&f.setParent(t,null),e==null||e.add(f,A.Added),s&&f.subscribe();const c=((I=this.dataType)==null?void 0:I.clone(e,f,m.UUID.uuid(),s))||null;c&&f.setDataType(c);const T=(D=this.defaultValue)==null?void 0:D.clone(e,f,m.UUID.uuid(),s);return f.defaultValue=T||null,e==null||e.attemptAutoclose("clone-entity",this.id),f}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-data-type"))){return e==null||e.attemptAutoclose("get-data-type",this.id),this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}implementAsReturnDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-return-declaration")),t,i){const s=ri.new(e);s.id=i||s.id,s.name=this.name,s.description=this.description,s.parent=t.toReference(),s.implements=this.toJSON(),s.isError=this.parentRelationType===L.ReturnedError;const l=st(s,this.project);if(l.hydrateAncestors(),l.addSelfToProject(e),e==null||e.add(l,A.Added),l.initChildren(e),this.dataType){const o=this.dataType.clone(e,l);l.setDataType(o)}if(this.defaultValue){const o=this.defaultValue.clone(e,l);l.setDefaultValue(o)}return e==null||e.attemptAutoclose("implement-as-return-declaration",this.id),l}implementAsArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-as-return-declaration")),t,i){const s=br.new(e);s.id=i||s.id,s.name=this.name,s.description=this.description,s.parent=t.toReference(),s.implements=this.toJSON();const l=st(s,this.project);if(l.hydrateAncestors(),l.addSelfToProject(e),e==null||e.add(l,A.Added),l.initChildren(e),this.dataType){const o=this.dataType.clone(e,l);l.setDataType(o)}if(this.defaultValue){const o=this.defaultValue.clone(e,l);l.setDefaultValue(o)}return e==null||e.attemptAutoclose("implement-as-return-declaration",this.id),l}};h(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Ue,"type",n.ValueDescriptor),h(Ue,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),h(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),h(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),h(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),h(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),h(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"index"]),h(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),h(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),h(Ue,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),h(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),h(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let ir=Ue;function fW(r,a){if(!r.type&&!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:O.Error,code:R.MissingTypeProperty,issue:null}),new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:O.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null};if(r.type){if(!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:`Last generated entity, with type "${r.type}" is missing an 'id' property.`,severity:O.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new w({id:`${r.id}--${R.MissingTypeProperty}`,message:`Entity with id "${r.id}" is missing a 'type' property.`,severity:O.Error,code:R.MissingTypeProperty,issue:null})],modifiedData:null};if(r.type===n.GenericReference)return{errors:[new w({id:`${r.id}--${R.RootReference}`,message:`Generic reference entity with id "${r.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:O.Error,code:R.RootReference,issue:null})],modifiedData:null};const e=r,t=a.instances[e.id],i=a.builtInInstances[e.id];if(t&&!i&&e.type!==n.GenericReference){let s=`A previously generated entity with id "${e.id}" already exists in the project state.
|
|
208
208
|
Are you trying to update that entity?
|
|
209
209
|
If so, you should use the 'update' action for core mutable metadata properties, or 'delete' and then 'post' again to replace it.
|
|
210
210
|
If you are trying to create a new entity, please use a different id, for example: "${Vc(e,a)}".`;return{errors:[new w({id:`duplicate--${e.id}--${R.EntityIdNotUnique}`,message:s,severity:O.Error,code:R.EntityIdNotUnique,issue:null})],modifiedData:r}}else if(t&&e.type!==n.GenericReference)return{errors:[new w({id:`${e.id}--${R.EntityIdNotUnique}`,message:`A built in entity with id "${e.id}" already exists. You cannot modify built in entities. If you are trying to create a new entity, please use a different id, for example: "${Vc(e,a)}".`,severity:O.Error,code:R.EntityIdNotUnique,issue:null})],modifiedData:r};switch(e.type){case n.Project:return m.validateGenerationTarget(e,a);case n.DefinitionEntity:return dn.validateGenerationTarget(e,a);case n.Property:return xr.validateGenerationTarget(e,a);case n.FunctionDeclaration:return kr.validateGenerationTarget(e,a);case n.DataType:return Zr.validateGenerationTarget(e,a);case n.Operation:return qr.validateGenerationTarget(e,a);case n.FunctionCall:return an.validateGenerationTarget(e,a);case n.VariableDeclaration:return Hr.validateGenerationTarget(e,a);case n.VariableInstance:return Yr.validateGenerationTarget(e,a);case n.GlobalEvent:return Wr.validateGenerationTarget(e,a);case n.InputMap:return er.validateGenerationTarget(e,a);case n.OutputMap:return tr.validateGenerationTarget(e,a);case n.ArgumentDeclaration:return br.validateGenerationTarget(e,a);case n.ReturnDeclaration:return ri.validateGenerationTarget(e,a);case n.Loop:return Sr.validateGenerationTarget(e,a);case n.Condition:return zr.validateGenerationTarget(e,a);case n.Search:return Kr.validateGenerationTarget(e,a);case n.InstalledProject:return Xr.validateGenerationTarget(e,a);case n.InternalCall:return Qr.validateGenerationTarget(e,a);case n.LiteralValue:return en.validateGenerationTarget(e,a);case n.ReturnStatement:return Jr.validateGenerationTarget(e,a);case n.BreakStatement:return tn.validateGenerationTarget(e,a);case n.ContinueStatement:return Gt.validateGenerationTarget(e,a);case n.ActionDescriptor:return We.validateGenerationTarget(e,a);case n.ValueDescriptor:return ir.validateGenerationTarget(e,a);case n.BuiltInBaseEntity:case n.PrimitiveEntity:{const s="Did you mean to generate a",o={[n.BuiltInBaseEntity]:`${s} '${n.DefinitionEntity}' instead?`,[n.PrimitiveEntity]:`${s} '${n.DefinitionEntity}' instead?`}[e.type]||"";return{errors:[new w({id:`${e.id}--${R.BuiltInEntityGenerated}`,message:`Entity with id "${e.id} is of "${e.type}" type and should not be generated. Built in entities can only be referenced by user created entities.
|
|
@@ -402,7 +402,7 @@ All global 'function-declaration' entity ids are:
|
|
|
402
402
|
The project currently has no global 'function-declaration' entities that can be called as 'function-call' entities.`;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:O.Error,message:`Entity of type "${n.FunctionCall}" with id "${i.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'function-declaration' entity.
|
|
403
403
|
References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${d}`,issue:null}))}return{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),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&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Je(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Je(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:T}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...T),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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=B(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Je.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Je.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=nP(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(T=>T.declaration.id===c.id));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(T=>{const I=V(T,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(T=>!this.outputs.find(I=>I.declaration.id===T.id));this.outputs.sort((T,I)=>T.index-I.index),d.forEach((T,I)=>{this.outputs.forEach(M=>{M.index>=T.index&&M.index++});const D=o.includes(T.index)?this.outputs.length-1+I:T.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:T.toJSON(),defaultValue:null,writesValues:[],index:D,parent:this.toReference()},C=V(P,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,A.Added),C.addSelfToProject(e)}),this.outputs.sort((T,I)=>T.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(Je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Je,"type",n.FunctionCall),h(Je,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Je,"PARENT_TYPES",[...Je.USER_MANAGED_PARENT_TYPES]),h(Je,"MUTABLE_BASE_PROPERTIES",[]),h(Je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Je,"BASE_PROPERTIES",[...Je.MUTABLE_BASE_PROPERTIES,...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"MUTABLE_META_PROPERTIES",["x","y"]),h(Je,"INMUTABLE_META_PROPERTIES",[...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"META_PROPERTIES",[...Je.MUTABLE_META_PROPERTIES,...Je.INMUTABLE_META_PROPERTIES]),h(Je,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Je,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Je,"UPSTREAM_PROPERTIES",[...Je.MUTABLE_UPSTREAM_PROPERTIES,...Je.INMUTABLE_UPSTREAM_PROPERTIES]),h(Je,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),h(Je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Je,"DOWNSTREAM_PROPERTIES",[...Je.MUTABLE_DOWNSTREAM_PROPERTIES,...Je.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Je,"PROPERTIES",[...Je.META_PROPERTIES,...Je.UPSTREAM_PROPERTIES,...Je.DOWNSTREAM_PROPERTIES]);let an=Je;function Jc(r){return r&&typeof r.then=="function"}class zl{constructor(a){h(this,"order",[]);h(this,"flatRecord",{});h(this,"allBuiltInEntityIds",Gi());h(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(Gi()),t=p(j(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Ql(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Ql(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Ql(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Jc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Jc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function aP(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var f;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=u.getDefaultValue())==null?void 0:f.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),f=u==null?void 0:u.defaultValue;if(f)f.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:N.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},T=V(c,r.project);return T.setParent(u==null?void 0:u.dataType,a),T.initChildren(a),a==null||a.add(T,A.Added),T.addSelfToProject(a),{newEntities:[T]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=Yl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:N.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=V(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,A.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function oP(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let f=r.project.entities.filter(I=>I.implements.find(D=>D.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(I=>!!I.properties.find(D=>{var P;return D.implements&&D.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=D.getDefaultValue())==null?void 0:P.value)===!0}));if(!f){f=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const D=f.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=D==null?void 0:D.defaultValue)==null||d.metaSync({value:!0},a),t.push(f)}const c=r.properties.find(I=>I.implements&&I.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),T=c==null?void 0:c.defaultValue;if(c&&!T){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:N.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:f,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},D=V(I,r.project);D.hydrateAncestors(),D.setParent(c,a),D.addSelfToProject(a),D.initChildren(a),a==null||a.add(D,A.Added),t.push(D);return}else T&&T.setValueAsTypeSingle(f,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function Yl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r.toJSON()],x:0,y:0,parent:r.project.toReference()};aP(r,e);const o=V(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,A.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),oP(o,e),o}function Wc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function lP(r,a,e,t=wt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},f=V(u,r.project);return s.push(f),f.setParent(a,e),f.initChildren(e),e==null||e.add(f,A.Added),f.setEntity(r),f.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:f}}function Sc(r,a,e,t,i){var u,f,c,T,I,D,P,C;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const G=new Date(r);if(G instanceof Date&&!isNaN(G.valueOf())&&(M=!0),M){const _=a.project.getBuiltIn(k[n.PrimitiveEntity][N.Date].id);a.setEntity(_);break}else{const _=a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id);a.setEntity(_);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const _=r.slice(0,5).filter(q=>q!==void 0);if(_.every(q=>typeof q==typeof _[0])&&(typeof _[0]!="object"||_[0]===null))switch(typeof _[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else{const q=[];let S=!1;_.forEach(de=>{var me,z,oe,Ft;if(Array.isArray(de)&&(S=!0),typeof de=="object"&&!Array.isArray(de)&&de!==null){const nr=Hl(de,a.project,{...e,id:m.UUID.uuid()},t,i);nr.hasCreated&&q.push((me=nr.changeSet)==null?void 0:me.self),s.push(...(z=nr.changeSet)==null?void 0:z.updated),l.push(...(oe=nr.changeSet)==null?void 0:oe.added),o.push(...(Ft=nr.changeSet)==null?void 0:Ft.removed)}});const K=p(q);if(!K.length&&!S){_.forEach(de=>{const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:wt.OrDataTypeGroup,parent:a.toReference()},z=V(me,a.project);switch(z.setParent(a,t),z.initChildren(t),t==null||t.add(z,A.Added),z.addSelfToProject(t),typeof de){case"string":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}});break}else K.length===1&&!S?a.setEntity(K[0]):_.forEach(de=>{if(typeof de=="object"&&!Array.isArray(de)&&de!==null){const me=Wc(Object.keys(de),a.project);if(me){const z=lP(me||K[0],a,t,wt.OrDataTypeGroup);s.push(...z.updated),l.push(...z.added),o.push(...z.removed)}}else{const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(de),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:wt.OrDataTypeGroup,parent:a.toReference()},z=V(me,a.project);z.setParent(a,t),z.initChildren(t),t==null||t.add(z,A.Added),z.addSelfToProject(t);const oe=Sc(de,z,{...e,id:m.UUID.uuid()},t,i);s.push(...oe.updated),l.push(...oe.added),o.push(...oe.removed)}})}}else{const _=Hl(r[0],a.project,{...e},t,i);a.setEntity((u=_.changeSet)==null?void 0:u.self),s.push(...(f=_.changeSet)==null?void 0:f.updated),l.push(...(c=_.changeSet)==null?void 0:c.added),o.push(...(T=_.changeSet)==null?void 0:T.removed);break}else{const _=Hl(r,a.project,{...e},t,i);a.setEntity((I=_.changeSet)==null?void 0:I.self),s.push(...(D=_.changeSet)==null?void 0:D.updated),l.push(...(P=_.changeSet)==null?void 0:P.added),o.push(...(C=_.changeSet)==null?void 0:C.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Hl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),f=Wc(u,a);if(f)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:f}};const c=i?e.name+" of "+i.name:e.name,I={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},D=V(I,a);return D.setParent(a,t),D.initChildren(t),t==null||t.add(D,A.Added),D.addSelfToProject(t),l.push(D),u.forEach((P,C)=>{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,extends:null,index:C,hidden:!1,private:!1,required:!0,parent:D.toReference()},_=V(G,a);_.setParent(D,t),_.initChildren(t),t==null||t.add(_,A.Added),_.addSelfToProject(t),l.push(_);const g=r[P],S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:_.toReference()},K=V(S,a);K.setParent(_,t),K.initChildren(t),t==null||t.add(K,A.Added),K.addSelfToProject(t),l.push(K);const de=Sc(g,K,{...e,name:P,id:m.UUID.uuid()},t,i||D);s.push(...de.updated),l.push(...de.added),o.push(...de.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:D}}}function Dr(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,f;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((f=s.implements)==null?void 0:f.id)});if(l){const d=new Ye({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:O.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new Ye({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:O.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var f,c;return!!u.implements&&((f=u.implements)==null?void 0:f.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new Ye({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:O.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new Ye({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:O.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function PW(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Bc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function wW(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===sd.Implements||t.field===sd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function CW(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function VW(r,a){return r.static&&r.metaSync({static:!1},a),r}var dP=(r=>(r.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",r.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",r))(dP||{});function uP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s/g,"-")}}function pP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}if(t.includes("-")){const i=new Ye({id:r.id+"--string-value-must-not-have-dashes",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-dashes",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s|-/g,"_")}}function _s(r,a){const e=gn(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=_s(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function zc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=zt(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||_s(s,t).last?s:(_s(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function Q(r,a){var i,s;let e=zc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!ht.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(ot.includes(r.type))return;Te(r).forEach(l=>{var d,u;const o=zc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!ht.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function cP(r,a,e=new Set){const t=on(r),i=on(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...cP(u,a,e)])),[]);return p([...l,...o])}function Ua(r,a){const e=_s(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function _W(r,a){return!!_s(r,a).last}function BW(r){if(rt.includes(r.type))return r;if([...xi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return rt.includes(a.type)?a:null}return null}function Yc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return Yc(e,t)}function Rt(r){if(Ha.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return Rt(a);if(a.type===n.Loop)return a}return r.type===n.DefinitionEntity&&r.parent.type===n.DataType?Rt(r.parent):r}else{const a=r.parent;return a?Rt(a):null}}function Kl(r,a){const e=$a(r,a);if(!e)return null;if(Ha.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=$a(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?$a(e.parent,a):null;return t?Kl(t,a):null}}function fP(r){if(!r)return null;if(xi.includes(r.type))return r;const a=r.parent;return a?fP(a):null}function hP(r){if(!r)return null;if(dt.includes(r.type))return r;const a=r.parent;return a?hP(a):null}function yP(r){if(!r)return null;if(ki.includes(r.type))return r;const a=r.parent;return a?yP(a):null}function MW(r){return r.type===n.VariableDeclaration?[r]:dt.includes(r.type)?[...r.inputs,...r.outputs||[]]:ot.includes(r.type)?r.outputs:qn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function NW(r){const a=on(r),e=[],t=[];pf.includes(r.type)&&e.push(...Hc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:xi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>Ua(l,s)?-1:0),t.sort((s,l)=>Ua(l,s)?-1:0),[...e,...t,...i]}function mP(r){return[...r].sort((a,e)=>Ua(e,a)?-1:0)}function LW(r){const a=mP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];Ua(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function gt(r){const a=r.map(e=>Rt(e));return p(a)}function Hc(r){return dt.includes(r.type)?[...gt(r.successCalls),...gt(r.errorCalls)]:rt.includes(r.type)?gt(r.calls):[]}function jW(r,a){return Hc(r).includes(a)}function Kc(r){return r.writesValues||[]}function UW(r,a){return Kc(r).includes(a)}function vP(r){var a;return it.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function $W(r){return r.writesValues}function EP(r=[]){return r.map(vP).filter(a=>!!a)}function Xl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>it.includes(a.type))}function TP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&it.includes(a.type))}function IP(r){return it.includes(r.type)?r:null}function AP(r){return r.writesValues.map(IP).filter(a=>!!a)}function bP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...AP(e)]:a,[])}function Te(r){return r.type===n.Loop?p([...Vi(gt(r.successCalls)),...Vi(gt(r.errorCalls)),...r.body?Te(r.body):[]]):dt.includes(r.type)?p([...Vi(gt(r.successCalls)),...Vi(gt(r.errorCalls))]):rt.includes(r.type)?p(Vi(gt(r.calls))):[]}function GW(r){return dt.includes(r.type)?[...Vi(gt(r.successCalls)),...Vi(gt(r.errorCalls))]:rt.includes(r.type)?Vi(gt(r.calls)):[]}function RP(r,a=new Set){return r.writesValues.filter(t=>it.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...He(i,a)],[])}function DP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>it.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...He(s,a)],[])}function He(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return TP(r.outputs).reduce((t,i)=>[...t,...He(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Te(r).reduce((s,l)=>{const o=Rt(l);return[...s,...He(o||l,a)]},[]),...EP(r.inputs),...bP(r.outputs)].reduce((s,l)=>[...s,...He(l,a)],[]);if(qn.includes(r.type)){const e=Xl(r.inputs),i=Te(r).reduce((s,l)=>{const o=Rt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Xl(r.inputs)],i=Te(r).reduce((s,l)=>{const o=Rt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l)],[])}if(it.includes(r.type)){a.add(r.id);const t=Te(r).reduce((i,s)=>{const l=Rt(s);return[...i,...He(l||s,a)]},[]);return[r,...t,...DP(r,a),...RP(r,a)]}return[]}function ci(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...on(r).reduce((i,s)=>[...i,s,...ci(s,a)],[])])}function Vi(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Te(e)],[])}function OP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Xl(u.inputs),...Vi(gt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Vi(gt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Vi(gt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function PP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return dt.includes(r.type)?ew(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function gW(r){const a=OP(r.project);return PP(r,a)}function $a(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Ql(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(si.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,f=r,c=r,T=r,I=r,D=r,P=r,C=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(D.calledByEntry||[]).flatMap(g=>g),...(D.calledBySuccess||[]).flatMap(g=>g),...(D.calledByError||[]).flatMap(g=>g),...T.parent?[T.parent]:[]];Array.isArray(s.implements)?C.push(...s.implements.flatMap(g=>g)):c.implements&&C.push(c.implements),Array.isArray(s.extends)?C.push(...s.extends.flatMap(g=>g)):c.extends&&C.push(c.extends),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&C.push(...o.valueAsTypeList.flatMap(g=>g)),o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(g=>g),...(I.inputsDeclarations||[]).flatMap(g=>g),...(t.outputs||[]).flatMap(g=>g),...(I.outputsDeclarations||[]).flatMap(g=>g),...(P.internalCalls||[]).flatMap(g=>g),...P.writesValues||[],...D.dataType?[D.dataType]:[],...d.body?[d.body]:[],...D.defaultValue?[D.defaultValue]:[],...(D.successCalls||[]).flatMap(g=>g),...(D.errorCalls||[]).flatMap(g=>g),...(s.properties||[]).flatMap(g=>g),...(s.methods||[]).flatMap(g=>g),...(s.abstractMethods||[]).flatMap(g=>g),...u.error?[u.error]:[],...u.process?[u.process]:[],...T.throws?[T.throws]:[],...(i.andChildrenGroup||[]).flatMap(g=>g),...(i.orChildrenGroup||[]).flatMap(g=>g),...(f.entities||[]).flatMap(g=>g),...(f.functions||[]).flatMap(g=>g),...(f.functionCalls||[]).flatMap(g=>g),...(f.events||[]).flatMap(g=>g),...(f.conditions||[]).flatMap(g=>g),...(f.operations||[]).flatMap(g=>g),...(f.loops||[]).flatMap(g=>g),...(f.variableDeclarations||[]).flatMap(g=>g),...(f.variableInstances||[]).flatMap(g=>g),...(f.searches||[]).flatMap(g=>g),...(f.projects||[]).flatMap(g=>g),...(l.calls||[]).flatMap(g=>g)];r.type===n.DataType&&(i.entity&&a[B(i.entity)]&&a[B(i.entity)].parent&&B(a[B(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&C.push(i.entity));const G={},_={};return C.forEach(g=>{const q=B(g);if(q&&e.ignoreBuiltInBaseEntities&&(si.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(G[q]=S)}),M.forEach(g=>{const q=B(g);if(q&&e.ignoreBuiltInBaseEntities&&(si.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(_[q]=S)}),{upstream:G,downstream:_}}function FW(r,a){const e=[];if(xi.includes(r.type)){Ai(r).forEach(s=>{const l=Kl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=$a(s,a);return l?iw(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(it.includes(r.type)){const t=ed(r);t&&e.push(t)}return p(e)}function gn(r){const a=[];if(xi.includes(r.type)){r.calledBy.forEach(i=>{const s=Rt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>ed(i)).filter(i=>i!==null);a.push(...p(t))}if(it.includes(r.type)){const e=ed(r);e&&a.push(e)}return p(a)}function Ai(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>j(t,a,e)),...r.outputs.flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.parent?j(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a):[],...r.writesValues.flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...(r.extends||[]).flatMap(t=>j(t,a,e))]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>j(t,a,e)),...(r.implements||[]).flatMap(t=>j(t,a,e)),...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>j(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>j(t,a,e)),...r.entity?j(r.entity,a,e):[],...r.parent?j(r.parent,a,e):[]]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.parent?j(r.parent,a,e):[]]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?j(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>j(t,a,e)):[],...r.parent?j(r.parent,a,e):[]]}function kP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.body?j(r.body,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function ZP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function qP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function JP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e))]}function WP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>j(t,a,e)),...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.variableInstances||[]).flatMap(t=>j(t,a,e)),...(r.operations||[]).flatMap(t=>j(t,a,e)),...(r.conditions||[]).flatMap(t=>j(t,a,e)),...(r.functionCalls||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.loops||[]).flatMap(t=>j(t,a,e)),...(r.searches||[]).flatMap(t=>j(t,a,e))]}function SP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function zP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function YP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function HP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function KP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function XP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function QP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.parent?j(r.parent,a,e):[]]}function Gi(){const r=new Set,a=hI.flatMap(e=>j(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function j(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(si.includes(r.type)||Gi().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return jP(r,a,e);case n.Operation:return ZP(r,a,e);case n.Condition:return BP(r,a,e);case n.Loop:return kP(r,a,e);case n.Search:return HP(r,a,e);case n.GlobalEvent:return $P(r,a,e);case n.ReturnStatement:return YP(r,a,e);case n.ContinueStatement:return MP(r,a,e);case n.BreakStatement:return VP(r,a,e);case n.VariableDeclaration:return XP(r,a,e);case n.DefinitionEntity:return NP(r,a,e);case n.FunctionDeclaration:return UP(r,a,e);case n.Project:return WP(r,a,e);case n.ActionDescriptor:return wP(r,a,e);case n.ArgumentDeclaration:return CP(r,a,e);case n.ReturnDeclaration:return zP(r,a,e);case n.ValueDescriptor:return KP(r,a,e);case n.InputMap:return GP(r,a,e);case n.OutputMap:return qP(r,a,e);case n.DataType:return LP(r,a,e);case n.InstalledProject:return gP(r,a,e);case n.InternalCall:return FP(r,a,e);case n.LiteralValue:return xP(r,a,e);case n.Property:return SP(r,a,e);case n.VariableInstance:return QP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:_P(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:JP(r,a,e)}return[]}function Xc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||qn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function xW(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function ew(r){return dt.includes(r.type)?r.inputs:[]}function tw(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:ot.includes(r.type)?r.outputs:[]}function kW(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function ZW(r){return r.type===n.Condition?[]:dt.includes(r.type)?r.outputs:[]}function ed(r){const a=r.readsValue;return a?Rt(a):null}function iw(r,a){const e=r.readsValue;return e?Kl(e,a):null}function rw(r){const a=r.internalCalls||[];return p(gt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Bs(r){const a=Kc(r),e=[];return a.forEach(t=>{if(it.includes(t.type))e.push(t);else if(Pr.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function on(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),ht.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:on(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>Rt(s)),i=r.errorCalls.map(s=>Rt(s));e.push(...t,...i)}if(qn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Bs(s)).flat(),i=r.calls.map(s=>Rt(s));e.push(...p(t),...i)}if(dt.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Bs(l)).flat(),i=r.successCalls.map(l=>Rt(l)),s=r.errorCalls.map(l=>Rt(l));e.push(...p(t),...i,...s)}if(it.includes(r.type)){const t=Bs(r),i=rw(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Bs(l)).flat();if(r.body){const l=on(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>Rt(l)),s=r.successCalls.map(l=>Rt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Bs(s)).flat(),i=r.calls.map(s=>Rt(s));e.push(...p(t),...i)}return p(e)}function nw(r,a=!1){const e=on(r,a),t=[...e,...e.reduce((i,s)=>[...i,...nw(s,a)],[])];return p(t)}function sw(r){const a=gn(r),e=[...a,...a.reduce((t,i)=>[...t,...sw(i)],[])];return p(e)}function Ga(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Ga(e),...ga(e)]:[...a,e.name],[])}function ga(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...ga(e),...Ga(e)]:[...a,e.name],[])}function Qc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Qc(e),...ef(e)]:[...a,e],[])}function ef(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...ef(e),...Qc(e)]:[...a,e],[])}function tf(r){return[...ga(r),...Ga(r)].filter((e,t,i)=>i.indexOf(e)===t)}function aw(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===J.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=aw(i);if(s)return s}return t},null)}function qW(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function JW(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function ow(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function St(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...St(t)]:e,[]);return p(a)}function Fa(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!St(r).find(t=>!t.interactive)}function WW(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function rf(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function lw(r){if([...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||rf(r))return!1;const a=gn(r);return a.length===0?!0:a.some(e=>lw(e))}function nf(r){return[...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||rf(r)?!1:gn(r).length===0}function dw(r,a=0){if(nf(r)){const e=gn(r);return e.length===0?r:e.map(i=>dw(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function uw(r){const a=[];if(nf(r))a.push(r);else return[];return gn(r).forEach(t=>{a.push(...uw(t))}),a}function pw(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function SW(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function xa(r){switch(r){case n.DefinitionEntity:return dn;case n.FunctionDeclaration:return kr;case n.VariableDeclaration:return Hr;case n.VariableInstance:return Yr;case n.FunctionCall:return an;case n.Operation:return qr;case n.Condition:return zr;case n.ReturnStatement:return Jr;case n.Loop:return Sr;case n.Search:return Kr;case n.InputMap:return er;case n.OutputMap:return tr;case n.ArgumentDeclaration:return br;case n.ReturnDeclaration:return ri;case n.Property:return xr;case n.InstalledProject:return Xr;case n.Project:return m;case n.DataType:return Zr;case n.GlobalEvent:return Wr;case n.InternalCall:return Qr;case n.ValueDescriptor:return ir;case n.BuiltInBaseEntity:return Fi;case n.PrimitiveEntity:return ni;case n.ActionDescriptor:return We;case n.LiteralValue:return en;case n.ContinueStatement:return Gt;case n.BreakStatement:return tn;default:return null}}function zt(r,a,e=null){const t=r!=null&&r.parent?B(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.ReturnStatement)return It(r,a,s);if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return i;if(rt.includes(r.type))return r;if(r.type===n.Loop)return s.id===r.id?i:r;if(si.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=B(l);if(!o)return null;const d=a.get(o);return d?zt(d,a,s):null}else return l===a?a:zt(l,a,s)}function It(r,a,e=null){const t=r!=null&&r.parent?B(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return It(i.parent,a,s);if(rt.includes(r.type))return r;if(si.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=B(l);if(!o)return null;const d=a.get(o);return d?It(d,a,s):null}else return l===a?a:It(l,a,s)}function sf(r,a){if(si.includes(r.type)||a.getBuiltIn(r.id))return null;const e=bi(r.parent,a);return e?e===a?ht.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:sf(e,a):null}function td(r,a,e){if(r===a||a===e||r===e)return!1;const t=zt(a.parent,e);return t===r?!0:td(t,a,e)}var id=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(id||{});function ka(r,a,e){const t=zt(r,e),i=zt(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(td(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(td(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=Yc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:zt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function cw(r,a,e){const t=ka(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=zt(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=zt(i.parent,e)}let s=zt(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=zt(s.parent,e)}return null}function fw(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=cw(e,t,t.project);return!i||i===t?e:t},r[0])}function bi(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=B(r):e=r.id,e===a.id?a:a.get(e)}function ln(r){if(!r)return null;if(si.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:ln(a)}function Za(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=sf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Te(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Za(o);d.reachable||Te(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Te(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Za(o);d.reachable||Te(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Te(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=Rt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=Za(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function zW(r){return Ha.includes(r.type)?r.type===n.FunctionDeclaration?!pw(r):!0:!1}function YW(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function rd(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ga(r).includes(a)}function HW(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Ga(r).includes(a)}function gi(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!tf(r).includes(a)}function KW(r){const a=[];return r.entities.forEach(e=>{if(rd(e,J.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function XW(r){const a=[];return r.entities.forEach(e=>{if(rd(e,J.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function QW(r){return r.type!==n.DefinitionEntity||r.abstract||!rd(r,J.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][J.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function eS(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!gi(r,J.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][J.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function tS(r){var e;if(!r||r.type!==n.DefinitionEntity||!gi(r,J.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][J.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!ff.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function iS(r){switch(r){case n.Project:return m;case n.InstalledProject:return Xr;case n.DefinitionEntity:return dn;case n.FunctionDeclaration:return kr;case n.GlobalEvent:return Wr;case n.VariableInstance:return Yr;case n.VariableDeclaration:return Hr;case n.InputMap:return er;case n.OutputMap:return tr;case n.Condition:return zr;case n.Operation:return qr;case n.FunctionCall:return an;case n.ReturnDeclaration:return ri;case n.ArgumentDeclaration:return br;case n.PrimitiveEntity:return ni;case n.DataType:return Zr;case n.Property:return xr;case n.ActionDescriptor:return We;case n.ReturnStatement:return Jr;case n.ContinueStatement:return Gt;case n.BreakStatement:return tn;case n.Loop:return Sr;case n.Search:return Kr;case n.ValueDescriptor:return ir;case n.InternalCall:return Qr;case n.LiteralValue:return en}return null}function rS(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function pt(r,a){const e=xa(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function nd(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=B(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...nd(t,a)]:[]}function nS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=Rt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function sS(r){if(r.type===n.Condition)return null;if(r.type===n.Search)return r.project.getBuiltIn(k["value-descriptor"][Jn.SearchErrorOutputDescriptor].id)||null;if(r.type===n.Operation)return r.declaration.error;if(r.type===n.FunctionCall){const e=r.declaration.returnStatements.find(t=>!!t.throws);return(e==null?void 0:e.throws)||null}return null}function hw(r){const a=Nq(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(f=>aS(r,f)),s=r.extends.flatMap(f=>oS(r,f)),l=dS(r),o=lS(r);r.methods.flatMap(f=>f.validate());const d=[...i,...s,...l,...o];return Ke(r.errors,d)}function yw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function mw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function aS(r,a){const e=[];if(!a.abstract){const f=fe({id:r.id+"--"+x.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.ImplementingNonAbstractEntity,entity:r});return e.push(f.error),e}const t=a.properties.filter(f=>f.abstract),i=[];let s=[...r.properties];t.forEach(f=>{const c=s.find(T=>{var I;return((I=T.implements)==null?void 0:I.id)===f.id});c?s=s.filter(T=>T.id!==c.id):i.push(f)}),i.length&&i.forEach(f=>{const c=fe({id:r.id+"--"+x.MissingPropertyImplementation+"--"+f.id,message:`Property "${f.name}" with id "${f.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:O.Error,code:x.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(f=>{const c=o.find(T=>{var I;return((I=T.implements)==null?void 0:I.id)===f.id});c?o=o.filter(T=>T.id!==c.id):l.push(f)}),l.length&&l.forEach(f=>{const c=fe({id:r.id+"--"+x.MissingMethodImplementation+"--"+f.id,message:`Method "${f.name}" with id "${f.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:O.Error,code:x.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(f=>{const c=s.find(T=>T.name===f.name);c&&d.push([c,f])}),d.length&&d.forEach(([f])=>{const c=fe({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Property "${f.name}" with id "${f.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(f=>{const c=o.find(T=>T.name===f.name);c&&u.push([c,f])}),u.length&&u.forEach(([f])=>{const c=fe({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Method "${f.name}" with id "${f.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function oS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=fe({id:r.id+"--"+a.id+"--"+x.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=fe({id:r.id+"--"+a.id+"--"+x.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>{var u;return d.name===s.name&&((u=s.extends)==null?void 0:u.id)!==d.id});((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=fe({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>{var u;return d.name===s.name&&((u=s.extends)==null?void 0:u.id)!==d.id});((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=fe({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function lS(r){const a=[];if(!r.properties.length){const e=fe({id:r.id+"--"+x.NoProperties,message:"No properties implemented",issue:null,severity:O.Warning,code:x.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function dS(r){const a=[];if(r.abstract){if(r.methods.length){const e=fe({id:r.id+"--"+x.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:O.Error,code:x.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=fe({id:r.id+"--"+x.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:O.Error,code:x.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=fe({id:r.id+"--"+x.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:O.Error,code:x.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=fe({id:r.id+"--"+x.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:O.Error,code:x.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}r.properties.some(e=>e.abstract)&&r.properties.forEach(e=>{if(e.abstract){const t=fe({id:r.id+"--"+x.AbstractPropertyInNonAbstractEntity+"--"+e.id,message:`Property "${e.name}" with id "${e.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:O.Error,code:x.AbstractPropertyInNonAbstractEntity,entity:r,firstRelationship:e});a.push(t.error)}})}return r.static&&r.properties.some(e=>!e.static)&&r.properties.forEach(e=>{if(!e.static){const t=fe({id:r.id+"--"+x.NonStaticPropertyInStaticEntity+"--"+e.id,message:`Property "${e.name}" with id "${e.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:O.Error,code:x.NonStaticPropertyInStaticEntity,entity:r,firstRelationship:e});a.push(t.error)}}),a}function uS(r,a){const e=[],t=St(a);if(!a.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+x.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+x.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+x.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+x.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new Ye({id:r.id+"--"+d.id+"--"+l.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{St(l).forEach(f=>{const c=t.filter(T=>T.id!==f.id);c.length&&c.forEach(T=>{if(T.id!==f.id){const I=new Ye({id:r.id+"--"+T.id+"--"+f.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${T.name}" with id "${T.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:T,secondRelationship:f});e.push(I)}})});const d=Dr(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=Dr(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>St(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new Ye({id:r.id+"--"+a.id+"--"+l.id+"--"+x.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function pS(r,a,e=!1){const t=[],i=St(a);if(!r.abstract&&a.abstract){const f=fe({id:r.id+"--"+a.id+"--"+x.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.abstract&&!a.abstract){const f=fe({id:r.id+"--"+a.id+"--"+x.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!r.static&&a.static){const f=fe({id:r.id+"--"+a.id+"--"+x.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.static&&!a.static){const f=fe({id:r.id+"--"+a.id+"--"+x.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!Fa(a)){const f=fe({id:r.id+"--"+a.id+"--"+x.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(f.error)}const l=r.extends.filter(f=>f.id!==a.id);l.length&&l.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(T=>T.id!==f.id);c.length&&c.forEach(T=>{if(T.id!==f.id){const I=fe({id:r.id+"--"+T.id+"--"+f.id+"--"+x.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${T.name}" with id "${T.id}" but also extends entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ExtendsIncompatibleEntities,entity:r,firstRelationship:T,secondRelationship:f});t.push(I.error)}})}else{St(f).forEach(M=>{const G=i.filter(_=>_.id!==M.id);G.length&&G.forEach(_=>{if(_.id!==M.id){const g=new Ye({id:r.id+"--"+_.id+"--"+M.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${_.name}" with id "${_.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:_,secondRelationship:M});t.push(g)}})});const T=!!St(f).find(M=>M.id===a.id);let I=[...f.properties];T&&(I=I.filter(M=>!a.properties.find(G=>{var _;return G.id===M.id||G.name===M.name||G.id===((_=M.implements)==null?void 0:_.id)})));let D=[...f.methods];T&&(D=D.filter(M=>!a.methods.find(G=>{var _;return G.id===M.id||G.name===M.name||G.id===((_=M.implements)==null?void 0:_.id)})));const P=Dr(a.ownDeclaredProperties,I,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const C=Dr(a.abstractMethods,D,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...C.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(T=>T.id!==f.id);c.length&&c.forEach(T=>{if(T.id!==f.id){const I=new Ye({id:r.id+"--"+T.id+"--"+f.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${T.name}" with id "${T.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:T,secondRelationship:f});t.push(I)}})}else{St(f).forEach(D=>{const P=i.filter(C=>C.id!==D.id);P.length&&P.forEach(C=>{if(C.id!==D.id){const M=new Ye({id:r.id+"--"+C.id+"--"+D.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${C.name}" with id "${C.id}" but also implements entity "${D.name}" with id "${D.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:C,secondRelationship:D});t.push(M)}})});const T=Dr(a.ownDeclaredProperties,f.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...T.errors);const I=Dr(a.abstractMethods,[...f.abstractMethods,...f.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...I.errors)}});const o=Dr(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=Dr(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(f=>St(f))).forEach(f=>{if(!i.find(c=>c.id===f.id)){const c=new Ye({id:r.id+"--"+a.id+"--"+f.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:f});t.push(c)}}),t}function cS(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+x.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:O.Error,code:x.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+x.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:O.Error,code:x.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function fS(r){const a=[];if(r.implements.length){const e=new Ye({id:r.id+"--"+x.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:O.Error,code:x.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+x.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:O.Error,code:x.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function hS(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+x.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:O.Error,code:x.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function yS(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+x.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:O.Error,code:x.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const mS=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:mw,getBasePropertiesNotImplemented:yw,validate:hw,validateCanBecomeAbstract:fS,validateCanBecomeNonAbstract:yS,validateCanBecomeNonStatic:hS,validateCanBecomeStatic:cS,validateCanExtendEntity:pS,validateCanImplementEntity:uS},Symbol.toStringTag,{value:"Module"}));function vS(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var sd=(r=>(r.Extends="extends",r.Implements="implements",r))(sd||{});const $e=class $e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"static");h(this,"abstract");h(this,"type",n.DefinitionEntity);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"implements",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestedProperties",[]);h(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=B(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=V(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=vS(i,t),o=Rc(i,t);s.push(...l,...o,...ut(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
405
|
+
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}if(t==="parent"){const{updated:u,added:f,removed:c}=this.restore({},i);s.push(...u),l.push(...f),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){var e;return(e=this.parent)==null||e.unsubscribeDependents([{entity:this,field:"parent"}]),this.declaration.unsubscribeDependents([{entity:this,field:"declaration"}]),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&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Je(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Je(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=B(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:f,added:c,removed:T}=this.syncMissingFixedOutputs(e);return t.push(...o,...f),i.push(...d,...c),s.push(...u,...T),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&Q(this,t)),t==null||t.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&Q(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?!0:(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected),!1)),i&&Q(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated))),t==null||t.attemptAutoclose("set-parent",this.id),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().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=B(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=V(t,this.project);if(i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=V(t,this.project);if(i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type))i.setParent(this.parent.parent,null),i.initChildren(e);else if(i.type===n.ReturnStatement){const s=It(this,this.project);i.setParent(s,null),i.initChildren(e)}else i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e));return i}),this.inputs=this.initialData.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=V(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=V(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await Je.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await Je.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await Je.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await Je.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await Je.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await Je.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:f,removed:c,added:T}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...f),s.push(...c),l.push(...T)}),this.process){const{updated:u,removed:f}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}if(this.inputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.outputs.forEach(u=>{const{updated:f,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...f),s.push(...c)}),this.error){const{updated:u,removed:f}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=W){var i,s,l,o,d,u,f;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(f=this.error)==null?void 0:f.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=nP(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var D,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(D=this.inputs)==null?void 0:D.map((C,M)=>C.clone(e,c,f+"-input-map-"+M+"-id",s));c.inputs=T;const I=(P=this.outputs)==null?void 0:P.map((C,M)=>C.clone(e,c,f+"-output-map-"+M+"-id",s));return c.outputs=I,this.error&&(c.error=this.error.clone(e,c,f+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,f+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var f;return u.id===((f=o.declaration)==null?void 0:f.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(T=>T.declaration.id===c.id));this.inputs.sort((c,T)=>c.index-T.index),o.forEach(c=>{this.inputs.forEach(D=>{D.index>=c.index&&D.metaSync({index:D.index+1},e)});const T={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},I=V(T,this.project);I.setParent(this,e),I.initChildren(e),e==null||e.add(I,A.Added),I.addSelfToProject(e),i.push(I)}),this.inputs.sort((c,T)=>c.index-T.index);const{updated:d,added:u,removed:f}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...f),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(T=>{const I=V(T,this.project);return o.push(I.index),I.setParent(this,null),I.initChildren(e),I});const d=this.declaration.getUniqueReturnDeclarations().filter(T=>!this.outputs.find(I=>I.declaration.id===T.id));this.outputs.sort((T,I)=>T.index-I.index),d.forEach((T,I)=>{this.outputs.forEach(M=>{M.index>=T.index&&M.index++});const D=o.includes(T.index)?this.outputs.length-1+I:T.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:T.toJSON(),defaultValue:null,writesValues:[],index:D,parent:this.toReference()},C=V(P,this.project);C.setParent(this,e),C.initChildren(e),e==null||e.add(C,A.Added),C.addSelfToProject(e)}),this.outputs.sort((T,I)=>T.index-I.index);const{updated:u,added:f,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...f),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};h(Je,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(Je,"type",n.FunctionCall),h(Je,"USER_MANAGED_PARENT_TYPES",[...ht,n.Project]),h(Je,"PARENT_TYPES",[...Je.USER_MANAGED_PARENT_TYPES]),h(Je,"MUTABLE_BASE_PROPERTIES",[]),h(Je,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(Je,"BASE_PROPERTIES",[...Je.MUTABLE_BASE_PROPERTIES,...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"MUTABLE_META_PROPERTIES",["x","y"]),h(Je,"INMUTABLE_META_PROPERTIES",[...Je.INMUTABLE_BASE_PROPERTIES]),h(Je,"META_PROPERTIES",[...Je.MUTABLE_META_PROPERTIES,...Je.INMUTABLE_META_PROPERTIES]),h(Je,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),h(Je,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),h(Je,"UPSTREAM_PROPERTIES",[...Je.MUTABLE_UPSTREAM_PROPERTIES,...Je.INMUTABLE_UPSTREAM_PROPERTIES]),h(Je,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),h(Je,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(Je,"DOWNSTREAM_PROPERTIES",[...Je.MUTABLE_DOWNSTREAM_PROPERTIES,...Je.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(Je,"PROPERTIES",[...Je.META_PROPERTIES,...Je.UPSTREAM_PROPERTIES,...Je.DOWNSTREAM_PROPERTIES]);let an=Je;function Jc(r){return r&&typeof r.then=="function"}class zl{constructor(a){h(this,"order",[]);h(this,"flatRecord",{});h(this,"allBuiltInEntityIds",Gi());h(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(Gi()),t=p(j(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Ql(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Ql(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Ql(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Jc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);Jc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function aP(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var f;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((f=u.getDefaultValue())==null?void 0:f.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),f=u==null?void 0:u.defaultValue;if(f)f.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:N.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},T=V(c,r.project);return T.setParent(u==null?void 0:u.dataType,a),T.initChildren(a),a==null||a.add(T,A.Added),T.addSelfToProject(a),{newEntities:[T]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=Yl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:N.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=V(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,A.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function oP(r,a){const e=[],t=[],i=[],s=[];return r.implements.filter(o=>o.type===n.BuiltInBaseEntity).forEach(o=>{var d;switch(o.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{let f=r.project.entities.filter(I=>I.implements.find(D=>D.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(I=>!!I.properties.find(D=>{var P;return D.implements&&D.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((P=D.getDefaultValue())==null?void 0:P.value)===!0}));if(!f){f=r.project.getBuiltIn(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id).implement("Relational database",a);const D=f.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id});(d=D==null?void 0:D.defaultValue)==null||d.metaSync({value:!0},a),t.push(f)}const c=r.properties.find(I=>I.implements&&I.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),T=c==null?void 0:c.defaultValue;if(c&&!T){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:N.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:f,valueAsTypeList:null,parent:c==null?void 0:c.toReference()},D=V(I,r.project);D.hydrateAncestors(),D.setParent(c,a),D.addSelfToProject(a),D.initChildren(a),a==null||a.add(D,A.Added),t.push(D);return}else T&&T.setValueAsTypeSingle(f,a);return}}}),{self:r,updated:p(e),added:p(t),removed:p(i),affected:p(s)}}function Yl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r.toJSON()],x:0,y:0,parent:r.project.toReference()};aP(r,e);const o=V(l,r.project);return o.hydrateAncestors(),e==null||e.add(o,A.Added),o.addSelfToProject(e),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),oP(o,e),o}function Wc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function lP(r,a,e,t=wt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},f=V(u,r.project);return s.push(f),f.setParent(a,e),f.initChildren(e),e==null||e.add(f,A.Added),f.setEntity(r),f.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:f}}function Sc(r,a,e,t,i){var u,f,c,T,I,D,P,C;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const G=new Date(r);if(G instanceof Date&&!isNaN(G.valueOf())&&(M=!0),M){const _=a.project.getBuiltIn(k[n.PrimitiveEntity][N.Date].id);a.setEntity(_);break}else{const _=a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id);a.setEntity(_);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const _=r.slice(0,5).filter(q=>q!==void 0);if(_.every(q=>typeof q==typeof _[0])&&(typeof _[0]!="object"||_[0]===null))switch(typeof _[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}else{const q=[];let S=!1;_.forEach(de=>{var me,z,oe,Ft;if(Array.isArray(de)&&(S=!0),typeof de=="object"&&!Array.isArray(de)&&de!==null){const nr=Hl(de,a.project,{...e,id:m.UUID.uuid()},t,i);nr.hasCreated&&q.push((me=nr.changeSet)==null?void 0:me.self),s.push(...(z=nr.changeSet)==null?void 0:z.updated),l.push(...(oe=nr.changeSet)==null?void 0:oe.added),o.push(...(Ft=nr.changeSet)==null?void 0:Ft.removed)}});const K=p(q);if(!K.length&&!S){_.forEach(de=>{const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:wt.OrDataTypeGroup,parent:a.toReference()},z=V(me,a.project);switch(z.setParent(a,t),z.initChildren(t),t==null||t.add(z,A.Added),z.addSelfToProject(t),typeof de){case"string":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.String].id));break;case"number":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.Number].id));break;case"boolean":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.Boolean].id));break;case"object":z.setEntity(z.project.getBuiltIn(k[n.PrimitiveEntity][N.Null].id));break}});break}else K.length===1&&!S?a.setEntity(K[0]):_.forEach(de=>{if(typeof de=="object"&&!Array.isArray(de)&&de!==null){const me=Wc(Object.keys(de),a.project);if(me){const z=lP(me||K[0],a,t,wt.OrDataTypeGroup);s.push(...z.updated),l.push(...z.added),o.push(...z.removed)}}else{const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(de),asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parentRelationType:wt.OrDataTypeGroup,parent:a.toReference()},z=V(me,a.project);z.setParent(a,t),z.initChildren(t),t==null||t.add(z,A.Added),z.addSelfToProject(t);const oe=Sc(de,z,{...e,id:m.UUID.uuid()},t,i);s.push(...oe.updated),l.push(...oe.added),o.push(...oe.removed)}})}}else{const _=Hl(r[0],a.project,{...e},t,i);a.setEntity((u=_.changeSet)==null?void 0:u.self),s.push(...(f=_.changeSet)==null?void 0:f.updated),l.push(...(c=_.changeSet)==null?void 0:c.added),o.push(...(T=_.changeSet)==null?void 0:T.removed);break}else{const _=Hl(r,a.project,{...e},t,i);a.setEntity((I=_.changeSet)==null?void 0:I.self),s.push(...(D=_.changeSet)==null?void 0:D.updated),l.push(...(P=_.changeSet)==null?void 0:P.added),o.push(...(C=_.changeSet)==null?void 0:C.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Hl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),f=Wc(u,a);if(f)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:f}};const c=i?e.name+" of "+i.name:e.name,I={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},D=V(I,a);return D.setParent(a,t),D.initChildren(t),t==null||t.add(D,A.Added),D.addSelfToProject(t),l.push(D),u.forEach((P,C)=>{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,extends:null,index:C,hidden:!1,private:!1,required:!0,parent:D.toReference()},_=V(G,a);_.setParent(D,t),_.initChildren(t),t==null||t.add(_,A.Added),_.addSelfToProject(t),l.push(_);const g=r[P],S={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,staticEntities:!1,interactiveEntities:!0,actionEntities:!1,like:!0,inferred:!1,parent:_.toReference()},K=V(S,a);K.setParent(_,t),K.initChildren(t),t==null||t.add(K,A.Added),K.addSelfToProject(t),l.push(K);const de=Sc(g,K,{...e,name:P,id:m.UUID.uuid()},t,i||D);s.push(...de.updated),l.push(...de.added),o.push(...de.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:D}}}function Dr(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,f;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((f=s.implements)==null?void 0:f.id)});if(l){const d=new Ye({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:O.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new Ye({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:O.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var f,c;return!!u.implements&&((f=u.implements)==null?void 0:f.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new Ye({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:O.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new Ye({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:O.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function PW(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Bc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function wW(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===sd.Implements||t.field===sd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function CW(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function VW(r,a){return r.static&&r.metaSync({static:!1},a),r}var dP=(r=>(r.StringValueMustNotHaveSpaces="string-value-must-not-have-spaces",r.StringValueMustNotHaveDashes="string-value-must-not-have-dashes",r))(dP||{});function uP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s/g,"-")}}function pP(r,a){const e=[],t=a;if(!t)return{errors:e,override:a};if(typeof t!="string")return{errors:[],override:a};if(t.includes(" ")){const i=new Ye({id:r.id+"--string-value-must-not-have-spaces",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-spaces",entity:r});e.push(i)}if(t.includes("-")){const i=new Ye({id:r.id+"--string-value-must-not-have-dashes",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value cannot contain spaces or dashes.`,issue:null,severity:O.Error,code:"string-value-must-not-have-dashes",entity:r});e.push(i)}return{errors:e,override:t.replace(/\s|-/g,"_")}}function _s(r,a){const e=gn(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=_s(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function zc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=zt(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||_s(s,t).last?s:(_s(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function Q(r,a){var i,s;let e=zc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!ht.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(ot.includes(r.type))return;Te(r).forEach(l=>{var d,u;const o=zc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!ht.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function cP(r,a,e=new Set){const t=on(r),i=on(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...cP(u,a,e)])),[]);return p([...l,...o])}function Ua(r,a){const e=_s(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function _W(r,a){return!!_s(r,a).last}function BW(r){if(rt.includes(r.type))return r;if([...xi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return rt.includes(a.type)?a:null}return null}function Yc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return Yc(e,t)}function Rt(r){if(Ha.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return Rt(a);if(a.type===n.Loop)return a}return r.type===n.DefinitionEntity&&r.parent.type===n.DataType?Rt(r.parent):r}else{const a=r.parent;return a?Rt(a):null}}function Kl(r,a){const e=$a(r,a);if(!e)return null;if(Ha.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=$a(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?$a(e.parent,a):null;return t?Kl(t,a):null}}function fP(r){if(!r)return null;if(xi.includes(r.type))return r;const a=r.parent;return a?fP(a):null}function hP(r){if(!r)return null;if(dt.includes(r.type))return r;const a=r.parent;return a?hP(a):null}function yP(r){if(!r)return null;if(ki.includes(r.type))return r;const a=r.parent;return a?yP(a):null}function MW(r){return r.type===n.VariableDeclaration?[r]:dt.includes(r.type)?[...r.inputs,...r.outputs||[]]:ot.includes(r.type)?r.outputs:qn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function NW(r){const a=on(r),e=[],t=[];pf.includes(r.type)&&e.push(...Hc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:xi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>Ua(l,s)?-1:0),t.sort((s,l)=>Ua(l,s)?-1:0),[...e,...t,...i]}function mP(r){return[...r].sort((a,e)=>Ua(e,a)?-1:0)}function LW(r){const a=mP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];Ua(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function gt(r){const a=r.map(e=>Rt(e));return p(a)}function Hc(r){return dt.includes(r.type)?[...gt(r.successCalls),...gt(r.errorCalls)]:rt.includes(r.type)?gt(r.calls):[]}function jW(r,a){return Hc(r).includes(a)}function Kc(r){return r.writesValues||[]}function UW(r,a){return Kc(r).includes(a)}function vP(r){var a;return it.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function $W(r){return r.writesValues}function EP(r=[]){return r.map(vP).filter(a=>!!a)}function Xl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>it.includes(a.type))}function TP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&it.includes(a.type))}function IP(r){return it.includes(r.type)?r:null}function AP(r){return r.writesValues.map(IP).filter(a=>!!a)}function bP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...AP(e)]:a,[])}function Te(r){return r.type===n.Loop?p([...Vi(gt(r.successCalls)),...Vi(gt(r.errorCalls)),...r.body?Te(r.body):[]]):dt.includes(r.type)?p([...Vi(gt(r.successCalls)),...Vi(gt(r.errorCalls))]):rt.includes(r.type)?p(Vi(gt(r.calls))):[]}function GW(r){return dt.includes(r.type)?[...Vi(gt(r.successCalls)),...Vi(gt(r.errorCalls))]:rt.includes(r.type)?Vi(gt(r.calls)):[]}function RP(r,a=new Set){return r.writesValues.filter(t=>it.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...He(i,a)],[])}function DP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>it.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...He(s,a)],[])}function He(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return TP(r.outputs).reduce((t,i)=>[...t,...He(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...Te(r).reduce((s,l)=>{const o=Rt(l);return[...s,...He(o||l,a)]},[]),...EP(r.inputs),...bP(r.outputs)].reduce((s,l)=>[...s,...He(l,a)],[]);if(qn.includes(r.type)){const e=Xl(r.inputs),i=Te(r).reduce((s,l)=>{const o=Rt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Xl(r.inputs)],i=Te(r).reduce((s,l)=>{const o=Rt(l);return[...s,...He(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...He(l)],[])}if(it.includes(r.type)){a.add(r.id);const t=Te(r).reduce((i,s)=>{const l=Rt(s);return[...i,...He(l||s,a)]},[]);return[r,...t,...DP(r,a),...RP(r,a)]}return[]}function ci(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...on(r).reduce((i,s)=>[...i,s,...ci(s,a)],[])])}function Vi(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...Te(e)],[])}function OP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Xl(u.inputs),...Vi(gt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Vi(gt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Vi(gt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function PP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return dt.includes(r.type)?ew(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function gW(r){const a=OP(r.project);return PP(r,a)}function $a(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Ql(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(si.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,f=r,c=r,T=r,I=r,D=r,P=r,C=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(D.calledByEntry||[]).flatMap(g=>g),...(D.calledBySuccess||[]).flatMap(g=>g),...(D.calledByError||[]).flatMap(g=>g),...T.parent?[T.parent]:[]];Array.isArray(s.implements)?C.push(...s.implements.flatMap(g=>g)):c.implements&&C.push(c.implements),Array.isArray(s.extends)?C.push(...s.extends.flatMap(g=>g)):c.extends&&C.push(c.extends),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&C.push(...o.valueAsTypeList.flatMap(g=>g)),o.valueAsTypeSingle&&C.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap(g=>g),...(I.inputsDeclarations||[]).flatMap(g=>g),...(t.outputs||[]).flatMap(g=>g),...(I.outputsDeclarations||[]).flatMap(g=>g),...(P.internalCalls||[]).flatMap(g=>g),...P.writesValues||[],...D.dataType?[D.dataType]:[],...d.body?[d.body]:[],...D.defaultValue?[D.defaultValue]:[],...(D.successCalls||[]).flatMap(g=>g),...(D.errorCalls||[]).flatMap(g=>g),...(s.properties||[]).flatMap(g=>g),...(s.methods||[]).flatMap(g=>g),...(s.abstractMethods||[]).flatMap(g=>g),...u.error?[u.error]:[],...u.process?[u.process]:[],...T.throws?[T.throws]:[],...(i.andChildrenGroup||[]).flatMap(g=>g),...(i.orChildrenGroup||[]).flatMap(g=>g),...(f.entities||[]).flatMap(g=>g),...(f.functions||[]).flatMap(g=>g),...(f.functionCalls||[]).flatMap(g=>g),...(f.events||[]).flatMap(g=>g),...(f.conditions||[]).flatMap(g=>g),...(f.operations||[]).flatMap(g=>g),...(f.loops||[]).flatMap(g=>g),...(f.variableDeclarations||[]).flatMap(g=>g),...(f.variableInstances||[]).flatMap(g=>g),...(f.searches||[]).flatMap(g=>g),...(f.projects||[]).flatMap(g=>g),...(l.calls||[]).flatMap(g=>g)];r.type===n.DataType&&(i.entity&&a[B(i.entity)]&&a[B(i.entity)].parent&&B(a[B(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&C.push(i.entity));const G={},_={};return C.forEach(g=>{const q=B(g);if(q&&e.ignoreBuiltInBaseEntities&&(si.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(G[q]=S)}),M.forEach(g=>{const q=B(g);if(q&&e.ignoreBuiltInBaseEntities&&(si.includes(g.type)||(e.allBuiltInEntityIds||[]).includes(q)))return;const S=g.version;q&&(_[q]=S)}),{upstream:G,downstream:_}}function FW(r,a){const e=[];if(xi.includes(r.type)){Ai(r).forEach(s=>{const l=Kl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=$a(s,a);return l?iw(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(it.includes(r.type)){const t=ed(r);t&&e.push(t)}return p(e)}function gn(r){const a=[];if(xi.includes(r.type)){r.calledBy.forEach(i=>{const s=Rt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>ed(i)).filter(i=>i!==null);a.push(...p(t))}if(it.includes(r.type)){const e=ed(r);e&&a.push(e)}return p(a)}function Ai(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>j(t,a,e)),...r.outputs.flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.parent?j(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a):[],...r.writesValues.flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...(r.extends||[]).flatMap(t=>j(t,a,e))]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>j(t,a,e)),...(r.implements||[]).flatMap(t=>j(t,a,e)),...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>j(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>j(t,a,e)),...r.entity?j(r.entity,a,e):[],...r.parent?j(r.parent,a,e):[]]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.calls||[]).flatMap(t=>j(t,a,e)),...r.implements?j(r.implements,a,e):[],...r.parent?j(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.parent?j(r.parent,a,e):[]]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?j(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>j(t,a,e)):[],...r.parent?j(r.parent,a,e):[]]}function kP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...r.body?j(r.body,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function ZP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...r.process?j(r.process,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function qP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.parent?j(r.parent,a,e):[]]}function JP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>j(t,a,e)),...(r.methods||[]).flatMap(t=>j(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>j(t,a,e))]}function WP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>j(t,a,e)),...(r.functions||[]).flatMap(t=>j(t,a,e)),...(r.events||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.variableInstances||[]).flatMap(t=>j(t,a,e)),...(r.operations||[]).flatMap(t=>j(t,a,e)),...(r.conditions||[]).flatMap(t=>j(t,a,e)),...(r.functionCalls||[]).flatMap(t=>j(t,a,e)),...(r.projects||[]).flatMap(t=>j(t,a,e)),...(r.loops||[]).flatMap(t=>j(t,a,e)),...(r.searches||[]).flatMap(t=>j(t,a,e))]}function SP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function zP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function YP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.throws?j(r.throws,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function HP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...r.error?j(r.error,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.parent?j(r.parent,a,e):[]]}function KP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?j(r.defaultValue,a,e):[],...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function XP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.dataType?j(r.dataType,a,e):[],...r.parent?j(r.parent,a,e):[]]}function QP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>j(t,a,e)),...(r.errorCalls||[]).flatMap(t=>j(t,a,e)),...(r.inputs||[]).flatMap(t=>j(t,a,e)),...(r.outputs||[]).flatMap(t=>j(t,a,e)),...(r.internalCalls||[]).flatMap(t=>j(t,a,e)),...(r.writesValues||[]).flatMap(t=>j(t,a,e)),...r.readsValue?j(r.readsValue,a,e):[],...r.defaultValue?j(r.defaultValue,a,e):[],...(Ai(r)||[]).flatMap(t=>j(t,a,e)),...r.declaration?j(r.declaration,a,e):[],...r.parent?j(r.parent,a,e):[]]}function Gi(){const r=new Set,a=hI.flatMap(e=>j(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function j(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(si.includes(r.type)||Gi().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return jP(r,a,e);case n.Operation:return ZP(r,a,e);case n.Condition:return BP(r,a,e);case n.Loop:return kP(r,a,e);case n.Search:return HP(r,a,e);case n.GlobalEvent:return $P(r,a,e);case n.ReturnStatement:return YP(r,a,e);case n.ContinueStatement:return MP(r,a,e);case n.BreakStatement:return VP(r,a,e);case n.VariableDeclaration:return XP(r,a,e);case n.DefinitionEntity:return NP(r,a,e);case n.FunctionDeclaration:return UP(r,a,e);case n.Project:return WP(r,a,e);case n.ActionDescriptor:return wP(r,a,e);case n.ArgumentDeclaration:return CP(r,a,e);case n.ReturnDeclaration:return zP(r,a,e);case n.ValueDescriptor:return KP(r,a,e);case n.InputMap:return GP(r,a,e);case n.OutputMap:return qP(r,a,e);case n.DataType:return LP(r,a,e);case n.InstalledProject:return gP(r,a,e);case n.InternalCall:return FP(r,a,e);case n.LiteralValue:return xP(r,a,e);case n.Property:return SP(r,a,e);case n.VariableInstance:return QP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:_P(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:JP(r,a,e)}return[]}function Xc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||qn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function xW(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function ew(r){return dt.includes(r.type)?r.inputs:[]}function tw(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:ot.includes(r.type)?r.outputs:[]}function kW(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function ZW(r){return r.type===n.Condition?[]:dt.includes(r.type)?r.outputs:[]}function ed(r){const a=r.readsValue;return a?Rt(a):null}function iw(r,a){const e=r.readsValue;return e?Kl(e,a):null}function rw(r){const a=r.internalCalls||[];return p(gt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Bs(r){const a=Kc(r),e=[];return a.forEach(t=>{if(it.includes(t.type))e.push(t);else if(Pr.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function on(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),ht.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:on(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>Rt(s)),i=r.errorCalls.map(s=>Rt(s));e.push(...t,...i)}if(qn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Bs(s)).flat(),i=r.calls.map(s=>Rt(s));e.push(...p(t),...i)}if(dt.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Bs(l)).flat(),i=r.successCalls.map(l=>Rt(l)),s=r.errorCalls.map(l=>Rt(l));e.push(...p(t),...i,...s)}if(it.includes(r.type)){const t=Bs(r),i=rw(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Bs(l)).flat();if(r.body){const l=on(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>Rt(l)),s=r.successCalls.map(l=>Rt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Bs(s)).flat(),i=r.calls.map(s=>Rt(s));e.push(...p(t),...i)}return p(e)}function nw(r,a=!1){const e=on(r,a),t=[...e,...e.reduce((i,s)=>[...i,...nw(s,a)],[])];return p(t)}function sw(r){const a=gn(r),e=[...a,...a.reduce((t,i)=>[...t,...sw(i)],[])];return p(e)}function Ga(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Ga(e),...ga(e)]:[...a,e.name],[])}function ga(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...ga(e),...Ga(e)]:[...a,e.name],[])}function Qc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Qc(e),...ef(e)]:[...a,e],[])}function ef(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...ef(e),...Qc(e)]:[...a,e],[])}function tf(r){return[...ga(r),...Ga(r)].filter((e,t,i)=>i.indexOf(e)===t)}function aw(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===J.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=aw(i);if(s)return s}return t},null)}function qW(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function JW(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function ow(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function St(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...St(t)]:e,[]);return p(a)}function Fa(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!St(r).find(t=>!t.interactive)}function WW(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function rf(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function lw(r){if([...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||rf(r))return!1;const a=gn(r);return a.length===0?!0:a.some(e=>lw(e))}function nf(r){return[...rt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||rf(r)?!1:gn(r).length===0}function dw(r,a=0){if(nf(r)){const e=gn(r);return e.length===0?r:e.map(i=>dw(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function uw(r){const a=[];if(nf(r))a.push(r);else return[];return gn(r).forEach(t=>{a.push(...uw(t))}),a}function pw(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function SW(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function xa(r){switch(r){case n.DefinitionEntity:return dn;case n.FunctionDeclaration:return kr;case n.VariableDeclaration:return Hr;case n.VariableInstance:return Yr;case n.FunctionCall:return an;case n.Operation:return qr;case n.Condition:return zr;case n.ReturnStatement:return Jr;case n.Loop:return Sr;case n.Search:return Kr;case n.InputMap:return er;case n.OutputMap:return tr;case n.ArgumentDeclaration:return br;case n.ReturnDeclaration:return ri;case n.Property:return xr;case n.InstalledProject:return Xr;case n.Project:return m;case n.DataType:return Zr;case n.GlobalEvent:return Wr;case n.InternalCall:return Qr;case n.ValueDescriptor:return ir;case n.BuiltInBaseEntity:return Fi;case n.PrimitiveEntity:return ni;case n.ActionDescriptor:return We;case n.LiteralValue:return en;case n.ContinueStatement:return Gt;case n.BreakStatement:return tn;default:return null}}function zt(r,a,e=null){const t=r!=null&&r.parent?B(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.ReturnStatement)return It(r,a,s);if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return i;if(rt.includes(r.type))return r;if(r.type===n.Loop)return s.id===r.id?i:r;if(si.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=B(l);if(!o)return null;const d=a.get(o);return d?zt(d,a,s):null}else return l===a?a:zt(l,a,s)}function It(r,a,e=null){const t=r!=null&&r.parent?B(r==null?void 0:r.parent):null;let i=t?a.get(t):null,s=e||r;if(r.type===n.FunctionDeclaration&&(i==null?void 0:i.type)===n.Loop)return It(i.parent,a,s);if(rt.includes(r.type))return r;if(si.includes(r.type))return null;const l=r.parent;if(!l)return null;if(l.type===n.GenericReference){const o=B(l);if(!o)return null;const d=a.get(o);return d?It(d,a,s):null}else return l===a?a:It(l,a,s)}function sf(r,a){if(si.includes(r.type)||a.getBuiltIn(r.id))return null;const e=bi(r.parent,a);return e?e===a?ht.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:sf(e,a):null}function td(r,a,e){if(r===a||a===e||r===e)return!1;const t=zt(a.parent,e);return t===r?!0:td(t,a,e)}var id=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(id||{});function ka(r,a,e){const t=zt(r,e),i=zt(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(td(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(td(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=Yc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:zt(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function cw(r,a,e){const t=ka(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=zt(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=zt(i.parent,e)}let s=zt(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=zt(s.parent,e)}return null}function fw(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=cw(e,t,t.project);return!i||i===t?e:t},r[0])}function bi(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=B(r):e=r.id,e===a.id?a:a.get(e)}function ln(r){if(!r)return null;if(si.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:ln(a)}function Za(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=sf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Te(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Za(o);d.reachable||Te(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Te(r).find(c=>c===d)||t(s,d))});let o;if(dt.includes(s.type)&&(o=s),o){const d=Za(o);d.reachable||Te(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{ot.includes(d.type)&&d!==r&&(Te(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=Rt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=Za(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function zW(r){return Ha.includes(r.type)?r.type===n.FunctionDeclaration?!pw(r):!0:!1}function YW(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function rd(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!ga(r).includes(a)}function HW(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!Ga(r).includes(a)}function gi(r,a){return r.type===n.BuiltInBaseEntity?r.name===a:!!tf(r).includes(a)}function KW(r){const a=[];return r.entities.forEach(e=>{if(rd(e,J.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function XW(r){const a=[];return r.entities.forEach(e=>{if(rd(e,J.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function QW(r){return r.type!==n.DefinitionEntity||r.abstract||!rd(r,J.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][J.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function eS(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!gi(r,J.PERSISTED_ENTITY))return r.id==="a2d0ec83-72ce-4f54-b059-a39e018fa86c"&&console.log("Entity does not have persisted base entity",r),[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][J.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function tS(r){var e;if(!r||r.type!==n.DefinitionEntity||!gi(r,J.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][J.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!ff.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function iS(r){switch(r){case n.Project:return m;case n.InstalledProject:return Xr;case n.DefinitionEntity:return dn;case n.FunctionDeclaration:return kr;case n.GlobalEvent:return Wr;case n.VariableInstance:return Yr;case n.VariableDeclaration:return Hr;case n.InputMap:return er;case n.OutputMap:return tr;case n.Condition:return zr;case n.Operation:return qr;case n.FunctionCall:return an;case n.ReturnDeclaration:return ri;case n.ArgumentDeclaration:return br;case n.PrimitiveEntity:return ni;case n.DataType:return Zr;case n.Property:return xr;case n.ActionDescriptor:return We;case n.ReturnStatement:return Jr;case n.ContinueStatement:return Gt;case n.BreakStatement:return tn;case n.Loop:return Sr;case n.Search:return Kr;case n.ValueDescriptor:return ir;case n.InternalCall:return Qr;case n.LiteralValue:return en}return null}function rS(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function pt(r,a){const e=xa(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function nd(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=B(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...nd(t,a)]:[]}function nS(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=Rt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function sS(r){if(r.type===n.Condition)return null;if(r.type===n.Search)return r.project.getBuiltIn(k["value-descriptor"][Jn.SearchErrorOutputDescriptor].id)||null;if(r.type===n.Operation)return r.declaration.error;if(r.type===n.FunctionCall){const e=r.declaration.returnStatements.find(t=>!!t.throws);return(e==null?void 0:e.throws)||null}return null}function hw(r){const a=Nq(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(f=>aS(r,f)),s=r.extends.flatMap(f=>oS(r,f)),l=dS(r),o=lS(r);r.methods.flatMap(f=>f.validate());const d=[...i,...s,...l,...o];return Ke(r.errors,d)}function yw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function mw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function aS(r,a){const e=[];if(!a.abstract){const f=fe({id:r.id+"--"+x.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.ImplementingNonAbstractEntity,entity:r});return e.push(f.error),e}const t=a.properties.filter(f=>f.abstract),i=[];let s=[...r.properties];t.forEach(f=>{const c=s.find(T=>{var I;return((I=T.implements)==null?void 0:I.id)===f.id});c?s=s.filter(T=>T.id!==c.id):i.push(f)}),i.length&&i.forEach(f=>{const c=fe({id:r.id+"--"+x.MissingPropertyImplementation+"--"+f.id,message:`Property "${f.name}" with id "${f.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:O.Error,code:x.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(f=>{const c=o.find(T=>{var I;return((I=T.implements)==null?void 0:I.id)===f.id});c?o=o.filter(T=>T.id!==c.id):l.push(f)}),l.length&&l.forEach(f=>{const c=fe({id:r.id+"--"+x.MissingMethodImplementation+"--"+f.id,message:`Method "${f.name}" with id "${f.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:O.Error,code:x.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(f=>{const c=s.find(T=>T.name===f.name);c&&d.push([c,f])}),d.length&&d.forEach(([f])=>{const c=fe({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Property "${f.name}" with id "${f.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(f=>{const c=o.find(T=>T.name===f.name);c&&u.push([c,f])}),u.length&&u.forEach(([f])=>{const c=fe({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName+"--"+f.id,message:`Method "${f.name}" with id "${f.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function oS(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=fe({id:r.id+"--"+a.id+"--"+x.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=fe({id:r.id+"--"+a.id+"--"+x.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>{var u;return d.name===s.name&&((u=s.extends)==null?void 0:u.id)!==d.id});((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=fe({id:r.id+"--"+$.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>{var u;return d.name===s.name&&((u=s.extends)==null?void 0:u.id)!==d.id});((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=fe({id:r.id+"--"+$.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:$.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function lS(r){const a=[];if(!r.properties.length){const e=fe({id:r.id+"--"+x.NoProperties,message:"No properties implemented",issue:null,severity:O.Warning,code:x.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function dS(r){const a=[];if(r.abstract){if(r.methods.length){const e=fe({id:r.id+"--"+x.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:O.Error,code:x.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=fe({id:r.id+"--"+x.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:O.Error,code:x.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=fe({id:r.id+"--"+x.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:O.Error,code:x.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=fe({id:r.id+"--"+x.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:O.Error,code:x.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}r.properties.some(e=>e.abstract)&&r.properties.forEach(e=>{if(e.abstract){const t=fe({id:r.id+"--"+x.AbstractPropertyInNonAbstractEntity+"--"+e.id,message:`Property "${e.name}" with id "${e.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:O.Error,code:x.AbstractPropertyInNonAbstractEntity,entity:r,firstRelationship:e});a.push(t.error)}})}return r.static&&r.properties.some(e=>!e.static)&&r.properties.forEach(e=>{if(!e.static){const t=fe({id:r.id+"--"+x.NonStaticPropertyInStaticEntity+"--"+e.id,message:`Property "${e.name}" with id "${e.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:O.Error,code:x.NonStaticPropertyInStaticEntity,entity:r,firstRelationship:e});a.push(t.error)}}),a}function uS(r,a){const e=[],t=St(a);if(!a.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+x.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new Ye({id:r.id+"--"+a.id+"--"+x.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+x.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new Ye({id:r.id+"--"+a.id+"--"+x.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new Ye({id:r.id+"--"+d.id+"--"+l.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{St(l).forEach(f=>{const c=t.filter(T=>T.id!==f.id);c.length&&c.forEach(T=>{if(T.id!==f.id){const I=new Ye({id:r.id+"--"+T.id+"--"+f.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${T.name}" with id "${T.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:T,secondRelationship:f});e.push(I)}})});const d=Dr(a.ownDeclaredProperties,l.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=Dr(a.abstractMethods,[...l.abstractMethods,...l.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>St(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new Ye({id:r.id+"--"+a.id+"--"+l.id+"--"+x.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function pS(r,a,e=!1){const t=[],i=St(a);if(!r.abstract&&a.abstract){const f=fe({id:r.id+"--"+a.id+"--"+x.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.abstract&&!a.abstract){const f=fe({id:r.id+"--"+a.id+"--"+x.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!r.static&&a.static){const f=fe({id:r.id+"--"+a.id+"--"+x.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(r.static&&!a.static){const f=fe({id:r.id+"--"+a.id+"--"+x.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(f.error)}if(!Fa(a)){const f=fe({id:r.id+"--"+a.id+"--"+x.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:O.Error,code:x.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(f.error)}const l=r.extends.filter(f=>f.id!==a.id);l.length&&l.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(T=>T.id!==f.id);c.length&&c.forEach(T=>{if(T.id!==f.id){const I=fe({id:r.id+"--"+T.id+"--"+f.id+"--"+x.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${T.name}" with id "${T.id}" but also extends entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ExtendsIncompatibleEntities,entity:r,firstRelationship:T,secondRelationship:f});t.push(I.error)}})}else{St(f).forEach(M=>{const G=i.filter(_=>_.id!==M.id);G.length&&G.forEach(_=>{if(_.id!==M.id){const g=new Ye({id:r.id+"--"+_.id+"--"+M.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${_.name}" with id "${_.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:_,secondRelationship:M});t.push(g)}})});const T=!!St(f).find(M=>M.id===a.id);let I=[...f.properties];T&&(I=I.filter(M=>!a.properties.find(G=>{var _;return G.id===M.id||G.name===M.name||G.id===((_=M.implements)==null?void 0:_.id)})));let D=[...f.methods];T&&(D=D.filter(M=>!a.methods.find(G=>{var _;return G.id===M.id||G.name===M.name||G.id===((_=M.implements)==null?void 0:_.id)})));const P=Dr(a.ownDeclaredProperties,I,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const C=Dr(a.abstractMethods,D,$.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...C.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(f=>{if(f.type===n.BuiltInBaseEntity){const c=i.filter(T=>T.id!==f.id);c.length&&c.forEach(T=>{if(T.id!==f.id){const I=new Ye({id:r.id+"--"+T.id+"--"+f.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${T.name}" with id "${T.id}" but also implements entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:T,secondRelationship:f});t.push(I)}})}else{St(f).forEach(D=>{const P=i.filter(C=>C.id!==D.id);P.length&&P.forEach(C=>{if(C.id!==D.id){const M=new Ye({id:r.id+"--"+C.id+"--"+D.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${C.name}" with id "${C.id}" but also implements entity "${D.name}" with id "${D.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:C,secondRelationship:D});t.push(M)}})});const T=Dr(a.ownDeclaredProperties,f.ownDeclaredProperties,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,$.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...T.errors);const I=Dr(a.abstractMethods,[...f.abstractMethods,...f.methods],$.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,$.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...I.errors)}});const o=Dr(r.ownDeclaredProperties,a.ownDeclaredProperties,$.PropertyOverwritesOtherSiblingWithSameImplementation,$.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=Dr(a.methods,a.abstractMethods,$.MethodOverwritesOtherSiblingWithSameImplementation,$.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(f=>St(f))).forEach(f=>{if(!i.find(c=>c.id===f.id)){const c=new Ye({id:r.id+"--"+a.id+"--"+f.id+"--"+x.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${f.name}" with id "${f.id}" which is incompatible`,issue:null,severity:O.Error,code:x.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:f});t.push(c)}}),t}function cS(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+x.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:O.Error,code:x.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+x.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:O.Error,code:x.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function fS(r){const a=[];if(r.implements.length){const e=new Ye({id:r.id+"--"+x.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:O.Error,code:x.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+x.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:O.Error,code:x.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function hS(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new Ye({id:r.id+"--"+e.id+"--"+x.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:O.Error,code:x.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function yS(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new Ye({id:r.id+"--"+e.id+"--"+x.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:O.Error,code:x.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const mS=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:mw,getBasePropertiesNotImplemented:yw,validate:hw,validateCanBecomeAbstract:fS,validateCanBecomeNonAbstract:yS,validateCanBecomeNonStatic:hS,validateCanBecomeStatic:cS,validateCanExtendEntity:pS,validateCanImplementEntity:uS},Symbol.toStringTag,{value:"Module"}));function vS(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${$.InvalidObjectStructure}`,code:$.InvalidObjectStructure,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:O.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var sd=(r=>(r.Extends="extends",r.Implements="implements",r))(sd||{});const $e=class $e extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"x");h(this,"y");h(this,"static");h(this,"abstract");h(this,"type",n.DefinitionEntity);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"implements",[]);h(this,"project");h(this,"errors",[]);h(this,"parent");h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"suggestedProperties",[]);h(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(e=null){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=B(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=V(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=vS(i,t),o=Rc(i,t);s.push(...l,...o,...ut(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:O.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
|
|
406
406
|
You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
|
|
407
407
|
${rr({describe_entity:u.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:s,modifiedData:i}}get interactive(){return this.implements.length?this.implements.every(e=>e.interactive):!0}get allBasePropertiesFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>t.type!==n.DefinitionEntity?[]:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[]),...this.implements.reduce((e,t)=>t.type!==n.DefinitionEntity?t.abstractMethods:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[])])}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])].filter(e=>!!e.abstract))}get extendedMethodsFromOriginalParents(){return p(this.extends.reduce((e,t)=>{if(t.type!==n.DefinitionEntity)return[];const i=[...t.ownDeclaredMethods,...t.extendedMethodsFromOriginalParents].filter(s=>s.type!==n.ActionDescriptor);return[...e,...i]},[]))}get implementedMethodsFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.type===n.DefinitionEntity?t.methods:[],s=[...t.abstractMethods].filter(l=>!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>[...t.abstractMethods,...e],[])].filter(e=>e.type===n.ActionDescriptor))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}get extendedMethods(){return this.methods.filter(e=>e.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(e=>!e.isExtendedMethod)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(e=>{si.includes(e.type)||e.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(e=>{si.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{si.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new $e(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new $e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.extends.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addExtension(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),this.initialData.implements.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addImplementation(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:f}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...f);const{updated:c,added:T,removed:I,affected:D}=this.addExtendedProperties(e);t.push(...c),i.push(...T),s.push(...I),l.push(...D);const{updated:P,added:C,removed:M}=this.removeUnrecognizedProperties(e);t.push(...P),i.push(...C),s.push(...M);const{updated:G,added:_,removed:g,affected:q}=this.syncImplementationMethods(e);t.push(...G),i.push(..._),s.push(...g),l.push(...q);const{updated:S,added:K,removed:de,affected:me}=this.addExtendedMethods(e);t.push(...S),i.push(...K),s.push(...de),l.push(...me);const{updated:z,added:oe,removed:Ft}=this.removeUnrecognizedMethods(e);return t.push(...z),i.push(...oe),s.push(...Ft),this.addSuggestions(),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.methods=this.initialData.methods.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.extends=this.initialData.extends.map(t=>V(t,this.project)),this.implements=this.initialData.implements.map(t=>V(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-properties"))){const t=[],i=[],s=[],l=[];let o=[...this.properties];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedProperty);const d=this.implementedPropertiesFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-methods"))){const t=[],i=[],s=[],l=[];let o=[...this.methods];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedMethod);const d=this.implementedMethodsFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-implementation-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,d=this.implementedMethodsFromOriginalParents,u=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})).forEach(c=>{if(this.methods.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===c.id}))return;const I=this.methods.find(P=>{var g,q;if(P.name===c.name&&!P.implements)return!0;const C=gi(this,J.CRON_JOB),M=gi(this,J.HTTP_ENDPOINT),G=((g=P.implements)==null?void 0:g.id)===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,_=((q=P.implements)==null?void 0:q.id)===k["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(C&&!_&&!M&&G||M&&!G&&!C&&_)});if(I&&I.type===n.FunctionDeclaration){I.setImplements(c),I.metaSync({name:c.name},e),e==null||e.add(I,A.Updated),e==null||e.add(this,A.Updated);return}const D=c.implementAsFunctionDeclaration(e,this);i.push(D),e==null||e.add(D,A.Added),this.addMethod(D)}),e==null||e.attemptAutoclose("sync-implementation-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.implementedPropertiesFromOriginalParents,u=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})).forEach(c=>{if(this.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===c.id}))return;const I=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(I){I.implements=c,I.abstract=!1;return}const D=c.clone(e,this,m.UUID.uuid());D.initChildren(e),i.push(D),e==null||e.add(D,A.Added),D.setImplements(c,e),D.metaSync({abstract:!1},e),this.addProperty(D)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-extended-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,u=this.extendedMethodsFromOriginalParents.filter(c=>c.type===n.FunctionDeclaration),f=new Set(o.filter(c=>{var T;return!!((T=c.extends)!=null&&T.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const T=c.clone(e,this,m.UUID.uuid());T.setExtends(c,e),T.initChildren(e),i.push(T),e==null||e.add(T,A.Added),this.addMethod(T)}),e==null||e.attemptAutoclose("add-extended-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.extendedPropertiesFromOriginalParents,u=d.filter(c=>d.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})?!1:!c.abstract),f=new Set(o.filter(c=>{var T;return!!((T=c.extends)!=null&&T.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const T=c.clone(e,this,m.UUID.uuid());T.setExtends(c,e),T.initChildren(e),i.push(T),e==null||e.add(T,A.Added),this.addProperty(T)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{yw(this,e).forEach(s=>{const l=s.toJSON();l.id=`_suggestion--parent--${this.id}--${s.id}`;const o=V(l,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),mw(this,e).forEach(s=>{const l=`_suggestion--parent--${this.id}--${s.id}`,o=s.implementAsFunctionDeclaration(null,this,l),d=V(o,this.project);if(d.suggestion=!0,d.setParent(this,null),d.initChildren(null),this.methods=this.methods.filter(u=>u.id!==l),d.inputs.forEach(u=>{u.suggestion=!0}),d.returnStatements.length){const u=d.returnStatements[0];u.suggestion=!0,u.outputs.forEach(f=>{f.suggestion=!0})}this.addSuggestedMethod(d)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.static=e.static!==void 0?e.static:this.static,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await $e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await $e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await $e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await $e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await $e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await $e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.methods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const d=this.parent.setEntity(null);i.push(d)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.properties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.methods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.abstractMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedProperties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(i=>i.toFlat(e)),...this.implements.flatMap(i=>i.toFlat(e)),...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(i=>i.toFlatIds(e)),...this.implements.flatMap(i=>i.toFlatIds(e)),...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(u=>u.toJSONClone({...e,newId:null})),methods:this.methods.map(u=>u.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(u=>u.toJSONClone({...e,newId:null})),implements:this.implements.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),extends:this.extends.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toReference(e)),methods:this.methods.map(s=>s.toReference(e)),abstractMethods:this.abstractMethods.map(s=>s.toReference(e)),implements:this.implements.map(s=>s.toReference(e)),extends:this.extends.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e)),...this.implements.flatMap(i=>i.toFlatJSON(e)),...this.extends.flatMap(i=>i.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=hw(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=T;const I=(C=this.methods)==null?void 0:C.map((G,_)=>G.clone(e,c,f+"-method-"+_+"-id",s));c.methods=I;const D=(M=this.abstractMethods)==null?void 0:M.map((G,_)=>G.clone(e,c,f+"-abstract-method-"+_+"-id",s));return c.abstractMethods=D,e==null||e.attemptAutoclose("clone-entity",this.id),c}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-definition-entity")),i){const s=Yl(this,e,t,i);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),s}getAllInteractiveMethods(){const e=this.implements.filter(i=>i.type===n.DefinitionEntity||i.type===n.BuiltInBaseEntity&&i.interactive);return p([...this.methods,...this.extends.flatMap(i=>i.getAllInteractiveMethods()),...e.flatMap(i=>i.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const i=[],s=[],l=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const d=[];e.forEach(c=>{d.find(I=>F(I,this.project)===F(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const T=u.find(_=>F(_,this.project)===F(c,this.project));if(!T)return;const D=Gn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=$i(D,t),C=P==null?void 0:P.clone(t,T,m.UUID.uuid(),!0);if(C){const _=(M=T.dataType)==null?void 0:M.merge(C,t);T.dataType&&(_==null?void 0:_.self.id)!==T.dataType.id&&T.dataType.remove({ignoreUpstream:!1},t),C.id!==((G=_==null?void 0:_.self)==null?void 0:G.id)&&C.remove({ignoreUpstream:!1},t),_!=null&&_.self&&(_.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(_.self,A.Added),T.setDataType(_.self),t==null||t.add(T,A.Updated))}c.setDeclaration(T),t==null||t.add(c,A.Updated)});const f=[];return d.forEach(c=>{if(!c.declaration){f.push(c);return}}),f.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(f.forEach(c=>{var _,g,q,S;const T=this.properties.find(K=>F(K,this.project)===F(c,this.project));if(T){if(c.setDeclaration(T),!T.getDataType(t)){const de=Gn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),me=$i(de),z=me==null?void 0:me.clone(t,T,m.UUID.uuid(),!0);if(z){const oe=(_=T.dataType)==null?void 0:_.merge(z,t);T.dataType&&(oe==null?void 0:oe.self.id)!==T.dataType.id&&T.dataType.remove({ignoreUpstream:!1},t),z.id!==((g=oe==null?void 0:oe.self)==null?void 0:g.id)&&z.remove({ignoreUpstream:!1},t),oe!=null&&oe.self&&(oe.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(oe.self,A.Added),T.setDataType(oe.self),t==null||t.add(T,A.Updated))}}return}const I={id:m.UUID.uuid(),type:n.Property,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:F(c,this.project),description:c.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:c.index,implements:null,extends:null,dataType:null,parent:this.toReference()},D=V(I,this.project);D.setParent(this,t),D.initChildren(t),t==null||t.add(D,A.Added);const C=Gn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=$i(C),G=M==null?void 0:M.clone(t,D,m.UUID.uuid(),!0);if(G){const K=(q=D.dataType)==null?void 0:q.merge(G,t);D.dataType&&(K==null?void 0:K.self.id)!==D.dataType.id&&D.dataType.remove({ignoreUpstream:!1},t),G.id!==((S=K==null?void 0:K.self)==null?void 0:S.id)&&G.remove({ignoreUpstream:!1},t),K!=null&&K.self&&(K.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(K.self,A.Added),D.setDataType(K.self),t==null||t.add(D,A.Updated))}return this.addProperty(D),c.setDeclaration(D),t==null||t.add(c,A.Updated),D}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:p(i),updated:p(s),removed:p(l),affected:p(o),self:this})}};h($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,...i)=>null}),h($e,"type",n.DefinitionEntity),h($e,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),h($e,"PARENT_TYPES",[...$e.USER_MANAGED_PARENT_TYPES]),h($e,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),h($e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h($e,"BASE_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"MUTABLE_META_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,"x","y"]),h($e,"INMUTABLE_META_PROPERTIES",[...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"META_PROPERTIES",[...$e.MUTABLE_META_PROPERTIES,...$e.INMUTABLE_META_PROPERTIES]),h($e,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),h($e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h($e,"UPSTREAM_PROPERTIES",[...$e.MUTABLE_UPSTREAM_PROPERTIES,...$e.INMUTABLE_UPSTREAM_PROPERTIES]),h($e,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),h($e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h($e,"DOWNSTREAM_PROPERTIES",[...$e.MUTABLE_DOWNSTREAM_PROPERTIES,...$e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h($e,"PROPERTIES",[...$e.META_PROPERTIES,...$e.UPSTREAM_PROPERTIES,...$e.DOWNSTREAM_PROPERTIES]);let dn=$e;function ES(r){const a=c5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const Wa=class Wa extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"version");h(this,"name");h(this,"description",null);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",!1);h(this,"static");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"interactive",!1);h(this,"errors",[]);h(this,"project");this.initialData=this.initialData||e,this.project=this.project||t,this.id=this.id||e.id,this.version=this.version||e.version,this.name=this.name||e.name,this.static=this.static||e.static,this.interactive=this.interactive||e.interactive,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.extends=this.initialData.extends.map(i=>V(i,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=U,...t){return await Wa.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.extends.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.extends.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=W){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=W){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=ES(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 b(this.project,m.sessionAuthor,E().toISOString(),null,!0,"implement-built-in-base-entity")),i){const s=Yl(this,e,t,i);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),s}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Wa&&e.push(...i.getAllInteractiveMethods())})),p(e)}};h(Wa,"repository",{APILoad:async(e,...t)=>null});let Fi=Wa;function TS(r){const a=r5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const dd=class dd extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"type",n.PrimitiveEntity);h(this,"static");h(this,"abstract");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.static=e.static,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.parent=this,s})}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=U,...t){return await dd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=W){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=W){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=TS(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Fi&&e.push(...i.getAllInteractiveMethods())}),p(e)}};h(dd,"repository",{APILoad:async(e,...t)=>null});let ni=dd;function st(r,a){if(!r)throw new Error("Entity is null");const e=a.get(r.id);switch(r.type){case n.LiteralValue:return e||new en(r,a);case n.DefinitionEntity:return e||new dn(r,a);case n.PrimitiveEntity:return e||new ni(r,a);case n.FunctionDeclaration:return e||new kr(r,a);case n.GlobalEvent:return e||new Wr(r,a);case n.DataType:return e||new Zr(r,a);case n.Property:return e||new xr(r,a);case n.FunctionCall:return e||new an(r,a);case n.Condition:return e||new zr(r,a);case n.Operation:return e||new qr(r,a);case n.VariableDeclaration:return e||new Hr(r,a);case n.VariableInstance:return e||new Yr(r,a);case n.OutputMap:return e||new tr(r,a);case n.ReturnDeclaration:return e||new ri(r,a);case n.ArgumentDeclaration:return e||new br(r,a);case n.InputMap:return e||new er(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Xr(r,a);case n.ActionDescriptor:return e||new We(r,a);case n.ReturnStatement:return e||new Jr(r,a);case n.Loop:return e||new Sr(r,a);case n.Search:return e||new Kr(r,a);case n.ValueDescriptor:return e||new ir(r,a);case n.BuiltInBaseEntity:return e||new Fi(r,a);case n.InternalCall:return e||new Qr(r,a);case n.ContinueStatement:return e||new Gt(r,a);case n.BreakStatement:return e||new tn(r,a);case n.GenericReference:return a.get(r.entityId);default:throw new Error("Invalid entity type: "+r.type)}}function V(r,a){if(!r)throw new Error("Entity is null");const e=st(r,a);return e.subscribe(),e}function IS(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return en.fromGenerationTarget(r,a);case n.DefinitionEntity:return dn.fromGenerationTarget(r,a);case n.FunctionDeclaration:return kr.fromGenerationTarget(r,a);case n.GlobalEvent:return Wr.fromGenerationTarget(r,a);case n.DataType:return Zr.fromGenerationTarget(r,a);case n.Property:return xr.fromGenerationTarget(r,a);case n.FunctionCall:return an.fromGenerationTarget(r,a);case n.Condition:return zr.fromGenerationTarget(r,a);case n.Operation:return qr.fromGenerationTarget(r,a);case n.VariableDeclaration:return Hr.fromGenerationTarget(r,a);case n.VariableInstance:return Yr.fromGenerationTarget(r,a);case n.OutputMap:return tr.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ri.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return br.fromGenerationTarget(r,a);case n.InputMap:return er.fromGenerationTarget(r,a);case n.InstalledProject:return Xr.fromGenerationTarget(r,a);case n.ReturnStatement:return Jr.fromGenerationTarget(r,a);case n.Loop:return Sr.fromGenerationTarget(r,a);case n.Search:return Kr.fromGenerationTarget(r,a);case n.ActionDescriptor:return We.fromGenerationTarget(r,a);case n.ValueDescriptor:return ir.fromGenerationTarget(r,a);case n.InternalCall:return Qr.fromGenerationTarget(r,a);case n.ContinueStatement:return Gt.fromGenerationTarget(r,a);case n.BreakStatement:return tn.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const W={seenEntityMaps:new Map,seenEntities:new Set,timestamp:E().toISOString()};class vw{constructor(){h(this,"initialData")}}const U={cascade:!1},Ew={APILoad:async(r,...a)=>null},AS={APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoadVersion:async(r,a,...e)=>null,...Ew};class bS{}class RS extends vw{}class DS{}class OS{}class PS{}class af{}class wS extends af{}class CS extends af{}class VS{}class Or{static initReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=V(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=bi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),a.readsValue.initChildren(null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}static hydrateReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=V(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=bi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}}class qa{static initWritesValues(a,e){const t=a.initialData.writesValues.reduce((s,l)=>{if(l.type===n.GenericReference||a.writesValues.some(d=>d.id===l.id))return s;const o=V(l,a.project);return o.setValueWriter(a,null),it.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class _S{}class BS{constructor(a){h(this,"eventName");h(this,"callbacks",[]);this.eventName=a}on(a){if(typeof a!="function")throw new Error("Event callback must be a function");this.callbacks.includes(a)||this.callbacks.push(a)}off(a){if(typeof a!="function")throw new Error("Event callback must be a function");this.callbacks=this.callbacks.filter(e=>e!==a)}destroy(){this.callbacks=[]}}class of{constructor(){h(this,"subscribedEvents",{});h(this,"on",this._on);h(this,"emit",this._emit);h(this,"off",this._off);h(this,"destroy",this._destroy)}getEvent(a){return this.subscribedEvents[a]||(this.subscribedEvents[a]=new BS(a)),this.subscribedEvents[a]}_on(a,e){this.getEvent(a).on(e)}_emit(a,...e){const t=this.getEvent(a);t&&t.callbacks.forEach(i=>{i.apply(null,e)})}_off(a,e){const t=this.getEvent(a);t&&(e?t.off(e):(t.destroy(),delete this.subscribedEvents[a]))}_destroy(){Object.keys(this.subscribedEvents).forEach(a=>{this._off(a)}),this.subscribedEvents={}}}var Bt=(r=>(r.DEFINITION_ENTITY_ADDED="definition-entity-added",r.DEFINITION_ENTITY_REMOVED="definition-entity-removed",r.DEFINITION_ENTITY_UPDATED="definition-entity-updated",r.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",r.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",r.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",r.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",r.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",r.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",r))(Bt||{});function MS(r,a){a.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(t=>{t!=="constructor"&&Object.defineProperty(r.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t))})})}class Tw extends lt{constructor(...a){super(...a),Object.assign(this,new of)}}MS(Tw,[of]);const re=class re extends Tw{constructor(e){super(e);h(this,"initialData");h(this,"id");h(this,"type",n.Project);h(this,"name",null);h(this,"description",null);h(this,"x");h(this,"y");h(this,"entities",[]);h(this,"projects",[]);h(this,"functions",[]);h(this,"events",[]);h(this,"variableDeclarations",[]);h(this,"variableInstances",[]);h(this,"conditions",[]);h(this,"operations",[]);h(this,"functionCalls",[]);h(this,"loops",[]);h(this,"searches",[]);h(this,"primitives",[]);h(this,"builtInBaseEntities",[]);h(this,"operationDeclarations",[]);h(this,"globalEventActionDescriptors",[]);h(this,"loopDeclarations",[]);h(this,"loopDeclarationsBodies",[]);h(this,"conditionDeclarations",[]);h(this,"valueDescriptors",[]);h(this,"dataTypes",[]);h(this,"project");h(this,"instances",{});h(this,"builtInInstances",{});h(this,"deletedInstances",{});h(this,"errors",[]);h(this,"references",[]);h(this,"history",[]);h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"onCloseChangeSetCallback",null);h(this,"onRequestActiveValueCallback",null);this.initialData=e,this.id=e.id,this.name=e.name,this.description=e.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!re.UUID||re.UUID.isBackup)&&(re.UUID=Wo==null?void 0:Wo()),re.UUID||(re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:t=>t})}catch(t){console.error("Error initializing UUID module",t),re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){re.UUID=e}static new(e=null){return{id:re.UUID.uuid(),version:re.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||re.sessionAuthor,previousVersion:null,deleted:!1,type:n.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingChangeSets(){const e=this.history.find(t=>t.dirty&&!t.open);e&&await this.closeChangeSet(e)}onRequestActiveValue(e){this.onRequestActiveValueCallback=e}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingChangeSets()}async closeChangeSet(e){const t=this.history.findIndex(l=>l.id===e.id),i=this.history.slice(0,t),s=i[i.length-1];if(!(s!=null&&s.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(e)).success&&(e.dirty=!1,this.closePendingChangeSets());return}}toLatestChangeSet(e,t,i,s=!1,l="here-this"){if(!this.history.length)return new b(this,e,t,i,s,l);const o=this.history[this.history.length-1];return o.open?o:this.addChangeSet(new b(this,e,t,i,s,l))}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(l=>l.id===(e==null?void 0:e.id));if(t)return t;const i=this.history.find(l=>l.open);if(i)throw console.warn("Previous still open: ",i),console.warn("New change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>E(e==null?void 0:e.timestamp).isBefore(E(l==null?void 0:l.timestamp)));return s===-1?this.history.push(e):this.history.splice(s,0,e),e}discardChangeSet(e){const t=this.history.findIndex(i=>i.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}redo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async i=>{await t.init(this),i(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=re.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new re(this);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new re(u)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=null){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.validate(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e){const t=[],i=[],s=[],l=[];return this.subscribe(),this.subscribeToDependencies(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.projects=this.initialData.projects.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableInstances=this.initialData.variableInstances.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.conditions=this.initialData.conditions.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.operations=this.initialData.operations.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functions=this.initialData.functions.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functionCalls=this.initialData.functionCalls.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.loops=this.initialData.loops.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.searches=this.initialData.searches.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.getBuiltIn(e)?null:this.instances[e]||null}getBuiltIn(e){return this.builtInInstances[e]||null}findSubscribedInstanceFromReference(e){return this.instances[e.entityId]||null}findSubscribedBuiltInInstanceFromReference(e){return this.builtInInstances[e.entityId]||null}metaSync(e,t=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(i=>i.toFlat(e)),...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e)),...this.projects.flatMap(i=>i.toFlat(e)),...this.variableDeclarations.flatMap(i=>i.toFlat(e)),...this.variableInstances.flatMap(i=>i.toFlat(e)),...this.conditions.flatMap(i=>i.toFlat(e)),...this.operations.flatMap(i=>i.toFlat(e)),...this.functionCalls.flatMap(i=>i.toFlat(e)),...this.loops.flatMap(i=>i.toFlat(e)),...this.searches.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(i=>i.toFlatIds(e)),...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e)),...this.projects.flatMap(i=>i.toFlatIds(e)),...this.variableDeclarations.flatMap(i=>i.toFlatIds(e)),...this.variableInstances.flatMap(i=>i.toFlatIds(e)),...this.conditions.flatMap(i=>i.toFlatIds(e)),...this.operations.flatMap(i=>i.toFlatIds(e)),...this.functionCalls.flatMap(i=>i.toFlatIds(e)),...this.loops.flatMap(i=>i.toFlatIds(e)),...this.searches.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,i=new Set,s=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(l=>{if(s.includes(l)){t.set(l,l);return}t.set(l,re.UUID.uuid())}),i.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),projects:this.projects.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableDeclarations:this.variableDeclarations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableInstances:this.variableInstances.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),conditions:this.conditions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),operations:this.operations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functions:this.functions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),events:this.events.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functionCalls:this.functionCalls.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),loops:this.loops.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),searches:this.searches.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null}))}}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+re.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(s=>s.toReference(e)),functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),projects:this.projects.map(s=>s.toReference(e)),variableDeclarations:this.variableDeclarations.map(s=>s.toReference(e)),variableInstances:this.variableInstances.map(s=>s.toReference(e)),conditions:this.conditions.map(s=>s.toReference(e)),operations:this.operations.map(s=>s.toReference(e)),functionCalls:this.functionCalls.map(s=>s.toReference(e)),loops:this.loops.map(s=>s.toReference(e)),searches:this.searches.map(s=>s.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(i=>i.toFlatJSON(e)),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e)),...this.projects.flatMap(i=>i.toFlatJSON(e)),...this.variableDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.variableInstances.flatMap(i=>i.toFlatJSON(e)),...this.conditions.flatMap(i=>i.toFlatJSON(e)),...this.operations.flatMap(i=>i.toFlatJSON(e)),...this.functionCalls.flatMap(i=>i.toFlatJSON(e)),...this.loops.flatMap(i=>i.toFlatJSON(e)),...this.searches.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e)),...this.projects.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(i=>i.toFlatGenerationTarget(e)),...this.conditions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.operations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.loops.flatMap(i=>i.toFlatGenerationTarget(e)),...this.searches.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=Cq(),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}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(i=>i.id===e.id);if(t>-1){const i=this.entities[t];return this.entities.splice(t,1),i}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(i=>i.id===e.id);if(t>-1){const i=this.functions[t];return this.functions.splice(t,1),i}return null}removeExternalProject(e){const t=this.projects.findIndex(i=>i.id===e.id);if(t>-1){const i=this.projects[t];return this.projects.splice(t,1),i}return null}removeGlobalEvent(e){const t=this.events.findIndex(i=>i.id===e.id);if(t>-1){const i=this.events[t];return this.events.splice(t,1),i}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(i=>i.id===e.id);if(t>-1){const i=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),i}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.ReturnStatement||l.type===n.ContinueStatement||l.type===n.BreakStatement)]},[])]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=He(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[])]}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(i=>{if(!i.declaration){const s=i.initialData,l=s.declaration.entityId||s.declaration.id,o=t.find(d=>d.id===l);o&&i.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===J.PERSISTED_ENTITY)||null}requestActiveValue(e){var i;const t=(i=this.onRequestActiveValueCallback)==null?void 0:i.call(this,e);return t?t||null:e.getDefaultValue()}};h(re,"sessionAuthor","1"),h(re,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),h(re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(re,"type",n.Project),h(re,"USER_MANAGED_PARENT_TYPES",[]),h(re,"PARENT_TYPES",[...re.USER_MANAGED_PARENT_TYPES]),h(re,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(re,"BASE_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,...re.INMUTABLE_BASE_PROPERTIES]),h(re,"MUTABLE_META_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,"x","y"]),h(re,"INMUTABLE_META_PROPERTIES",[...re.INMUTABLE_BASE_PROPERTIES]),h(re,"META_PROPERTIES",[...re.MUTABLE_META_PROPERTIES,...re.INMUTABLE_META_PROPERTIES]),h(re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(re,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),h(re,"UPSTREAM_PROPERTIES",[...re.MUTABLE_UPSTREAM_PROPERTIES,...re.INMUTABLE_UPSTREAM_PROPERTIES]),h(re,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),h(re,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(re,"DOWNSTREAM_PROPERTIES",[...re.MUTABLE_DOWNSTREAM_PROPERTIES,...re.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(re,"PROPERTIES",[...re.META_PROPERTIES,...re.UPSTREAM_PROPERTIES,...re.DOWNSTREAM_PROPERTIES]);let m=re;var Iw=(r=>(r.PersistChangeSet="persist-change-set",r.CreateSingle="create-single",r.CreateBulk="create-bulk",r.CreateSingleNested="create-single-nested",r.CreateBulkNested="create-bulk-nested",r.Update="update",r.Clone="clone",r.Delete="delete",r.Load="load",r.LoadNested="load-nested",r.LoadVersion="load-version",r))(Iw||{});class Aw extends We{constructor(e){super(Bi,e);h(this,"id",Qe.Parallel);h(this,"name",Qe.Parallel);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",Bi);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Bi.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Bi.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Bi.error?V(Bi.error,this.project):null}}class bw extends We{constructor(e){super(Ht,e);h(this,"id",Ht.id);h(this,"name",Ht.name);h(this,"description",Ht.description);h(this,"version",Ht.version);h(this,"autoexecutable",!1);h(this,"initialData",Ht);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Ht.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Ht.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Ht.error?V(Ht.error,this.project):null}}class Rw extends We{constructor(e){super(ur,e);h(this,"id",Qe.Sequential);h(this,"name",Qe.Sequential);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",ur);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=ur.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=ur.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=ur.error?V(ur.error,this.project):null}}class NS extends We{constructor(a){super(js,a)}}class LS extends We{constructor(a){super(cn,a)}}class jS extends We{constructor(e){super(fn,e);h(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[et.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[et.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[et.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-entity-to-match-validate-data"))){const i=this.project.requestActiveValue(e),s=i==null?void 0:i.valueAsTypeSingle;return t==null||t.attemptAutoclose("get-entity-to-match-validate-data",this.id),s}syncOperationInstance(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const i=[],s=[],l=[],o=[],d=this.getEntityToMatchInputMap(e);if(d){const{added:c,updated:T,removed:I,affected:D}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...T),s.push(...c),l.push(...I),o.push(...D)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:T,removed:I,affected:D}=this.syncDataToValidateInputMapDataType(u,t);i.push(...T),s.push(...c),l.push(...I),o.push(...D)}const f=this.getOutputDataOutputMap(e);if(f){const{added:c,updated:T,removed:I,affected:D}=this.syncOutputDataOutputMapDataType(f,t);i.push(...T),s.push(...c),l.push(...I),o.push(...D)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var f,c,T,I,D,P,C,M,G,_,g,q,S,K,de;const i=[],s=[],l=[],o=[];if(((f=e.declaration)==null?void 0:f.id)!==k.operation[et.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};const d=this.project.requestActiveValue(e),u=d==null?void 0:d.valueAsTypeSingle;if(!e.dataType){const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:((c=e.declaration.dataType)==null?void 0:c.options)||null,implementationChooseOne:((T=e.declaration.dataType)==null?void 0:T.implementationChooseOne)||!1,staticEntities:((I=e.declaration.dataType)==null?void 0:I.staticEntities)??null,interactiveEntities:((D=e.declaration.dataType)==null?void 0:D.interactiveEntities)??null,actionEntities:((P=e.declaration.dataType)==null?void 0:P.actionEntities)??null,isList:((C=e.declaration.dataType)==null?void 0:C.isList)||!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:(u==null?void 0:u.toJSON())||null,like:!0,inferred:!0,parent:e.toReference()},z=V(me,e.project);z.hydrateAncestors(),z.setParent(e,t),z.initChildren(t),z.setEntity(u),t==null||t.add(z,A.Added),i.push(z),e.setDataType(z)}return(K=e.dataType)==null||K.metaSync({inferred:!0,like:!1,asType:!0,options:((M=e.declaration.dataType)==null?void 0:M.options)||null,implementationChooseOne:((G=e.declaration.dataType)==null?void 0:G.implementationChooseOne)||!1,staticEntities:((_=e.declaration.dataType)==null?void 0:_.staticEntities)??null,interactiveEntities:((g=e.declaration.dataType)==null?void 0:g.interactiveEntities)??null,actionEntities:((q=e.declaration.dataType)==null?void 0:q.actionEntities)??null,isList:((S=e.declaration.dataType)==null?void 0:S.isList)||!1},t),(de=e.dataType)==null||de.setEntity(u),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var c,T,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[et.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=V(D,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(T=e.dataType)==null||T.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(f),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var T,I,D;const i=[],s=[],l=[],o=[];if(((T=e.declaration)==null?void 0:T.id)!==k.operation[et.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const f=this.project.requestActiveValue(d),c=(f==null?void 0:f.valueAsTypeSingle)||null;if(!e.dataType){const P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:(c==null?void 0:c.toJSON())||null,like:!0,inferred:!0,parent:e.toReference()},C=V(P,e.project);C.hydrateAncestors(),C.setParent(e,t),C.initChildren(t),C.setEntity(c),t==null||t.add(C,A.Added),i.push(C),e.setDataType(C)}return(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t),(D=e.dataType)==null||D.setEntity(c),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var s,l,o;if(((s=e.declaration)==null?void 0:s.id)===k.operation[et.Validate].inputs.entityToMatch.id){const{added:d,updated:u,removed:f,affected:c}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(u),added:p(d),removed:p(f),affected:p(c),self:e.dataType}}if(((l=e.declaration)==null?void 0:l.id)===k.operation[et.Validate].inputs.dataToValidate.id){const{added:d,updated:u,removed:f,affected:c}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(u),added:p(d),removed:p(f),affected:p(c),self:e.dataType}}const i=(o=e.declaration)==null?void 0:o.getDataType(t);if(i&&i.isResolved)return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:i};if(e.readsValue){const d=$i(e.readsValue,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:d}}return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var i;if(((i=e.declaration)==null?void 0:i.id)===k.operation[et.Validate].outputs.outputEntity.id){const{added:s,updated:l,removed:o,affected:d}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:p(l),added:p(s),removed:p(o),affected:p(d),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class US extends We{constructor(a){super(Ad,a)}}class $S extends We{constructor(a){super(Rd,a)}}class GS extends We{constructor(a){super(Dd,a)}}class gS extends We{constructor(a){super(eo,a)}}class FS extends We{constructor(a){super(Ka,a)}}class xS extends We{constructor(a){super(Ls,a)}}function kS(r){const a=[new Rw(r),new Aw(r),new bw(r),new NS(r),new LS(r),new jS(r),new gS(r),new US(r),new GS(r),new $S(r),new FS(r),new xS(r),new We(Id,r),new We(Td,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class Dw extends Fi{constructor(e){super(Nt,e);h(this,"initialData");h(this,"id",J.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",J.PERSISTED_ENTITY);h(this,"description",Nt.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Nt.abstract);h(this,"static",Nt.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=Nt,this.project=e,this.id=Nt.id,this.version=Nt.version,this.name=Nt.name,this.static=Nt.static,this.abstract=Nt.abstract,this.properties=this.initialData.properties.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.methods=this.initialData.methods.map(t=>{const i=V(t,this.project);return i.parent=this,i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=V(t,this.project);return i.parent=this,i}),this.extends=this.initialData.extends.map(t=>V(t,this.project))}}var Ow=(r=>(r.StatusCodeMustBeNumber="status-code-must-be-number",r.StatusCodeMustBeBetween100And599="status-code-must-be-between-100-and-599",r))(Ow||{});function Pw(r,a){const e=[];if(typeof a!="number"){const t=new Ye({id:r.id+"--status-code-must-be-number",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number.`,issue:null,severity:O.Error,code:"status-code-must-be-number",entity:r});return e.push(t),{errors:e,override:a}}if(a<100){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}if(a>599){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}return{errors:e,override:a}}class ww extends Fi{constructor(e){super(ai,e);h(this,"initialData");h(this,"id",J.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",J.PERSISTED_ENTITY);h(this,"description",ai.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",ai.abstract);h(this,"static",ai.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=ai,this.project=e,this.id=ai.id,this.version=ai.version,this.name=ai.name,this.static=ai.static,this.abstract=ai.abstract,this.properties=this.initialData.properties.map(l=>{const o=V(l,this.project);return o.setParent(this,null),o.initChildren(null),o}),this.methods=this.initialData.methods.map(l=>{const o=V(l,this.project);return o.parent=this,o}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const o=V(l,this.project);return o.parent=this,o}),this.extends=this.initialData.extends.map(l=>V(l,this.project));const t=this.properties.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.path.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(l,o)=>uP(l,o);const i=this.abstractMethods.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id);if(!i)throw new Error("Handler method not found in endpoint entity");const s=i.outputs.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.outputs.statusCode.id);if(!s)throw new Error("Status code output not found in handler method");s.codeNativeValueValidation=(l,o)=>Pw(l,o)}}const ZS="test_primitive_entities_export";class qS extends Fi{constructor(e){super(Ot,e);h(this,"initialData");h(this,"id",J.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",J.PERSISTED_ENTITY);h(this,"description",Ot.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Ot.abstract);h(this,"static",Ot.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(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(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.extends=this.initialData.extends.map(i=>V(i,this.project));const t=this.properties.find(i=>i.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(i,s)=>pP(i,s)}}function JS(r){const a=[new Dw(r),new ww(r),new qS(r),new Fi(Ot,r),new Fi(Eo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function WS(r){const a=[new ni(ae,r),new ni(ar,r),new ni(Ee,r),new ni(fd,r),new ni(Ct,r),new ni(or,r),new ni(Zi,r),new ni(lr,r),new ni(Wn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function SS(r){const a=[new We(Io,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function zS(r){const a=[new We(gs,r),new We(wr,r),new We($s,r),new We(Yn,r),new We(Hn,r),new We(lo,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new We(fo,r),new We(Gs,r),new We(po,r),new We($d,r),new We(gd,r),new We(uo,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function YS(r){const a=[new ir(Ao,r),new ir(su,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function HS(r){const a=[new We(En,r),new We(ts,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Fn={},ad={},Ja={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function Cw(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new zl(e),s=new Set;t[e.id]=e,s.add(e.id);const l=E().toISOString();Object.values(t).forEach(u=>{!u||i.allBuiltInEntityIds.includes(u.id)||s.add(u.id)}),i.order=Array.from(s),i.flatRecord=t,i.orderEntities();const o=od(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new b(o,m.sessionAuthor,l,o,!0,"project-init-from-fetch-result")):null;return i.visit(u=>{if(u.id===o.id)return;const f=V(u,o);f.hydrateAncestors(),f.addSelfToProject(null)}),a?(i.visit(u=>{const f=o.get(u.id);f&&f.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):ld(o,l).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.attemptAutoclose("project-init-from-fetch-result",o.id),o}async function KS(r,a=Ja){const e={...Ja,...a};if(e.empty)return{data:{project:{id:r.id,type:n.Project,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(e.mock){const i={...cp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{try{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})}catch(s){console.error("Error fetching project: ",s),i({data:null})}})}function od(r){const a=new m(r);return WS(a),JS(a),kS(a),SS(a),zS(a),YS(a),HS(a),Array.from(new Set([...a.getAllBuiltInIds(),...Gi()])).forEach(t=>{if(!a.builtInInstances[t]&&a.instances[t])a.builtInInstances[t]=a.instances[t],delete a.instances[t];else if(!a.builtInInstances[t])throw new Error(`Built in entity was not properly initialized: ${t}`)}),a}function ld(r,a){return r.instancesList.filter(t=>E(t.createdAt).isAfter(E(a)||!!t.previousVersion))}function XS(r,{enrich:a}={enrich:!0}){const e=new Map,t=Array.from(new Set([...r.getAllBuiltInIds(),...Gi()]));Object.keys(r.instances).forEach(u=>{if(t.includes(u)){e.set(u,u);return}const f=r.get(u);if(!nd(f,{...r.instances,...r.builtInInstances}).every(I=>!t.includes(I))){e.set(u,u);return}e.set(u,m.UUID.uuid())});const i=E().toISOString(),s=r.toShallowJSON({seenEntityMaps:e});s.previousVersion=null,s.createdAt=i,s.version=m.UUID.uuid();const l=od(s),o=a?l.addChangeSet(new b(l,m.sessionAuthor,i,l,!0,"project-clone")):null,d=new zl(r);return d.visit(u=>{const f=u.toShallowJSON({seenEntityMaps:e});f.previousVersion=null,f.createdAt=i,f.version=m.UUID.uuid();const c=V(f,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,A.Added)}),a?(d.visit(u=>{const f=l.get(e.get(u.id));f&&f.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):ld(l,i).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.attemptAutoclose("project-clone",l.id),l}function Vw(r,{enrich:a}={enrich:!0}){const e=od(r),t=E().toISOString(),i=a?e.addChangeSet(new b(e,m.sessionAuthor,t,e,!0,"project-init")):null;i&&(i.type=_c.Automatic);const s=new zl(r);return s.visit(l=>{const o=V(l,e);o.hydrateAncestors(),o.addSelfToProject(i)}),a?(s.visit(l=>{const o=e.get(l.id);o&&o.afterAllChildrenInitialized(i)}),e.afterAllChildrenInitialized(i)):ld(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.attemptAutoclose("project-init",e.id),e}async function QS(r,a=Ja){const e={...Ja,...a};if(r.id&&Fn[r.id]&&!e.ignoreCache)return Fn[r.id];if(r.id&&ad[r.id]&&!e.ignoreCache)return await ad[r.id],Fn[r.id];const t=KS(r,e);r.id&&(ad[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=Vw(cp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=Cw(i.data,{enrich:!!e.enrich}),Fn[r.id]=s,r.id&&delete ad[r.id],s}return null}function ez(r){return Fn[r.id]&&delete Fn[r.id],null}y.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=kc,y.ALL_BUILT_IN_BASE_ENTITIES=WT,y.ALL_BUILT_IN_CONDITION_ENTITIES=aI,y.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=lI,y.ALL_BUILT_IN_LOOP_BODY_ENTITIES=IE,y.ALL_BUILT_IN_LOOP_ENTITIES=TE,y.ALL_BUILT_IN_OPERATION_ENTITIES=B0,y.ALL_BUILT_IN_PRIMITIVE_ENTITIES=Tf,y.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=hI,y.ALL_BUILT_IN_VALUE_DESCRIPTORS=fI,y.ActionDescriptorState=We,y.ActionInputMapState=nW,y.ActionOutputMapState=oW,y.AppendToListOperationInputIds=wy,y.AppendToListOperationOutputIds=Cy,y.ArgumentDeclarationDependencyField=g1,y.ArgumentDeclarationState=br,y.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Gc,y.BUILT_IN_BASE_ENTITY_IDS=k,y.BUILT_IN_ENTITY_TYPES=si,y.BaseCanvasDraggableState=DS,y.BaseEntityNames=J,y.BaseState=RS,y.BaseValueDescriptorIds=Jn,y.BreakStatementDependencyField=Z1,y.BreakStatementState=tn,y.BuiltInBaseEntityState=Fi,y.CACHED_PROJECTS_BY_ID=Fn,y.CALLABLE_ENTITIES_EXPLANATION=mW,y.CALLABLE_TYPES=xi,y.CALLER_ENTITIES_EXPLANATION=z1,y.CALLER_TYPES=ki,y.CALLS_UPDATE_EXPLANATION=nn,y.COMPARISON_CONDITIONS=nI,y.CONDITIONS=sI,y.CUSTOM_ENTITY_OPERATIONS=Ym,y.CallableEntityClass=PS,y.CallerEntityClass=af,y.ChangeSet=b,y.ChangeSetChangeCaptureType=_c,y.ChangeSetEntityChangeType=A,y.ChildEntityState=OS,y.CommonStringValidationErrorCodes=dP,y.ComparisonOperatorTypes=ft,y.ConditionDependencyField=D1,y.ConditionState=zr,y.ContinueStatementDependencyField=E1,y.ContinueStatementState=Gt,y.CreateNewInputIds=Rm,y.CreateNewOutputIds=Dm,y.DRAGGABLE_CALLABLE_TYPES=cd,y.DRAGGABLE_CALLER_TYPES=pf,y.DRAGGABLE_ELEMENT_TYPES=Ha,y.DRAGGABLE_EXECUTABLE_TYPES=Lw,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Ya,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=pd,y.DataTypeCompatibilityTypes=wi,y.DataTypeDependencyField=Bc,y.DataTypeParentChildRelation=wt,y.DataTypeState=Zr,y.DefinitionEntityDependencyField=sd,y.DefinitionEntityState=dn,y.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=AS,y.ENTITIES_WITH_VALLUES_EXPLANATION=Zl,y.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=U,y.ENTITY_RECUSION_OPTIONS_DEFAULTS=W,y.ENTITY_TYPES=jw,y.ENTITY_WITH_DECLARATION_TYPES=Mw,y.ENTITY_WITH_LOGIC_SCOPE_TYPES=ht,y.ENTITY_WITH_NAMES_TYPES=cf,y.ENTITY_WITH_PARENT_TYPES=_w,y.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=df,y.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=Bw,y.ENTITY_WITH_VALUE_TYPES=lf,y.ENTRY_POINT_ENTITIES_EXPLANATION=La,y.ENTRY_POINT_TYPES=rt,y.EVENT_TYPES=qn,y.EXECUTABLE_TYPES=Nw,y.EXECUTION_OPERATIONS=bm,y.EndpointEntity=ww,y.EntityAction=Iw,y.EntityError=Ye,y.EntityErrorSeverity=O,y.EntityGenerationError=w,y.EntityGenerationErrorCode=R,y.EntityInstanceErrorCode=x,y.EntityOperations=et,y.EntityType=n,y.EntityWithLogicScopeClass=_S,y.EntityWithValueClass=VS,y.EntryPointEntityClass=wS,y.Events=of,y.ExecutionOperations=Qe,y.ExecutionTerminationType=A1,y.FunctionCallDependencyField=sP,y.FunctionCallState=an,y.FunctionDeclarationDependencyField=u1,y.FunctionDeclarationState=kr,y.GET_PROJECT_OPTIONS_DEFAULTS=Ja,y.GLOBAL_EVENT_DECLARATIONS=oI,y.GetLastInListOperationInputIds=yy,y.GetLastInListOperationOutputIds=my,y.GlobalEventNames=sr,y.GlobalEventState=Wr,y.HTTPOperations=Ut,y.HTTPStatucCodeValidationErrorCodes=Ow,y.HTTP_OPERATIONS=V0,y.InputMapDependencyField=j1,y.InputMapState=er,y.InstalledProjectState=Xr,y.InternalCallDependencyField=N1,y.InternalCallState=Qr,y.JoinListOperationInputIds=jh,y.JoinListOperationOutputIds=Uh,y.LIST_OPERATIONS=xy,y.ListOperations=ye,y.LiteralValueDependencyField=x1,y.LiteralValueState=en,y.LoopDependencyField=b1,y.LoopState=Sr,y.LoopTypes=ee,y.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=sn,y.NUMBER_OPERATIONS=Yf,y.NumberOperations=tt,y.OPERATION_DECLARATIONS=_0,y.OperationDependencyField=f1,y.OperationState=qr,y.OutputMapDependencyField=$1,y.OutputMapParentChildRelation=Zn,y.OutputMapState=tr,y.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=ql,y.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=rn,y.PASS_THROUGH_CALLABLE_TYPES=dt,y.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=uf,y.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=xc,y.ParallelExecutionOperation=Aw,y.PassThroughCallableEntityClass=CS,y.PersistedEntity=Dw,y.PersistedEntityMethods=hi,y.PrimitiveEntityState=ni,y.PrimitiveTypes=N,y.ProjectState=m,y.ProjectStateEvents=Bt,y.PropertyDependencyField=l1,y.PropertyState=xr,y.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=Ew,y.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=vW,y.ReturnDeclarationDependencyField=y1,y.ReturnDeclarationState=ri,y.ReturnStatementDependencyField=Mc,y.ReturnStatementState=Jr,y.STANDALONE_CONDITIONS=YT,y.STRING_OPERATIONS=Lh,y.ScopeCompatibilityType=id,y.SearchDependencyField=V1,y.SearchState=Kr,y.SequentialExecutionOperation=Rw,y.SequentialExecutionOperationInputIds=dm,y.SequentialExecutionOperationOutputIds=um,y.SharedEntityErrorCode=$,y.SharedStateFunctionality=vw,y.SplitListOperationInputIds=Kh,y.SplitListOperationOutputIds=Xh,y.StandaloneOperatorTypes=Ri,y.StringOperations=Ae,y.TERMINATION_TYPES=ot,y.Traverser=zl,y.USER_MANAGED_ENTITY_TYPES=ff,y.UserManagedEntityStateTemplate=bS,y.VALUE_READING_ENTITIES_EXPLANATION=Fc,y.VALUE_READING_TYPES=Pr,y.VALUE_WRITING_ENTITIES_EXPLANATION=Y1,y.VALUE_WRITING_TYPES=Et,y.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=gc,y.VARIABLE_TYPES=it,y.ValueAutogenerationType=vt,y.ValueDescriptorDependencyField=J1,y.ValueDescriptorParentChildRelation=L,y.ValueDescriptorState=ir,y.ValueReadingEntityClass=Or,y.ValueWritingEntityClass=qa,y.VariableDeclarationDependencyField=w1,y.VariableDeclarationState=Hr,y.VariableInputMapState=rW,y.VariableInstanceDependencyField=Lc,y.VariableInstanceState=Yr,y.VariableOutputMapState=aW,y.WaitOperation=bw,y.WaitOperationInputIds=im,y.WaitOperationOutputIds=rm,y.actionDescriptorValidation=YJ,y.appendToListOperation=eo,y.appendToListOperationElementToAppendArgument=Pd,y.appendToListOperationElementToAppendArgumentParentRef=Uy,y.appendToListOperationElementToAppendArgumentRef=By,y.appendToListOperationError=Fy,y.appendToListOperationErrorParentRef=gy,y.appendToListOperationListArgument=Od,y.appendToListOperationListArgumentParentRef=jy,y.appendToListOperationListArgumentRef=Vy,y.appendToListOperationListDataType=_y,y.appendToListOperationResultListDataType=Ly,y.appendToListOperationResultListReturn=Gy,y.appendToListOperationResultListReturnParentRef=$y,y.appendToListOperationResultListReturnRef=Ny,y.appendToListOperationSecondListDataType=My,y.applyNewScope=Q,y.argumentDeclarationValidation=lW,y.asGenerationActionExample=rr,y.booleanPrototype=ar,y.breakStatementValidation=pW,y.calculateNewParentBasedOnCallers=zc,y.capitalizeFirstLetter=_t,y.changeSetJSONRecordToUniqueIds=jJ,y.checkAreDataTypesCompatible=Ci,y.checkAreDefinitionEntitiesCompatibleAsDataType=SO,y.checkArePropertiesCompatibleAsDataType=WO,y.checkExtendsBaseEntity=rd,y.checkHasBaseEntity=gi,y.checkHasMetadataChanged=pt,y.checkImplementationsOverlap=Dr,y.checkImplementsBaseEntity=HW,y.checkIsBranchDependentButNotDirectlyOnBranch=Ua,y.checkIsBranchDependentOnBranch=_W,y.checkIsCallableEntityReachable=Za,y.checkIsCanvasEntity=zW,y.checkIsDetachedBranch=lw,y.checkIsDetachedBranchShallow=nf,y.checkIsGlobalVariable=WW,y.checkIsGloballyDeclared=rf,y.checkIsMethod=pw,y.checkIsNestedScope=td,y.checkScopeCompatibility=ka,y.cloneProject=XS,y.conditionValidation=HJ,y.continueStatementValidation=JJ,y.convertToAbstract=PW,y.convertToNonAbstract=wW,y.convertToNonStatic=VW,y.convertToStatic=CW,y.countedLoopActionDescriptor=gs,y.countedLoopActionDescriptorDynamicReturnDeclaration=pE,y.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=uE,y.countedLoopActionDescriptorStringArgumentDeclaration=dE,y.countedLoopActionDescriptorStringArgumentDeclarationDataType=oE,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=sE,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=nE,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=aE,y.countedLoopActionDescriptorStringArgumentDeclarationParentRef=lE,y.countedLoopBodyActionDescriptor=fo,y.countedLoopBodyActionDescriptorAnyDynamicArgument=mE,y.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=yE,y.countedLoopBodyActionDescriptorAnyDynamicReturn=EE,y.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=vE,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=xd,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=fE,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=cE,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=hE,y.createDefinitionEntityFromJSONObject=Hl,y.createEntityError=fe,y.createNestedDataTypeForEntity=lP,y.createNewInstanceOperation=cn,y.createNewInstanceOperationEntityToInstanciateArgument=Mm,y.createNewInstanceOperationEntityToInstanciateArgumentRef=Vm,y.createNewInstanceOperationEntityToInstanciateDataType=_m,y.createNewInstanceOperationError=Um,y.createNewInstanceOperationErrorParentRef=jm,y.createNewInstanceOperationNewEntityDataArgument=Cm,y.createNewInstanceOperationNewEntityDataArgumentDataType=wm,y.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Pm,y.createNewInstanceOperationNewEntityDataArgumentParentRef=Om,y.createNewInstanceOperationOutputEntityDeclaration=Lm,y.createNewInstanceOperationOutputEntityDeclarationParentRef=Nm,y.createNewInstanceOperationRef=Bm,y.createSemanticId=s1,y.createStateFromGenerationTargetType=IS,y.createStateFromType=st,y.createStateFromTypeAndSubscribe=V,y.cronJobBuiltInBaseEntity=Eo,y.cronJobBuiltInBaseEntityExpressionProperty=qT,y.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Zw,y.cronJobBuiltInBaseEntityExpressionPropertyRef=kT,y.cronJobBuiltInBaseEntityRef=ZT,y.cronJobTriggeredFunctionDeclarationBlueprint=tu,y.cronJobTriggeredFunctionDeclarationBlueprintParentRef=FT,y.dataTypeCompatibilityToErrorExplanation=rP,y.dataTypeValidation=gJ,y.datePrototype=Zi,y.dateValueAutogenerationSchema=vp,y.definitionEntityToZodSchema=_I,y.definitionEntityValidation=mS,y.deletePersistedEntityMethod=eu,y.deletePersistedEntityMethodParentRef=OT,y.deleteRootProject=ez,y.endpointBuiltInBaseEntity=ai,y.endpointBuiltInBaseEntityRef=DE,y.endpointBuiltInBaseEntityRefFour=aT,y.endpointBuiltInBaseEntityRefThree=NE,y.endpointBuiltInBaseEntityRefTwo=VE,y.endpointBuiltInCorsProperty=OE,y.endpointBuiltInCorsPropertyDataType=RE,y.endpointBuiltInCorsPropertyDataTypeRef=AE,y.endpointBuiltInCorsPropertyRef=bE,y.endpointBuiltInMethodProperty=Zd,y.endpointBuiltInMethodPropertyDataType=ME,y.endpointBuiltInMethodPropertyDataTypeRef=_E,y.endpointBuiltInMethodPropertyRef=BE,y.endpointBuiltInPathProperty=kd,y.endpointBuiltInPathPropertyDataType=CE,y.endpointBuiltInPathPropertyDataTypeRef=PE,y.endpointBuiltInPathPropertyRef=wE,y.endpointPathParamsArgumentDeclaration=Jd,y.endpointPathParamsArgumentDeclarationRef=ZE,y.endpointPathParamsVariableDataType=qE,y.endpointPathParamsVariableDataTypeRef=kE,y.endpointReachedTriggerActionDescriptor=Kd,y.endpointReachedTriggerActionDescriptorRef=JE,y.endpointReachedTriggerActionDescriptorRefFour=zE,y.endpointReachedTriggerActionDescriptorRefThree=SE,y.endpointReachedTriggerActionDescriptorRefTwo=WE,y.endpointRequestBodyArgumentDeclaration=Sd,y.endpointRequestBodyArgumentDeclarationRef=$E,y.endpointRequestBodyVariableDataType=GE,y.endpointRequestHeadersArgumentDeclaration=qd,y.endpointRequestHeadersArgumentDeclarationRef=jE,y.endpointRequestHeadersVariableDataType=UE,y.endpointRequestHeadersVariableDataTypeRef=LE,y.endpointRequestQueryParamsArgumentDeclaration=Wd,y.endpointRequestQueryParamsArgumentDeclarationRef=FE,y.endpointRequestQueryParamsVariableDataType=xE,y.endpointRequestQueryParamsVariableDataTypeRef=gE,y.endpointResponseBodyDataType=nT,y.endpointResponseBodyReturnDeclaration=Hd,y.endpointResponseBodyReturnDeclarationRef=rT,y.endpointResponseCodeDataType=HE,y.endpointResponseCodeReturnDeclaration=zd,y.endpointResponseCodeReturnDeclarationDefaultValueParentRef=XE,y.endpointResponseCodeReturnDeclarationRef=YE,y.endpointResponseHeadersDataType=tT,y.endpointResponseHeadersDataTypeRef=QE,y.endpointResponseHeadersReturnDeclaration=Yd,y.endpointResponseHeadersReturnDeclarationRef=eT,y.endpointReturnStatementRef=KE,y.endpointReturnStatementRefThree=sT,y.endpointReturnStatementRefTwo=iT,y.enrichFromKnownEntities=$a,y.enumOptionsProperty=Ef,y.enumOptionsPropertyDataType=mf,y.enumOptionsPropertyDataTypeRef=hf,y.enumOptionsPropertyRef=yf,y.enumPrototype=or,y.enumPrototypeRef=vf,y.executionBuiltInBaseEntity=To,y.executionBuiltInEntityAbortMethod=iu,y.executionBuiltInEntityAbortMethodParentRef=JT,y.filterOutDuplicateEntities=p,y.filterOutDuplicateErrors=z3,y.findEntityFromKeys=Wc,y.findReferenceToSelfInList=PP,y.findReferencesToSelfInProject=gW,y.flattenActionDescriptor=wP,y.flattenArgumentDeclaration=CP,y.flattenBreakStatement=VP,y.flattenBuiltInBaseEntity=_P,y.flattenCalls=Vi,y.flattenCanvasAncestorsUntil=_s,y.flattenCondition=BP,y.flattenContinueStatement=MP,y.flattenDataType=LP,y.flattenDefinitionEntity=NP,y.flattenDefinitionEntityExtensionAndImplementationTypes=tf,y.flattenDefinitionEntityExtensionTypes=ga,y.flattenDefinitionEntityExtensions=Qc,y.flattenDefinitionEntityImplementations=ef,y.flattenDefinitionEntityImplementionTypes=Ga,y.flattenDerivedCanvasEntities=ci,y.flattenDetachedBranch=uw,y.flattenElementCalls=Te,y.flattenElementCallsOnTheSameScope=GW,y.flattenEntity=j,y.flattenFunctionCall=jP,y.flattenFunctionDeclaration=UP,y.flattenGlobalEvent=$P,y.flattenInputMap=GP,y.flattenInstalledProject=gP,y.flattenInternalCall=FP,y.flattenLiteralValue=xP,y.flattenLoop=kP,y.flattenOperation=ZP,y.flattenOutputMap=qP,y.flattenPrimitiveEntity=JP,y.flattenProject=WP,y.flattenProjectElements=OP,y.flattenProperty=SP,y.flattenRelatedCanvasElementsOnTheLeft=sw,y.flattenRelatedCanvasElementsOnTheRight=nw,y.flattenReturnDeclaration=zP,y.flattenReturnStatement=YP,y.flattenSearch=HP,y.flattenValueDescriptor=KP,y.flattenVariableDeclaration=XP,y.flattenVariableInstance=QP,y.flattenVariableReads=DP,y.flattenVariableWrites=RP,y.flattenVariables=He,y.fromChangeSetToRecordChangeSet=rS,y.fromZodParseToEntityGenerationErrors=jc,y.functionCallValidation=OW,y.functionDeclarationValidation=GJ,y.generate=SV,y.generateActionExample=EW,y.generateExecutionDataType=OJ,y.generateIdFromStrategy=yt,y.generateMutablePropertiesExplanation=Fl,y.generateRandomBoolean=rA,y.generateRandomDate=LI,y.generateRandomDateAfter=BI,y.generateRandomDateBefore=MI,y.generateRandomDateBetweenRange=NI,y.generateRandomNumber=XI,y.generateRandomNumberAfter=YI,y.generateRandomNumberBefore=HI,y.generateRandomNumberBetweenRange=KI,y.generateRandomText=iA,y.generateRandomTextAfter=QI,y.generateRandomTextBefore=eA,y.generateRandomTextBetweenRange=tA,y.generateUniqueUUID=zI,y.getAllActionDescriptorsForConditions=Sl,y.getAllActionDescriptorsForGlobalEvents=Jl,y.getAllActionDescriptorsForLoops=Wl,y.getAllActionDescriptorsForOperations=bW,y.getAllBuiltInEntityIds=Gi,y.getAllGloballyDeclaredFunctionDeclarationsExplanation=eP,y.getBaseBuiltInEntities=St,y.getBaseSchemaBasedOnType=W1,y.getBuiltInEntityOwner=ln,y.getCallableEntityReferenceSchema=Vt,y.getCallableEntityTypeSchema=LD,y.getCalledBy=Ai,y.getCallerEntityReferenceSchema=XZ,y.getCallerEntityTypeSchema=KZ,y.getCalls=Hc,y.getCanvasEntitiesDerivedFromInternalCalls=rw,y.getCanvasEntitiesDerivedFromWrites=Bs,y.getCanvasEntityDerivedFromValueReadingEntity=ed,y.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=iw,y.getCanvasEntityReferenceSchema=yq,y.getCanvasEntityTypeSchema=hq,y.getChildrenEntityWithValues=MW,y.getColumnProperties=eS,y.getCommonAncestor=Yc,y.getCommonChildren=cP,y.getDatabaseEntities=XW,y.getDatabaseEntity=tS,y.getDeclaration=Gn,y.getDeclarationOutputedError=sS,y.getDeepestScope=fw,y.getDraggableCallableEntityReferenceSchema=UD,y.getDraggableCallableEntityTypeSchema=jD,y.getDraggableCallerEntityReferenceSchema=eq,y.getDraggableCallerEntityTypeSchema=QZ,y.getDraggableExecutableEntityReferenceSchema=nq,y.getDraggableExecutableEntityTypeSchema=rq,y.getDraggablePassThroughCallableEntityReferenceSchema=Cl,y.getDraggablePassThroughCallableEntityTypeSchema=wl,y.getDraggablePlayableEntityReferenceSchema=dq,y.getDraggablePlayableEntityTypeSchema=lq,y.getEntitiesCreatedSinceInitialization=ld,y.getEntityArgumentDeclarations=Xc,y.getEntityInputMaps=ew,y.getEntityOutputMaps=ZW,y.getEntityReferenceSchema=fq,y.getEntityReturnDeclarations=tw,y.getEntityTypeSchema=cq,y.getEntityWithLogicScopeReferenceSchema=Tr,y.getEntityWithLogicScopeTypeSchema=sq,y.getEntityWithValueReferenceSchema=ND,y.getEntityWithValueTypeSchema=HZ,y.getEntryPointEntityReferenceSchema=Pt,y.getEntryPointEntityTypeSchema=Gr,y.getEventEntityReferenceSchema=Ol,y.getEventEntityTypeSchema=Dl,y.getExecutableEntityReferenceSchema=iq,y.getExecutableEntityTypeSchema=tq,y.getExtendedBuiltInEntity=qW,y.getExtendedDefinitionEntity=ow,y.getFirstNonLoopScopeOwner=It,y.getGenerationTargetSchemaBasedOnType=S1,y.getHeadIfPartOfDetachedBranch=dw,y.getHighestScope=cw,y.getImplementedBuiltInEntity=JW,y.getIsInteractive=Fa,y.getLastInListOperation=Dd,y.getLastInListOperationError=Py,y.getLastInListOperationErrorParentRef=Oy,y.getLastInListOperationInputListArgument=by,y.getLastInListOperationInputListArgumentParentRef=Ay,y.getLastInListOperationInputListArgumentRef=vy,y.getLastInListOperationInputListDataType=Ey,y.getLastInListOperationOutputElementDataType=Iy,y.getLastInListOperationOutputElementReturn=Dy,y.getLastInListOperationOutputElementReturnParentRef=Ry,y.getLastInListOperationOutputElementReturnRef=Ty,y.getLinkedEntitiesFromArgumentDeclaration=$W,y.getLowestPersistedEntityImplementation=aw,y.getParentCallableEntity=fP,y.getParentCallerEntity=yP,y.getParentCanvasEntities=gt,y.getParentCanvasEntity=Rt,y.getParentCanvasEntityFromTransfer=Kl,y.getParentEntryPoint=BW,y.getParentPassthroughCallableEntity=hP,y.getPassThroughCallableEntityReferenceSchema=nt,y.getPassThroughCallableEntityTypeSchema=Pl,y.getPeristedEntities=KW,y.getPlayableEntityReferenceSchema=oq,y.getPlayableEntityTypeSchema=aq,y.getProject=QS,y.getPrototypeByType=xa,y.getRecusriveParentsIds=nd,y.getReferenceEntityId=B,y.getReferencedEntitiesStateOrErrors=kl,y.getReferencedEntityStateOrErrors=Uc,y.getReferencedIds=Ql,y.getRelatedCanvasElementsOnTheLeft=gn,y.getRelatedCanvasElementsOnTheLeftFromTransfer=FW,y.getRelatedCanvasElementsOnTheRight=on,y.getRootEntryPointScopeOwner=sf,y.getScopeOwner=zt,y.getStateClassFromType=iS,y.getTerminationReferenceSchema=pq,y.getTerminationTypeSchema=uq,y.getTouchedCanvasEntitiesFromChangeSet=nS,y.getUsedArgFromDeclaration=xW,y.getUsedReturnFromDeclaration=kW,y.getValueReadingEntityReferenceSchema=MD,y.getValueReadingEntityTypeSchema=Er,y.getValueWritingEntityReferenceSchema=YZ,y.getValueWritingEntityTypeSchema=Ra,y.getVariableFromInputMapping=vP,y.getVariableFromReturnVariablePointer=IP,y.getVariableReferenceSchema=$r,y.getVariableTypeSchema=Mn,y.getVariablesFromArgumentDeclarations=Xl,y.getVariablesFromInputMaps=EP,y.getVariablesFromOutputMapping=AP,y.getVariablesFromOutputMaps=bP,y.getVariablesFromReturnDeclarations=TP,y.getVariablesInSameOrHigherScope=bc,y.getWrites=Kc,y.globalEventValidation=WJ,y.groupCallsBasedOnParallelizableExecution=LW,y.handleAfterEntityImplementationSideEffects=oP,y.handleBeforeEntityImplementationSideEffects=aP,y.httpRequestBodyArgument=no,y.httpRequestBodyArgumentRef=l0,y.httpRequestBodyDataType=d0,y.httpRequestHeadersArgument=ro,y.httpRequestHeadersArgumentRef=a0,y.httpRequestHeadersDataType=o0,y.httpRequestMethodArgument=to,y.httpRequestMethodArgumentRef=n0,y.httpRequestMethodDataType=s0,y.httpRequestMethodDataTypeRef=i0,y.httpRequestOperation=js,y.httpRequestOperationErrorValueDescriptor=Md,y.httpRequestOperationErrorValueDescriptorDatatype=C0,y.httpRequestOperationErrorValueDescriptorRef=w0,y.httpRequestOperationRef=R0,y.httpRequestOperationRefEight=O0,y.httpRequestOperationRefFive=A0,y.httpRequestOperationRefFour=I0,y.httpRequestOperationRefNine=P0,y.httpRequestOperationRefSeven=D0,y.httpRequestOperationRefSix=b0,y.httpRequestOperationRefThree=T0,y.httpRequestOperationRefTwo=E0,y.httpRequestQueryParamsArgument=Bd,y.httpRequestQueryParamsArgumentRef=e0,y.httpRequestQueryParamsDataType=t0,y.httpRequestVariableURLArgument=io,y.httpRequestVariableURLArgumentRef=Xm,y.httpRequestVariableURLDataType=Qm,y.httpRequestVariableURLDataTypeRef=Hm,y.httpResponseBodyReturnDataType=v0,y.httpResponseBodyReturnDataTypeRef=y0,y.httpResponseBodyReturnReturn=oo,y.httpResponseBodyReturnReturnRef=m0,y.httpResponseCodeDataType=p0,y.httpResponseCodeReturn=so,y.httpResponseCodeReturnRef=u0,y.httpResponseHeadersDataType=h0,y.httpResponseHeadersDataTypeRef=c0,y.httpResponseHeadersReturn=ao,y.httpResponseHeadersReturnRef=f0,y.httpStatusCodeValueValidation=Pw,y.implement=Yl,y.inferArgumentDeclarationDataType=zO,y.inferDataType=$i,y.inferInputMapDataType=Tc,y.inferOutputMapDataType=Ac,y.inferPropertyDataType=KO,y.inferReturnDeclarationDataType=Ic,y.inferValueDescriptorDataType=XO,y.inferVariableDeclarationDataType=HO,y.inferVariableInstanceDataType=YO,y.initBaseProjectEntity=od,y.initProject=Vw,y.initProjectFromFetchResult=Cw,y.inputMapValidation=iW,y.installedProjectValidation=eW,y.internalCallValidation=tW,y.isPromise=Jc,y.iterateOverListActionDescriptorListArgumentDeclaration=lv,y.iterateOverListActionDescriptorListArgumentDeclarationDataType=av,y.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=sv,y.iterateOverListActionDescriptorListArgumentDeclarationParentRef=ov,y.iterateOverListLoopActionDescriptor=wr,y.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=uv,y.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=dv,y.iterateOverListLoopBodyActionDescriptor=Gs,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=Tv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Ev,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Av,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=Iv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=co,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=cv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=pv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=fv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=vv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=yv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=hv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=mv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Pv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=Dv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Rv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=Ov,y.iterateOverObjectKeysLoopActionDescriptor=Yn,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Cv,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=wv,y.iterateOverObjectKeysLoopBodyActionDescriptor=$d,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=$v,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Uv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=gv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Gv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ud,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=_v,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Vv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Bv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Nv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Mv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Lv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=qv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=kv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=xv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Zv,y.iterateOverObjectValuesLoopActionDescriptor=Hn,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Wv,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Jv,y.iterateOverObjectValuesLoopBodyActionDescriptor=gd,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=tE,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=eE,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=rE,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=iE,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Gd,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=zv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Sv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Yv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Qv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Kv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Hv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Xv,y.iterateOverStringActionDescriptorDynamicReturnDeclaration=S0,y.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=W0,y.iterateOverStringActionDescriptorStringArgumentDeclaration=J0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=Z0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=k0,y.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=q0,y.iterateOverStringLoopActionDescriptor=$s,y.iterateOverStringLoopBodyActionDescriptor=po,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=tv,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=ev,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=rv,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=iv,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ld,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Y0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=z0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=H0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jd,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=X0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=K0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Q0,y.joinListOperation=Ad,y.joinListOperationError=Hh,y.joinListOperationErrorParentRef=Yh,y.joinListOperationFirstListArgument=qh,y.joinListOperationFirstListArgumentParentRef=Zh,y.joinListOperationFirstListArgumentRef=$h,y.joinListOperationFirstListDataType=Gh,y.joinListOperationResultListDataType=kh,y.joinListOperationResultListReturn=zh,y.joinListOperationResultListReturnParentRef=Sh,y.joinListOperationResultListReturnRef=xh,y.joinListOperationSecondListArgument=Wh,y.joinListOperationSecondListArgumentParentRef=Jh,y.joinListOperationSecondListArgumentRef=gh,y.joinListOperationSecondListDataType=Fh,y.joinListWithLastSeparator=se,y.joinStringsOperation=Ls,y.joinStringsOperationDynamicStringArgument=mh,y.joinStringsOperationDynamicStringArgumentParentRef=yh,y.joinStringsOperationDynamicStringArgumentRef=fh,y.joinStringsOperationDynamicStringDataType=hh,y.joinStringsOperationError=ch,y.joinStringsOperationErrorParentRef=ph,y.joinStringsOperationFirstStringArgument=Xa,y.joinStringsOperationFirstStringArgumentParentRef=ih,y.joinStringsOperationFirstStringArgumentRef=Hf,y.joinStringsOperationFirstStringDataType=Kf,y.joinStringsOperationResultStringDataType=th,y.joinStringsOperationResultStringReturn=Ns,y.joinStringsOperationResultStringReturnParentRef=uh,y.joinStringsOperationResultStringReturnRef=eh,y.joinStringsOperationSecondStringArgument=Qa,y.joinStringsOperationSecondStringArgumentParentRef=dh,y.joinStringsOperationSecondStringArgumentRef=Xf,y.joinStringsOperationSecondStringDataType=Qf,y.joinStringsOperationSeparatorStringArgument=lh,y.joinStringsOperationSeparatorStringArgumentParentRef=oh,y.joinStringsOperationSeparatorStringArgumentRef=rh,y.joinStringsOperationSeparatorStringDataType=ah,y.joinStringsOperationSeparatorStringDataTypeDefaultValue=sh,y.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=nh,y.keyValuePrototype=Wn,y.literalValudValidation=dW,y.loopValidation=zJ,y.lowercaseFirstLetter=Na,y.manualFlowActionDescriptorDeclarationArgumentDeclaration=Nd,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=j0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=L0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=U0,y.manualFlowLoopActionDescriptor=lo,y.manualFlowLoopActionDescriptorDynamicReturnDeclaration=N0,y.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=M0,y.manualFlowLoopBodyActionDescriptor=uo,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=G0,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=F0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=g0,y.mapActionDescriptorToTypeItRepresents=YW,y.mergeEntityErrorsList=Y3,y.mergeListOfEntities=SW,y.methodDefaultValue=r0,y.mockClientProject=cp,y.moreThanOrEqualCondition=ts,y.moreThanOrEqualConditionLeftHandArgument=QT,y.moreThanOrEqualConditionLeftHandArgumentDataType=KT,y.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=HT,y.moreThanOrEqualConditionLeftHandArgumentParentRef=XT,y.moreThanOrEqualConditionRightHandArgument=rI,y.moreThanOrEqualConditionRightHandArgumentDataType=tI,y.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=eI,y.moreThanOrEqualConditionRightHandArgumentParentRef=iI,y.noSpacesOrDashesValueValidation=pP,y.noSpacesValueValidation=uP,y.notEmptyCondition=En,y.notEmptyConditionArgument=zT,y.notEmptyConditionRef=ST,y.nullPrototype=fd,y.numberAdditionOperation=Ka,y.numberAdditionOperationDynamicSummandArgument=Mf,y.numberAdditionOperationDynamicSummandArgumentType=Bf,y.numberAdditionOperationDynamicSummandArgumentTypeParentRef=_f,y.numberAdditionOperationError=Vf,y.numberAdditionOperationErrorParentRef=Cf,y.numberAdditionOperationFirstNumberArgument=hd,y.numberAdditionOperationFirstNumberArgumentRef=If,y.numberAdditionOperationFirstNumberDataType=Af,y.numberAdditionOperationRef=Pf,y.numberAdditionOperationRefThree=md,y.numberAdditionOperationRefTwo=wf,y.numberAdditionOperationResultNumberDataType=Of,y.numberAdditionOperationResultNumberReturn=vd,y.numberAdditionOperationResultNumberReturnRef=Df,y.numberAdditionOperationSecondNumberArgument=yd,y.numberAdditionOperationSecondNumberArgumentRef=bf,y.numberAdditionOperationSecondNumberDataType=Rf,y.numberPrototype=Ee,y.numberSubtractionOperation=Td,y.numberSubtractionOperationDynamicSubtrahendArgument=zf,y.numberSubtractionOperationDynamicSubtrahendArgumentType=Sf,y.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Wf,y.numberSubtractionOperationError=Jf,y.numberSubtractionOperationErrorParentRef=qf,y.numberSubtractionOperationFirstNumberArgument=gf,y.numberSubtractionOperationFirstNumberArgumentRef=Nf,y.numberSubtractionOperationFirstNumberDataType=Lf,y.numberSubtractionOperationRef=Ed,y.numberSubtractionOperationRefThree=kf,y.numberSubtractionOperationRefTwo=Ff,y.numberSubtractionOperationResultNumberDataType=Gf,y.numberSubtractionOperationResultNumberReturn=Zf,y.numberSubtractionOperationResultNumberReturnRef=$f,y.numberSubtractionOperationSecondNumberArgument=xf,y.numberSubtractionOperationSecondNumberArgumentRef=jf,y.numberSubtractionOperationSecondNumberDataType=Uf,y.numberValueAutogenerationSchema=mp,y.operationValidation=kJ,y.outputMapValidation=sW,y.parallelExecutionOperation=Bi,y.parallelExecutionOperationError=tm,y.parallelExecutionOperationErrorParentRef=em,y.parallelExecutionOperationListOfExecutionResultsDataType=Ky,y.parallelExecutionOperationListOfExecutionResultsReturn=Cd,y.parallelExecutionOperationListOfExecutionResultsReturnRef=Hy,y.parallelExecutionOperationListOfFunctionsArgument=wd,y.parallelExecutionOperationListOfFunctionsArgumentDatatype=Yy,y.parallelExecutionOperationListOfFunctionsArgumentRef=zy,y.parallelExecutionOperationListOfFunctionsBlueprint=Sy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Jy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=qy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Zy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=ky,y.parallelExecutionOperationListOfFunctionsBlueprintParentRef=Wy,y.parallelExecutionOperationRef=Xy,y.parallelExecutionOperationRefThree=Qy,y.persistedBuiltInBaseEntity=Nt,y.persistedBuiltInBaseEntityDatabaseProperty=Xn,y.persistedBuiltInBaseEntityDatabasePropertyDataType=CT,y.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=Fw,y.persistedBuiltInBaseEntityDatabasePropertyParentRef=VT,y.persistedBuiltInBaseEntityDatabasePropertyRef=wT,y.persistedBuiltInBaseEntityPrimaryKeyProperty=Qn,y.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=$T,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=BT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=_T,y.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=GT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=UT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=NT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=MT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=jT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=LT,y.processOutputGlobalValueDescriptorDataType=uI,y.processOutputGlobalValueDescriptorReturn=Ao,y.processOutputGlobalValueDescriptorReturnRef=dI,y.projectPublicationCompletedGlobalEvent=Io,y.propertyToZodSchema=VI,y.propertyValidation=MJ,y.relationalDatabaseBuiltInBaseEntity=Ot,y.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Qd,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=RT,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=bT,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=DT,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=AT,y.relationalDatabaseBuiltInBaseEntityDefaultProperty=Xd,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=IT,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=ET,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=TT,y.relationalDatabaseBuiltInBaseEntityIdentifierProperty=ho,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=dT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=oT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=lT,y.relationalDatabaseBuiltInBaseEntityMinSizeProperty=vo,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=vT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=yT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=mT,y.relationalDatabaseBuiltInBaseEntityPasswordProperty=mo,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=fT,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=gw,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDefaultValueParentRef=hT,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=cT,y.relationalDatabaseBuiltInBaseEntityRef=Kn,y.relationalDatabaseBuiltInBaseEntityUsernameProperty=yo,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=pT,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=Gw,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=uT,y.resolveActionDescriptorName=n1,y.resolveBaseEntityName=e1,y.resolveBuiltInBaseEntityDataTypeLabel=t1,y.resolveClonedEntityProject=mt,y.resolveConditionOperatorLabel=gl,y.resolveDataType=Ul,y.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Sc,y.resolveDataTypeLabel=Gl,y.resolveDefinitionEntityDataTypeLabel=_J,y.resolveEntityDataTypeLabel=VJ,y.resolveEntityName=F,y.resolveFirstCallsSecond=jW,y.resolveFirstWritesSecond=UW,y.resolvePrimaryKeyProperty=QW,y.resolvePrimitiveEntityName=r1,y.resolveSearchName=i1,y.resolveVariableScope=PJ,y.returnDeclarationValidation=ZJ,y.returnStatementValidation=qJ,y.searchStatementErrorGlobalValueDescriptor=su,y.searchStatementErrorGlobalValueDescriptorDataType=cI,y.searchStatementErrorGlobalValueDescriptorRef=pI,y.searchValidation=QJ,y.sequentialExecutionOperation=ur,y.sequentialExecutionOperationError=Am,y.sequentialExecutionOperationErrorParentRef=Im,y.sequentialExecutionOperationListOfExecutionResultsDataType=vm,y.sequentialExecutionOperationListOfExecutionResultsReturn=_d,y.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=Tm,y.sequentialExecutionOperationListOfExecutionResultsReturnRef=mm,y.sequentialExecutionOperationListOfFunctionsArgument=Vd,y.sequentialExecutionOperationListOfFunctionsArgumentDatatype=ym,y.sequentialExecutionOperationListOfFunctionsArgumentParentRef=Em,y.sequentialExecutionOperationListOfFunctionsArgumentRef=hm,y.sequentialExecutionOperationListOfFunctionsBlueprint=fm,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=cm,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=pm,y.softDeletePersistedEntityMethod=xw,y.softDeletePersistedEntityMethodParentRef=gT,y.sortCallsBasedOnExecutionDependencies=mP,y.sortChildrenEntitiesBasedOnExecutionDependencies=NW,y.splitListOperation=Rd,y.splitListOperationError=hy,y.splitListOperationErrorParentRef=fy,y.splitListOperationFirstOutputListDataType=ry,y.splitListOperationFirstOutputListReturn=dy,y.splitListOperationFirstOutputListReturnParentRef=ly,y.splitListOperationFirstOutputListReturnRef=bd,y.splitListOperationInputListArgument=sy,y.splitListOperationInputListArgumentParentRef=ny,y.splitListOperationInputListArgumentRef=Qh,y.splitListOperationInputListDataType=ey,y.splitListOperationSecondOutputListDataType=uy,y.splitListOperationSecondOutputListReturn=cy,y.splitListOperationSecondOutputListReturnParentRef=py,y.splitListOperationSplitIndexArgument=oy,y.splitListOperationSplitIndexArgumentParentRef=ay,y.splitListOperationSplitIndexArgumentRef=ty,y.splitListOperationSplitIndexDataType=iy,y.splitStringOperation=Id,y.splitStringOperationError=Nh,y.splitStringOperationErrorParentRef=Mh,y.splitStringOperationFirstPartResultStringDataType=bh,y.splitStringOperationFirstPartResultStringReturn=Bh,y.splitStringOperationFirstPartResultStringReturnParentRef=_h,y.splitStringOperationFirstPartResultStringReturnRef=Ah,y.splitStringOperationIndexArgument=Ch,y.splitStringOperationIndexArgumentParentRef=wh,y.splitStringOperationIndexArgumentRef=Th,y.splitStringOperationIndexDataType=Ih,y.splitStringOperationSecondPartResultStringDataType=Dh,y.splitStringOperationSecondPartResultStringReturn=Uw,y.splitStringOperationSecondPartResultStringReturnParentRef=Vh,y.splitStringOperationSecondPartResultStringReturnRef=Rh,y.splitStringOperationStringArgument=Ph,y.splitStringOperationStringArgumentParentRef=Oh,y.splitStringOperationStringArgumentRef=vh,y.splitStringOperationStringDataType=Eh,y.stringPrototype=ae,y.stringValueAutogenerationSchema=yp,y.suggestNewIdForEntity=Vc,y.test_primitive_entities_export=ZS,y.toCamelCase=wJ,y.toEntityState=bi,y.toKebabCase=QO,y.toLowerCaseKebabCase=$l,y.toPascalCase=CJ,y.untypedDataPrototype=Ct,y.updateErrorsList=Ke,y.urlDefaultValue=Km,y.uuidPrototype=lr,y.validateArgumentDeclarationName=wc,y.validateCalledByErrorIdInAction=IW,y.validateCalledByIdInAction=TW,y.validateCallers=Q1,y.validateConditionEntityDeclaration=RW,y.validateDataOperation=fn,y.validateDataOperationDataToValidateArgument=Fm,y.validateDataOperationDataToValidateArgumentParentRef=gm,y.validateDataOperationDataToValidateArgumentRef=$m,y.validateDataOperationDataToValidateDataType=Gm,y.validateDataOperationEntityToMatchTypeArgument=qm,y.validateDataOperationEntityToMatchTypeArgumentParentRef=Zm,y.validateDataOperationEntityToMatchTypeArgumentRef=xm,y.validateDataOperationEntityToMatchTypeDataType=km,y.validateDataOperationError=zm,y.validateDataOperationErrorParentRef=Sm,y.validateDataOperationOutputEntityDeclaration=Wm,y.validateDataOperationOutputEntityDeclarationParentRef=Jm,y.validateDefinitionEntityName=Rc,y.validateEntryCaller=X1,y.validateErrorCaller=K1,y.validateFunctionCallDeclaration=tP,y.validateFunctionDeclarationName=Dc,y.validateGeneratedEntityParentIsNotBuiltInEntity=yW,y.validateGeneration=fW,y.validateGenerationTarget=ut,y.validateGenerationUpdate=hW,y.validateLoopEntityDeclaration=DW,y.validateName=BJ,y.validateOperationEntityDeclaration=iP,y.validatePropertyName=Pc,y.validateReachability=Rr,y.validateReadsValueInActionPayload=AW,y.validateReferenceObject=xl,y.validateReferenceToOne=$c,y.validateReferences=bt,y.validateReturnDeclarationName=Cc,y.validateSuccessCaller=H1,y.validateValueReaderGenerationUpdate=ja,y.validateValueWritter=Zc,y.validateVariableDeclarationName=Oc,y.validateVariableInternalCallUse=qc,y.valueAutogenerationCurrentDateAndTimeSchema=pD,y.valueAutogenerationGenericSchema=dl,y.valueAutogenerationOptions=Ep,y.valueAutogenerationOptionsSchema=uD,y.valueAutogenerationRandomBooleanSchema=hp,y.valueAutogenerationRandomDateBetweenSchema=ID,y.valueAutogenerationRandomDateFromSchema=ED,y.valueAutogenerationRandomDateSchema=cl,y.valueAutogenerationRandomDateUntilSchema=TD,y.valueAutogenerationRandomNumberBetweenSchema=hD,y.valueAutogenerationRandomNumberFromSchema=cD,y.valueAutogenerationRandomNumberSchema=ul,y.valueAutogenerationRandomNumberUntilSchema=fD,y.valueAutogenerationRandomSchema=ma,y.valueAutogenerationRandomTextBetweenSchema=vD,y.valueAutogenerationRandomTextFromSchema=yD,y.valueAutogenerationRandomTextSchema=pl,y.valueAutogenerationRandomTextUntilSchema=mD,y.valueAutogenerationRangeValueTypesSchema=ya,y.valueAutogenerationUniqueSchema=fp,y.valueDescriptorValidation=cW,y.variableDeclarationValidation=KJ,y.variableInstanceValidation=XJ,y.waitOperation=Ht,y.waitOperationMillisecondsNumberArgument=pn,y.waitOperationMillisecondsNumberArgumentRef=nm,y.waitOperationMillisecondsNumberDataType=sm,y.waitOperationOperationError=lm,y.waitOperationOperationErrorParentRef=om,y.waitOperationRef=am,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:s,modifiedData:i}}get interactive(){return this.implements.length?this.implements.every(e=>e.interactive):!0}get allBasePropertiesFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>t.type!==n.DefinitionEntity?[]:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[]),...this.implements.reduce((e,t)=>t.type!==n.DefinitionEntity?t.abstractMethods:[...[...t.ownDeclaredMethods,...t.allBaseMethodsFromExtendedAndImplementedEntities].filter(s=>s.type!==n.ActionDescriptor),...e],[])])}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])].filter(e=>!!e.abstract))}get extendedMethodsFromOriginalParents(){return p(this.extends.reduce((e,t)=>{if(t.type!==n.DefinitionEntity)return[];const i=[...t.ownDeclaredMethods,...t.extendedMethodsFromOriginalParents].filter(s=>s.type!==n.ActionDescriptor);return[...e,...i]},[]))}get implementedMethodsFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.type===n.DefinitionEntity?t.methods:[],s=[...t.abstractMethods].filter(l=>!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>[...t.abstractMethods,...e],[])].filter(e=>e.type===n.ActionDescriptor))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}get extendedMethods(){return this.methods.filter(e=>e.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(e=>!e.isExtendedMethod)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:O.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}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(e=>{si.includes(e.type)||e.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(e=>{si.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{si.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new $e(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new $e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=B(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.extends.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addExtension(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),this.initialData.implements.forEach(l=>{const o=B(l),d=this.project.get(o);d&&(this.addImplementation(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0;const{updated:o,added:d,removed:u,affected:f}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...f);const{updated:c,added:T,removed:I,affected:D}=this.addExtendedProperties(e);t.push(...c),i.push(...T),s.push(...I),l.push(...D);const{updated:P,added:C,removed:M}=this.removeUnrecognizedProperties(e);t.push(...P),i.push(...C),s.push(...M);const{updated:G,added:_,removed:g,affected:q}=this.syncImplementationMethods(e);t.push(...G),i.push(..._),s.push(...g),l.push(...q);const{updated:S,added:K,removed:de,affected:me}=this.addExtendedMethods(e);t.push(...S),i.push(...K),s.push(...de),l.push(...me);const{updated:z,added:oe,removed:Ft}=this.removeUnrecognizedMethods(e);return t.push(...z),i.push(...oe),s.push(...Ft),this.addSuggestions(),this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.methods=this.initialData.methods.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.extends=this.initialData.extends.map(t=>V(t,this.project)),this.implements=this.initialData.implements.map(t=>V(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-properties"))){const t=[],i=[],s=[],l=[];let o=[...this.properties];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedProperty);const d=this.implementedPropertiesFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-unrecognized-methods"))){const t=[],i=[],s=[],l=[];let o=[...this.methods];o=o.filter(u=>u.parent.id===this.id),o=o.filter(u=>!u.isExtendedMethod);const d=this.implementedMethodsFromOriginalParents;return o=o.filter(u=>this.interactive&&!u.implements?!1:!d.find(f=>{var c;return f.id===((c=u.implements)==null?void 0:c.id)})),o.forEach(u=>{const f=u.remove({ignoreUpstream:!1},e);s.push(...f.removed),t.push(...f.updated)}),e==null||e.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-implementation-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,d=this.implementedMethodsFromOriginalParents,u=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})).forEach(c=>{if(this.methods.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===c.id}))return;const I=this.methods.find(P=>{var g,q;if(P.name===c.name&&!P.implements)return!0;const C=gi(this,J.CRON_JOB),M=gi(this,J.HTTP_ENDPOINT),G=((g=P.implements)==null?void 0:g.id)===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,_=((q=P.implements)==null?void 0:q.id)===k["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(C&&!_&&!M&&G||M&&!G&&!C&&_)});if(I&&I.type===n.FunctionDeclaration){I.setImplements(c),I.metaSync({name:c.name},e),e==null||e.add(I,A.Updated),e==null||e.add(this,A.Updated);return}const D=c.implementAsFunctionDeclaration(e,this);i.push(D),e==null||e.add(D,A.Added),this.addMethod(D)}),e==null||e.attemptAutoclose("sync-implementation-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncImplementationProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.implementedPropertiesFromOriginalParents,u=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})).forEach(c=>{if(this.properties.find(P=>{var C;return((C=P.implements)==null?void 0:C.id)===c.id}))return;const I=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(I){I.implements=c,I.abstract=!1;return}const D=c.clone(e,this,m.UUID.uuid());D.initChildren(e),i.push(D),e==null||e.add(D,A.Added),D.setImplements(c,e),D.metaSync({abstract:!1},e),this.addProperty(D)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedMethods(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-extended-methods"))){const t=[],i=[],s=[],l=[],o=this.methods,u=this.extendedMethodsFromOriginalParents.filter(c=>c.type===n.FunctionDeclaration),f=new Set(o.filter(c=>{var T;return!!((T=c.extends)!=null&&T.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const T=c.clone(e,this,m.UUID.uuid());T.setExtends(c,e),T.initChildren(e),i.push(T),e==null||e.add(T,A.Added),this.addMethod(T)}),e==null||e.attemptAutoclose("add-extended-methods",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.extendedPropertiesFromOriginalParents,u=d.filter(c=>d.find(I=>{var D;return((D=I.implements)==null?void 0:D.id)===c.id})?!1:!c.abstract),f=new Set(o.filter(c=>{var T;return!!((T=c.extends)!=null&&T.id)}).map(c=>c.extends.id));return u.forEach(c=>{if(f.has(c.id))return;f.add(c.id);const T=c.clone(e,this,m.UUID.uuid());T.setExtends(c,e),T.initChildren(e),i.push(T),e==null||e.add(T,A.Added),this.addProperty(T)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{yw(this,e).forEach(s=>{const l=s.toJSON();l.id=`_suggestion--parent--${this.id}--${s.id}`;const o=V(l,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),mw(this,e).forEach(s=>{const l=`_suggestion--parent--${this.id}--${s.id}`,o=s.implementAsFunctionDeclaration(null,this,l),d=V(o,this.project);if(d.suggestion=!0,d.setParent(this,null),d.initChildren(null),this.methods=this.methods.filter(u=>u.id!==l),d.inputs.forEach(u=>{u.suggestion=!0}),d.returnStatements.length){const u=d.returnStatements[0];u.suggestion=!0,u.outputs.forEach(f=>{f.suggestion=!0})}this.addSuggestedMethod(d)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.static=e.static!==void 0?e.static:this.static,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await $e.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await $e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await $e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await $e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await $e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await $e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:f,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...f),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.methods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:f}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...f)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const d=this.parent.setEntity(null);i.push(d)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),Object.values(this.detachedDependents).forEach(o=>{const{updated:d,removed:u,added:f}=o.entity.onDetachedDependencyRestored(this,o.field,e);i.push(...d),s.push(...u),t.push(...f)}),this.properties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.methods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.abstractMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedProperties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(i=>i.toFlat(e)),...this.implements.flatMap(i=>i.toFlat(e)),...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(i=>i.toFlatIds(e)),...this.implements.flatMap(i=>i.toFlatIds(e)),...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=W){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||yt(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(u=>u.toJSONClone({...e,newId:null})),methods:this.methods.map(u=>u.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(u=>u.toJSONClone({...e,newId:null})),implements:this.implements.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),extends:this.extends.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toReference(e)),methods:this.methods.map(s=>s.toReference(e)),abstractMethods:this.abstractMethods.map(s=>s.toReference(e)),implements:this.implements.map(s=>s.toReference(e)),extends:this.extends.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e)),...this.implements.flatMap(i=>i.toFlatJSON(e)),...this.extends.flatMap(i=>i.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=hw(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 b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,C,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const u=d.split("-id"),f=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||E().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=st(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const T=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=T;const I=(C=this.methods)==null?void 0:C.map((G,_)=>G.clone(e,c,f+"-method-"+_+"-id",s));c.methods=I;const D=(M=this.abstractMethods)==null?void 0:M.map((G,_)=>G.clone(e,c,f+"-abstract-method-"+_+"-id",s));return c.abstractMethods=D,e==null||e.attemptAutoclose("clone-entity",this.id),c}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"implement-definition-entity")),i){const s=Yl(this,e,t,i);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),s}getAllInteractiveMethods(){const e=this.implements.filter(i=>i.type===n.DefinitionEntity||i.type===n.BuiltInBaseEntity&&i.interactive);return p([...this.methods,...this.extends.flatMap(i=>i.getAllInteractiveMethods()),...e.flatMap(i=>i.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const i=[],s=[],l=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const d=[];e.forEach(c=>{d.find(I=>F(I,this.project)===F(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const T=u.find(_=>F(_,this.project)===F(c,this.project));if(!T)return;const D=Gn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=$i(D,t),C=P==null?void 0:P.clone(t,T,m.UUID.uuid(),!0);if(C){const _=(M=T.dataType)==null?void 0:M.merge(C,t);T.dataType&&(_==null?void 0:_.self.id)!==T.dataType.id&&T.dataType.remove({ignoreUpstream:!1},t),C.id!==((G=_==null?void 0:_.self)==null?void 0:G.id)&&C.remove({ignoreUpstream:!1},t),_!=null&&_.self&&(_.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(_.self,A.Added),T.setDataType(_.self),t==null||t.add(T,A.Updated))}c.setDeclaration(T),t==null||t.add(c,A.Updated)});const f=[];return d.forEach(c=>{if(!c.declaration){f.push(c);return}}),f.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(f.forEach(c=>{var _,g,q,S;const T=this.properties.find(K=>F(K,this.project)===F(c,this.project));if(T){if(c.setDeclaration(T),!T.getDataType(t)){const de=Gn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),me=$i(de),z=me==null?void 0:me.clone(t,T,m.UUID.uuid(),!0);if(z){const oe=(_=T.dataType)==null?void 0:_.merge(z,t);T.dataType&&(oe==null?void 0:oe.self.id)!==T.dataType.id&&T.dataType.remove({ignoreUpstream:!1},t),z.id!==((g=oe==null?void 0:oe.self)==null?void 0:g.id)&&z.remove({ignoreUpstream:!1},t),oe!=null&&oe.self&&(oe.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(oe.self,A.Added),T.setDataType(oe.self),t==null||t.add(T,A.Updated))}}return}const I={id:m.UUID.uuid(),type:n.Property,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:F(c,this.project),description:c.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:c.index,implements:null,extends:null,dataType:null,parent:this.toReference()},D=V(I,this.project);D.setParent(this,t),D.initChildren(t),t==null||t.add(D,A.Added);const C=Gn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=$i(C),G=M==null?void 0:M.clone(t,D,m.UUID.uuid(),!0);if(G){const K=(q=D.dataType)==null?void 0:q.merge(G,t);D.dataType&&(K==null?void 0:K.self.id)!==D.dataType.id&&D.dataType.remove({ignoreUpstream:!1},t),G.id!==((S=K==null?void 0:K.self)==null?void 0:S.id)&&G.remove({ignoreUpstream:!1},t),K!=null&&K.self&&(K.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(K.self,A.Added),D.setDataType(K.self),t==null||t.add(D,A.Updated))}return this.addProperty(D),c.setDeclaration(D),t==null||t.add(c,A.Updated),D}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:p(i),updated:p(s),removed:p(l),affected:p(o),self:this})}};h($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,...i)=>null}),h($e,"type",n.DefinitionEntity),h($e,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),h($e,"PARENT_TYPES",[...$e.USER_MANAGED_PARENT_TYPES]),h($e,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),h($e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h($e,"BASE_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"MUTABLE_META_PROPERTIES",[...$e.MUTABLE_BASE_PROPERTIES,"x","y"]),h($e,"INMUTABLE_META_PROPERTIES",[...$e.INMUTABLE_BASE_PROPERTIES]),h($e,"META_PROPERTIES",[...$e.MUTABLE_META_PROPERTIES,...$e.INMUTABLE_META_PROPERTIES]),h($e,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),h($e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),h($e,"UPSTREAM_PROPERTIES",[...$e.MUTABLE_UPSTREAM_PROPERTIES,...$e.INMUTABLE_UPSTREAM_PROPERTIES]),h($e,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),h($e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h($e,"DOWNSTREAM_PROPERTIES",[...$e.MUTABLE_DOWNSTREAM_PROPERTIES,...$e.INMUTABLE_DOWNSTREAM_PROPERTIES]),h($e,"PROPERTIES",[...$e.META_PROPERTIES,...$e.UPSTREAM_PROPERTIES,...$e.DOWNSTREAM_PROPERTIES]);let dn=$e;function ES(r){const a=c5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const Wa=class Wa extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"version");h(this,"name");h(this,"description",null);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",!1);h(this,"static");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"interactive",!1);h(this,"errors",[]);h(this,"project");this.initialData=this.initialData||e,this.project=this.project||t,this.id=this.id||e.id,this.version=this.version||e.version,this.name=this.name||e.name,this.static=this.static||e.static,this.interactive=this.interactive||e.interactive,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.extends=this.initialData.extends.map(i=>V(i,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=U,...t){return await Wa.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.extends.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.extends.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=W){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=W){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=ES(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 b(this.project,m.sessionAuthor,E().toISOString(),null,!0,"implement-built-in-base-entity")),i){const s=Yl(this,e,t,i);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),s}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Wa&&e.push(...i.getAllInteractiveMethods())})),p(e)}};h(Wa,"repository",{APILoad:async(e,...t)=>null});let Fi=Wa;function TS(r){const a=r5(),e=r.toJSON();a.safeParse(e).success;const i=[];return Ke(r.errors,i)}const dd=class dd extends lt{constructor(e,t){super(e);h(this,"initialData");h(this,"id");h(this,"name");h(this,"description",null);h(this,"type",n.PrimitiveEntity);h(this,"static");h(this,"abstract");h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.static=e.static,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.parent=this,s})}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=U,...t){return await dd.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=W){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=W){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=TS(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Fi&&e.push(...i.getAllInteractiveMethods())}),p(e)}};h(dd,"repository",{APILoad:async(e,...t)=>null});let ni=dd;function st(r,a){if(!r)throw new Error("Entity is null");const e=a.get(r.id);switch(r.type){case n.LiteralValue:return e||new en(r,a);case n.DefinitionEntity:return e||new dn(r,a);case n.PrimitiveEntity:return e||new ni(r,a);case n.FunctionDeclaration:return e||new kr(r,a);case n.GlobalEvent:return e||new Wr(r,a);case n.DataType:return e||new Zr(r,a);case n.Property:return e||new xr(r,a);case n.FunctionCall:return e||new an(r,a);case n.Condition:return e||new zr(r,a);case n.Operation:return e||new qr(r,a);case n.VariableDeclaration:return e||new Hr(r,a);case n.VariableInstance:return e||new Yr(r,a);case n.OutputMap:return e||new tr(r,a);case n.ReturnDeclaration:return e||new ri(r,a);case n.ArgumentDeclaration:return e||new br(r,a);case n.InputMap:return e||new er(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Xr(r,a);case n.ActionDescriptor:return e||new We(r,a);case n.ReturnStatement:return e||new Jr(r,a);case n.Loop:return e||new Sr(r,a);case n.Search:return e||new Kr(r,a);case n.ValueDescriptor:return e||new ir(r,a);case n.BuiltInBaseEntity:return e||new Fi(r,a);case n.InternalCall:return e||new Qr(r,a);case n.ContinueStatement:return e||new Gt(r,a);case n.BreakStatement:return e||new tn(r,a);case n.GenericReference:return a.get(r.entityId);default:throw new Error("Invalid entity type: "+r.type)}}function V(r,a){if(!r)throw new Error("Entity is null");const e=st(r,a);return e.subscribe(),e}function IS(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return en.fromGenerationTarget(r,a);case n.DefinitionEntity:return dn.fromGenerationTarget(r,a);case n.FunctionDeclaration:return kr.fromGenerationTarget(r,a);case n.GlobalEvent:return Wr.fromGenerationTarget(r,a);case n.DataType:return Zr.fromGenerationTarget(r,a);case n.Property:return xr.fromGenerationTarget(r,a);case n.FunctionCall:return an.fromGenerationTarget(r,a);case n.Condition:return zr.fromGenerationTarget(r,a);case n.Operation:return qr.fromGenerationTarget(r,a);case n.VariableDeclaration:return Hr.fromGenerationTarget(r,a);case n.VariableInstance:return Yr.fromGenerationTarget(r,a);case n.OutputMap:return tr.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ri.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return br.fromGenerationTarget(r,a);case n.InputMap:return er.fromGenerationTarget(r,a);case n.InstalledProject:return Xr.fromGenerationTarget(r,a);case n.ReturnStatement:return Jr.fromGenerationTarget(r,a);case n.Loop:return Sr.fromGenerationTarget(r,a);case n.Search:return Kr.fromGenerationTarget(r,a);case n.ActionDescriptor:return We.fromGenerationTarget(r,a);case n.ValueDescriptor:return ir.fromGenerationTarget(r,a);case n.InternalCall:return Qr.fromGenerationTarget(r,a);case n.ContinueStatement:return Gt.fromGenerationTarget(r,a);case n.BreakStatement:return tn.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const W={seenEntityMaps:new Map,seenEntities:new Set,timestamp:E().toISOString()};class vw{constructor(){h(this,"initialData")}}const U={cascade:!1},Ew={APILoad:async(r,...a)=>null},AS={APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoadVersion:async(r,a,...e)=>null,...Ew};class bS{}class RS extends vw{}class DS{}class OS{}class PS{}class af{}class wS extends af{}class CS extends af{}class VS{}class Or{static initReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=V(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=bi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),a.readsValue.initChildren(null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}static hydrateReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=V(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=bi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(it.includes(a.readsValue.type)){let e=a.parent;ht.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}}class qa{static initWritesValues(a,e){const t=a.initialData.writesValues.reduce((s,l)=>{if(l.type===n.GenericReference||a.writesValues.some(d=>d.id===l.id))return s;const o=V(l,a.project);return o.setValueWriter(a,null),it.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class _S{}class BS{constructor(a){h(this,"eventName");h(this,"callbacks",[]);this.eventName=a}on(a){if(typeof a!="function")throw new Error("Event callback must be a function");this.callbacks.includes(a)||this.callbacks.push(a)}off(a){if(typeof a!="function")throw new Error("Event callback must be a function");this.callbacks=this.callbacks.filter(e=>e!==a)}destroy(){this.callbacks=[]}}class of{constructor(){h(this,"subscribedEvents",{});h(this,"on",this._on);h(this,"emit",this._emit);h(this,"off",this._off);h(this,"destroy",this._destroy)}getEvent(a){return this.subscribedEvents[a]||(this.subscribedEvents[a]=new BS(a)),this.subscribedEvents[a]}_on(a,e){this.getEvent(a).on(e)}_emit(a,...e){const t=this.getEvent(a);t&&t.callbacks.forEach(i=>{i.apply(null,e)})}_off(a,e){const t=this.getEvent(a);t&&(e?t.off(e):(t.destroy(),delete this.subscribedEvents[a]))}_destroy(){Object.keys(this.subscribedEvents).forEach(a=>{this._off(a)}),this.subscribedEvents={}}}var Bt=(r=>(r.DEFINITION_ENTITY_ADDED="definition-entity-added",r.DEFINITION_ENTITY_REMOVED="definition-entity-removed",r.DEFINITION_ENTITY_UPDATED="definition-entity-updated",r.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",r.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",r.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",r.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",r.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",r.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",r))(Bt||{});function MS(r,a){a.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(t=>{t!=="constructor"&&Object.defineProperty(r.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t))})})}class Tw extends lt{constructor(...a){super(...a),Object.assign(this,new of)}}MS(Tw,[of]);const re=class re extends Tw{constructor(e){super(e);h(this,"initialData");h(this,"id");h(this,"type",n.Project);h(this,"name",null);h(this,"description",null);h(this,"x");h(this,"y");h(this,"entities",[]);h(this,"projects",[]);h(this,"functions",[]);h(this,"events",[]);h(this,"variableDeclarations",[]);h(this,"variableInstances",[]);h(this,"conditions",[]);h(this,"operations",[]);h(this,"functionCalls",[]);h(this,"loops",[]);h(this,"searches",[]);h(this,"primitives",[]);h(this,"builtInBaseEntities",[]);h(this,"operationDeclarations",[]);h(this,"globalEventActionDescriptors",[]);h(this,"loopDeclarations",[]);h(this,"loopDeclarationsBodies",[]);h(this,"conditionDeclarations",[]);h(this,"valueDescriptors",[]);h(this,"dataTypes",[]);h(this,"project");h(this,"instances",{});h(this,"builtInInstances",{});h(this,"deletedInstances",{});h(this,"errors",[]);h(this,"references",[]);h(this,"history",[]);h(this,"detachedDependents",{});h(this,"knownVersions",null);h(this,"activeVersion",!1);h(this,"initialized",!1);h(this,"startedInitialization",!1);h(this,"onCloseChangeSetCallback",null);h(this,"onRequestActiveValueCallback",null);this.initialData=e,this.id=e.id,this.name=e.name,this.description=e.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!re.UUID||re.UUID.isBackup)&&(re.UUID=Wo==null?void 0:Wo()),re.UUID||(re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:t=>t})}catch(t){console.error("Error initializing UUID module",t),re.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){re.UUID=e}static new(e=null){return{id:re.UUID.uuid(),version:re.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||E().toISOString(),author:(e==null?void 0:e.author)||re.sessionAuthor,previousVersion:null,deleted:!1,type:n.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingChangeSets(){const e=this.history.find(t=>t.dirty&&!t.open);e&&await this.closeChangeSet(e)}onRequestActiveValue(e){this.onRequestActiveValueCallback=e}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingChangeSets()}async closeChangeSet(e){const t=this.history.findIndex(l=>l.id===e.id),i=this.history.slice(0,t),s=i[i.length-1];if(!(s!=null&&s.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(e)).success&&(e.dirty=!1,this.closePendingChangeSets());return}}toLatestChangeSet(e,t,i,s=!1,l="here-this"){if(!this.history.length)return new b(this,e,t,i,s,l);const o=this.history[this.history.length-1];return o.open?o:this.addChangeSet(new b(this,e,t,i,s,l))}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(l=>l.id===(e==null?void 0:e.id));if(t)return t;const i=this.history.find(l=>l.open);if(i)throw console.warn("Previous still open: ",i),console.warn("New change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>E(e==null?void 0:e.timestamp).isBefore(E(l==null?void 0:l.timestamp)));return s===-1?this.history.push(e):this.history.splice(s,0,e),e}discardChangeSet(e){const t=this.history.findIndex(i=>i.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}redo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async i=>{await t.init(this),i(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}unsubscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]&&delete this.detachedDependents[t.entity.id]}),this}syncDependents(e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"sync-dependents"))){const t=[],i=[],s=[],l=[];return Object.values(this.detachedDependents).forEach(o=>{const d=o.entity.afterAllChildrenInitialized(e);t.push(...d.updated),i.push(...d.added),s.push(...d.removed),l.push(...d.affected)}),e==null||e.attemptAutoclose("sync-dependents",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!E(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&E(e).isSame(E(this.createdAt))?this:(this.previousVersion=this.version,this.version=re.UUID.uuid(),this.createdAt=E(e).toISOString()||E().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new re(this);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[f,c]of this.knownVersions||new Map){if(u.set(f,c),c.activeVersion=!1,c.knownVersions)for(const[T,I]of c.knownVersions)u.set(T,I);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new re(u)}return this.metaSync(o.toShallowJSON(),null),this.previousVersion=o.previousVersion,this.version=o.version,this.createdAt=o.createdAt,this.author=o.author,this.deleted=o.deleted,this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=null){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.validate(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e){const t=[],i=[],s=[],l=[];return this.subscribe(),this.subscribeToDependencies(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.projects=this.initialData.projects.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableInstances=this.initialData.variableInstances.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.conditions=this.initialData.conditions.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.operations=this.initialData.operations.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functions=this.initialData.functions.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functionCalls=this.initialData.functionCalls.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.loops=this.initialData.loops.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.searches=this.initialData.searches.map(t=>{const i=V(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.getBuiltIn(e)?null:this.instances[e]||null}getBuiltIn(e){return this.builtInInstances[e]||null}findSubscribedInstanceFromReference(e){return this.instances[e.entityId]||null}findSubscribedBuiltInInstanceFromReference(e){return this.builtInInstances[e.entityId]||null}metaSync(e,t=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name!==void 0?e.name:s.name,this.description=e.description!==void 0?e.description:s.description,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=U,...t){return await re.repository.APILoad(this.id,...t),this}async APICreate(e=U,...t){return await re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=U,...t){return await re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=U,...t){return await re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=U,...t){return await re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=U,t,...i){return await re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,re.sessionAuthor,E().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(i=>i.toFlat(e)),...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e)),...this.projects.flatMap(i=>i.toFlat(e)),...this.variableDeclarations.flatMap(i=>i.toFlat(e)),...this.variableInstances.flatMap(i=>i.toFlat(e)),...this.conditions.flatMap(i=>i.toFlat(e)),...this.operations.flatMap(i=>i.toFlat(e)),...this.functionCalls.flatMap(i=>i.toFlat(e)),...this.loops.flatMap(i=>i.toFlat(e)),...this.searches.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(i=>i.toFlatIds(e)),...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e)),...this.projects.flatMap(i=>i.toFlatIds(e)),...this.variableDeclarations.flatMap(i=>i.toFlatIds(e)),...this.variableInstances.flatMap(i=>i.toFlatIds(e)),...this.conditions.flatMap(i=>i.toFlatIds(e)),...this.operations.flatMap(i=>i.toFlatIds(e)),...this.functionCalls.flatMap(i=>i.toFlatIds(e)),...this.loops.flatMap(i=>i.toFlatIds(e)),...this.searches.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,i=new Set,s=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(l=>{if(s.includes(l)){t.set(l,l);return}t.set(l,re.UUID.uuid())}),i.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),projects:this.projects.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableDeclarations:this.variableDeclarations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableInstances:this.variableInstances.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),conditions:this.conditions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),operations:this.operations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functions:this.functions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),events:this.events.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functionCalls:this.functionCalls.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),loops:this.loops.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),searches:this.searches.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null}))}}toReference(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+re.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=W){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(s=>s.toReference(e)),functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),projects:this.projects.map(s=>s.toReference(e)),variableDeclarations:this.variableDeclarations.map(s=>s.toReference(e)),variableInstances:this.variableInstances.map(s=>s.toReference(e)),conditions:this.conditions.map(s=>s.toReference(e)),operations:this.operations.map(s=>s.toReference(e)),functionCalls:this.functionCalls.map(s=>s.toReference(e)),loops:this.loops.map(s=>s.toReference(e)),searches:this.searches.map(s=>s.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(i=>i.toFlatJSON(e)),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e)),...this.projects.flatMap(i=>i.toFlatJSON(e)),...this.variableDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.variableInstances.flatMap(i=>i.toFlatJSON(e)),...this.conditions.flatMap(i=>i.toFlatJSON(e)),...this.operations.flatMap(i=>i.toFlatJSON(e)),...this.functionCalls.flatMap(i=>i.toFlatJSON(e)),...this.loops.flatMap(i=>i.toFlatJSON(e)),...this.searches.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e)),...this.projects.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(i=>i.toFlatGenerationTarget(e)),...this.conditions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.operations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.loops.flatMap(i=>i.toFlatGenerationTarget(e)),...this.searches.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=Cq(),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}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(i=>i.id===e.id);if(t>-1){const i=this.entities[t];return this.entities.splice(t,1),i}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(i=>i.id===e.id);if(t>-1){const i=this.functions[t];return this.functions.splice(t,1),i}return null}removeExternalProject(e){const t=this.projects.findIndex(i=>i.id===e.id);if(t>-1){const i=this.projects[t];return this.projects.splice(t,1),i}return null}removeGlobalEvent(e){const t=this.events.findIndex(i=>i.id===e.id);if(t>-1){const i=this.events[t];return this.events.splice(t,1),i}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(i=>i.id===e.id);if(t>-1){const i=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),i}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.ReturnStatement||l.type===n.ContinueStatement||l.type===n.BreakStatement)]},[])]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=He(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=He(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=He(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=Te(i);return[...t,...s.filter(l=>l.type===n.Search)]},[])]}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(i=>{if(!i.declaration){const s=i.initialData,l=s.declaration.entityId||s.declaration.id,o=t.find(d=>d.id===l);o&&i.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===J.PERSISTED_ENTITY)||null}requestActiveValue(e){var i;const t=(i=this.onRequestActiveValueCallback)==null?void 0:i.call(this,e);return t?t||null:e.getDefaultValue()}};h(re,"sessionAuthor","1"),h(re,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),h(re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),h(re,"type",n.Project),h(re,"USER_MANAGED_PARENT_TYPES",[]),h(re,"PARENT_TYPES",[...re.USER_MANAGED_PARENT_TYPES]),h(re,"MUTABLE_BASE_PROPERTIES",["name","description"]),h(re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),h(re,"BASE_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,...re.INMUTABLE_BASE_PROPERTIES]),h(re,"MUTABLE_META_PROPERTIES",[...re.MUTABLE_BASE_PROPERTIES,"x","y"]),h(re,"INMUTABLE_META_PROPERTIES",[...re.INMUTABLE_BASE_PROPERTIES]),h(re,"META_PROPERTIES",[...re.MUTABLE_META_PROPERTIES,...re.INMUTABLE_META_PROPERTIES]),h(re,"MUTABLE_UPSTREAM_PROPERTIES",[]),h(re,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),h(re,"UPSTREAM_PROPERTIES",[...re.MUTABLE_UPSTREAM_PROPERTIES,...re.INMUTABLE_UPSTREAM_PROPERTIES]),h(re,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),h(re,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),h(re,"DOWNSTREAM_PROPERTIES",[...re.MUTABLE_DOWNSTREAM_PROPERTIES,...re.INMUTABLE_DOWNSTREAM_PROPERTIES]),h(re,"PROPERTIES",[...re.META_PROPERTIES,...re.UPSTREAM_PROPERTIES,...re.DOWNSTREAM_PROPERTIES]);let m=re;var Iw=(r=>(r.PersistChangeSet="persist-change-set",r.CreateSingle="create-single",r.CreateBulk="create-bulk",r.CreateSingleNested="create-single-nested",r.CreateBulkNested="create-bulk-nested",r.Update="update",r.Clone="clone",r.Delete="delete",r.Load="load",r.LoadNested="load-nested",r.LoadVersion="load-version",r))(Iw||{});class Aw extends We{constructor(e){super(Bi,e);h(this,"id",Qe.Parallel);h(this,"name",Qe.Parallel);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",Bi);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Bi.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Bi.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Bi.error?V(Bi.error,this.project):null}}class bw extends We{constructor(e){super(Ht,e);h(this,"id",Ht.id);h(this,"name",Ht.name);h(this,"description",Ht.description);h(this,"version",Ht.version);h(this,"autoexecutable",!1);h(this,"initialData",Ht);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=Ht.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Ht.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Ht.error?V(Ht.error,this.project):null}}class Rw extends We{constructor(e){super(ur,e);h(this,"id",Qe.Sequential);h(this,"name",Qe.Sequential);h(this,"description","Execute a list of actions one after the other");h(this,"version","1");h(this,"autoexecutable",!0);h(this,"initialData",ur);h(this,"type",n.ActionDescriptor);h(this,"inputs",[]);h(this,"outputs",[]);h(this,"error",null);h(this,"project");this.project=e,this.inputs=ur.inputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=ur.outputs.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=ur.error?V(ur.error,this.project):null}}class NS extends We{constructor(a){super(js,a)}}class LS extends We{constructor(a){super(cn,a)}}class jS extends We{constructor(e){super(fn,e);h(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[et.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[et.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[et.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"get-entity-to-match-validate-data"))){const i=this.project.requestActiveValue(e),s=i==null?void 0:i.valueAsTypeSingle;return t==null||t.attemptAutoclose("get-entity-to-match-validate-data",this.id),s}syncOperationInstance(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const i=[],s=[],l=[],o=[],d=this.getEntityToMatchInputMap(e);if(d){const{added:c,updated:T,removed:I,affected:D}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...T),s.push(...c),l.push(...I),o.push(...D)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:T,removed:I,affected:D}=this.syncDataToValidateInputMapDataType(u,t);i.push(...T),s.push(...c),l.push(...I),o.push(...D)}const f=this.getOutputDataOutputMap(e);if(f){const{added:c,updated:T,removed:I,affected:D}=this.syncOutputDataOutputMapDataType(f,t);i.push(...T),s.push(...c),l.push(...I),o.push(...D)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var f,c,T,I,D,P,C,M,G,_,g,q,S,K,de;const i=[],s=[],l=[],o=[];if(((f=e.declaration)==null?void 0:f.id)!==k.operation[et.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};const d=this.project.requestActiveValue(e),u=d==null?void 0:d.valueAsTypeSingle;if(!e.dataType){const me={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:((c=e.declaration.dataType)==null?void 0:c.options)||null,implementationChooseOne:((T=e.declaration.dataType)==null?void 0:T.implementationChooseOne)||!1,staticEntities:((I=e.declaration.dataType)==null?void 0:I.staticEntities)??null,interactiveEntities:((D=e.declaration.dataType)==null?void 0:D.interactiveEntities)??null,actionEntities:((P=e.declaration.dataType)==null?void 0:P.actionEntities)??null,isList:((C=e.declaration.dataType)==null?void 0:C.isList)||!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:(u==null?void 0:u.toJSON())||null,like:!0,inferred:!0,parent:e.toReference()},z=V(me,e.project);z.hydrateAncestors(),z.setParent(e,t),z.initChildren(t),z.setEntity(u),t==null||t.add(z,A.Added),i.push(z),e.setDataType(z)}return(K=e.dataType)==null||K.metaSync({inferred:!0,like:!1,asType:!0,options:((M=e.declaration.dataType)==null?void 0:M.options)||null,implementationChooseOne:((G=e.declaration.dataType)==null?void 0:G.implementationChooseOne)||!1,staticEntities:((_=e.declaration.dataType)==null?void 0:_.staticEntities)??null,interactiveEntities:((g=e.declaration.dataType)==null?void 0:g.interactiveEntities)??null,actionEntities:((q=e.declaration.dataType)==null?void 0:q.actionEntities)??null,isList:((S=e.declaration.dataType)==null?void 0:S.isList)||!1},t),(de=e.dataType)==null||de.setEntity(u),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var c,T,I;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[et.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const D={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,staticEntities:null,interactiveEntities:null,actionEntities:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=V(D,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(T=e.dataType)==null||T.metaSync({inferred:!0,like:!0,asType:!1},t);const f=this.getEntityToMatch(d,t);return(I=e.dataType)==null||I.setEntity(f),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var T,I,D;const i=[],s=[],l=[],o=[];if(((T=e.declaration)==null?void 0:T.id)!==k.operation[et.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const f=this.project.requestActiveValue(d),c=(f==null?void 0:f.valueAsTypeSingle)||null;if(!e.dataType){const P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:(t==null?void 0:t.author)||m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,staticEntities:null,interactiveEntities:null,actionEntities:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:(c==null?void 0:c.toJSON())||null,like:!0,inferred:!0,parent:e.toReference()},C=V(P,e.project);C.hydrateAncestors(),C.setParent(e,t),C.initChildren(t),C.setEntity(c),t==null||t.add(C,A.Added),i.push(C),e.setDataType(C)}return(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t),(D=e.dataType)==null||D.setEntity(c),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var s,l,o;if(((s=e.declaration)==null?void 0:s.id)===k.operation[et.Validate].inputs.entityToMatch.id){const{added:d,updated:u,removed:f,affected:c}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(u),added:p(d),removed:p(f),affected:p(c),self:e.dataType}}if(((l=e.declaration)==null?void 0:l.id)===k.operation[et.Validate].inputs.dataToValidate.id){const{added:d,updated:u,removed:f,affected:c}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(u),added:p(d),removed:p(f),affected:p(c),self:e.dataType}}const i=(o=e.declaration)==null?void 0:o.getDataType(t);if(i&&i.isResolved)return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:i};if(e.readsValue){const d=$i(e.readsValue,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:d}}return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,E().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var i;if(((i=e.declaration)==null?void 0:i.id)===k.operation[et.Validate].outputs.outputEntity.id){const{added:s,updated:l,removed:o,affected:d}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:p(l),added:p(s),removed:p(o),affected:p(d),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class US extends We{constructor(a){super(Ad,a)}}class $S extends We{constructor(a){super(Rd,a)}}class GS extends We{constructor(a){super(Dd,a)}}class gS extends We{constructor(a){super(eo,a)}}class FS extends We{constructor(a){super(Ka,a)}}class xS extends We{constructor(a){super(Ls,a)}}function kS(r){const a=[new Rw(r),new Aw(r),new bw(r),new NS(r),new LS(r),new jS(r),new gS(r),new US(r),new GS(r),new $S(r),new FS(r),new xS(r),new We(Id,r),new We(Td,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class Dw extends Fi{constructor(e){super(Nt,e);h(this,"initialData");h(this,"id",J.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",J.PERSISTED_ENTITY);h(this,"description",Nt.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Nt.abstract);h(this,"static",Nt.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=Nt,this.project=e,this.id=Nt.id,this.version=Nt.version,this.name=Nt.name,this.static=Nt.static,this.abstract=Nt.abstract,this.properties=this.initialData.properties.map(t=>{const i=V(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.methods=this.initialData.methods.map(t=>{const i=V(t,this.project);return i.parent=this,i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=V(t,this.project);return i.parent=this,i}),this.extends=this.initialData.extends.map(t=>V(t,this.project))}}var Ow=(r=>(r.StatusCodeMustBeNumber="status-code-must-be-number",r.StatusCodeMustBeBetween100And599="status-code-must-be-between-100-and-599",r))(Ow||{});function Pw(r,a){const e=[];if(typeof a!="number"){const t=new Ye({id:r.id+"--status-code-must-be-number",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number.`,issue:null,severity:O.Error,code:"status-code-must-be-number",entity:r});return e.push(t),{errors:e,override:a}}if(a<100){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}if(a>599){const t=new Ye({id:r.id+"--status-code-must-be-between-100-and-599",message:`Entity of type ${r.type} with id "${r.id}" has an invalid value "${a}". The value must be a number between 100 and 599.`,issue:null,severity:O.Error,code:"status-code-must-be-between-100-and-599",entity:r});e.push(t)}return{errors:e,override:a}}class ww extends Fi{constructor(e){super(ai,e);h(this,"initialData");h(this,"id",J.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",J.PERSISTED_ENTITY);h(this,"description",ai.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",ai.abstract);h(this,"static",ai.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(this,"project");this.initialData=ai,this.project=e,this.id=ai.id,this.version=ai.version,this.name=ai.name,this.static=ai.static,this.abstract=ai.abstract,this.properties=this.initialData.properties.map(l=>{const o=V(l,this.project);return o.setParent(this,null),o.initChildren(null),o}),this.methods=this.initialData.methods.map(l=>{const o=V(l,this.project);return o.parent=this,o}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const o=V(l,this.project);return o.parent=this,o}),this.extends=this.initialData.extends.map(l=>V(l,this.project));const t=this.properties.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.properties.path.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(l,o)=>uP(l,o);const i=this.abstractMethods.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id);if(!i)throw new Error("Handler method not found in endpoint entity");const s=i.outputs.find(l=>l.id===k["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.outputs.statusCode.id);if(!s)throw new Error("Status code output not found in handler method");s.codeNativeValueValidation=(l,o)=>Pw(l,o)}}const ZS="test_primitive_entities_export";class qS extends Fi{constructor(e){super(Ot,e);h(this,"initialData");h(this,"id",J.PERSISTED_ENTITY);h(this,"version","1");h(this,"name",J.PERSISTED_ENTITY);h(this,"description",Ot.description);h(this,"type",n.BuiltInBaseEntity);h(this,"abstract",Ot.abstract);h(this,"static",Ot.static);h(this,"properties",[]);h(this,"methods",[]);h(this,"abstractMethods",[]);h(this,"extends",[]);h(this,"errors",[]);h(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(i=>{const s=V(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=V(i,this.project);return s.parent=this,s}),this.extends=this.initialData.extends.map(i=>V(i,this.project));const t=this.properties.find(i=>i.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.identifier.id);if(!t)throw new Error("Path property not found in endpoint entity");t._codeNativeValueValidation=(i,s)=>pP(i,s)}}function JS(r){const a=[new Dw(r),new ww(r),new qS(r),new Fi(Ot,r),new Fi(Eo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function WS(r){const a=[new ni(ae,r),new ni(ar,r),new ni(Ee,r),new ni(fd,r),new ni(Ct,r),new ni(or,r),new ni(Zi,r),new ni(lr,r),new ni(Wn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function SS(r){const a=[new We(Io,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function zS(r){const a=[new We(gs,r),new We(wr,r),new We($s,r),new We(Yn,r),new We(Hn,r),new We(lo,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new We(fo,r),new We(Gs,r),new We(po,r),new We($d,r),new We(gd,r),new We(uo,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function YS(r){const a=[new ir(Ao,r),new ir(su,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function HS(r){const a=[new We(En,r),new We(ts,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Fn={},ad={},Ja={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function Cw(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new zl(e),s=new Set;t[e.id]=e,s.add(e.id);const l=E().toISOString();Object.values(t).forEach(u=>{!u||i.allBuiltInEntityIds.includes(u.id)||s.add(u.id)}),i.order=Array.from(s),i.flatRecord=t,i.orderEntities();const o=od(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new b(o,m.sessionAuthor,l,o,!0,"project-init-from-fetch-result")):null;return i.visit(u=>{if(u.id===o.id)return;const f=V(u,o);f.hydrateAncestors(),f.addSelfToProject(null)}),a?(i.visit(u=>{const f=o.get(u.id);f&&f.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):ld(o,l).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.attemptAutoclose("project-init-from-fetch-result",o.id),o}async function KS(r,a=Ja){const e={...Ja,...a};if(e.empty)return{data:{project:{id:r.id,type:n.Project,version:m.UUID.uuid(),createdAt:E().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(e.mock){const i={...cp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{try{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})}catch(s){console.error("Error fetching project: ",s),i({data:null})}})}function od(r){const a=new m(r);return WS(a),JS(a),kS(a),SS(a),zS(a),YS(a),HS(a),Array.from(new Set([...a.getAllBuiltInIds(),...Gi()])).forEach(t=>{if(!a.builtInInstances[t]&&a.instances[t])a.builtInInstances[t]=a.instances[t],delete a.instances[t];else if(!a.builtInInstances[t])throw new Error(`Built in entity was not properly initialized: ${t}`)}),a}function ld(r,a){return r.instancesList.filter(t=>E(t.createdAt).isAfter(E(a)||!!t.previousVersion))}function XS(r,{enrich:a}={enrich:!0}){const e=new Map,t=Array.from(new Set([...r.getAllBuiltInIds(),...Gi()]));Object.keys(r.instances).forEach(u=>{if(t.includes(u)){e.set(u,u);return}const f=r.get(u);if(!nd(f,{...r.instances,...r.builtInInstances}).every(I=>!t.includes(I))){e.set(u,u);return}e.set(u,m.UUID.uuid())});const i=E().toISOString(),s=r.toShallowJSON({seenEntityMaps:e});s.previousVersion=null,s.createdAt=i,s.version=m.UUID.uuid();const l=od(s),o=a?l.addChangeSet(new b(l,m.sessionAuthor,i,l,!0,"project-clone")):null,d=new zl(r);return d.visit(u=>{const f=u.toShallowJSON({seenEntityMaps:e});f.previousVersion=null,f.createdAt=i,f.version=m.UUID.uuid();const c=V(f,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,A.Added)}),a?(d.visit(u=>{const f=l.get(e.get(u.id));f&&f.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):ld(l,i).forEach(f=>{f.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.attemptAutoclose("project-clone",l.id),l}function Vw(r,{enrich:a}={enrich:!0}){const e=od(r),t=E().toISOString(),i=a?e.addChangeSet(new b(e,m.sessionAuthor,t,e,!0,"project-init")):null;i&&(i.type=_c.Automatic);const s=new zl(r);return s.visit(l=>{const o=V(l,e);o.hydrateAncestors(),o.addSelfToProject(i)}),a?(s.visit(l=>{const o=e.get(l.id);o&&o.afterAllChildrenInitialized(i)}),e.afterAllChildrenInitialized(i)):ld(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.attemptAutoclose("project-init",e.id),e}async function QS(r,a=Ja){const e={...Ja,...a};if(r.id&&Fn[r.id]&&!e.ignoreCache)return Fn[r.id];if(r.id&&ad[r.id]&&!e.ignoreCache)return await ad[r.id],Fn[r.id];const t=KS(r,e);r.id&&(ad[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=Vw(cp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=Cw(i.data,{enrich:!!e.enrich}),Fn[r.id]=s,r.id&&delete ad[r.id],s}return null}function ez(r){return Fn[r.id]&&delete Fn[r.id],null}y.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=kc,y.ALL_BUILT_IN_BASE_ENTITIES=WT,y.ALL_BUILT_IN_CONDITION_ENTITIES=aI,y.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=lI,y.ALL_BUILT_IN_LOOP_BODY_ENTITIES=IE,y.ALL_BUILT_IN_LOOP_ENTITIES=TE,y.ALL_BUILT_IN_OPERATION_ENTITIES=B0,y.ALL_BUILT_IN_PRIMITIVE_ENTITIES=Tf,y.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=hI,y.ALL_BUILT_IN_VALUE_DESCRIPTORS=fI,y.ActionDescriptorState=We,y.ActionInputMapState=nW,y.ActionOutputMapState=oW,y.AppendToListOperationInputIds=wy,y.AppendToListOperationOutputIds=Cy,y.ArgumentDeclarationDependencyField=g1,y.ArgumentDeclarationState=br,y.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Gc,y.BUILT_IN_BASE_ENTITY_IDS=k,y.BUILT_IN_ENTITY_TYPES=si,y.BaseCanvasDraggableState=DS,y.BaseEntityNames=J,y.BaseState=RS,y.BaseValueDescriptorIds=Jn,y.BreakStatementDependencyField=Z1,y.BreakStatementState=tn,y.BuiltInBaseEntityState=Fi,y.CACHED_PROJECTS_BY_ID=Fn,y.CALLABLE_ENTITIES_EXPLANATION=mW,y.CALLABLE_TYPES=xi,y.CALLER_ENTITIES_EXPLANATION=z1,y.CALLER_TYPES=ki,y.CALLS_UPDATE_EXPLANATION=nn,y.COMPARISON_CONDITIONS=nI,y.CONDITIONS=sI,y.CUSTOM_ENTITY_OPERATIONS=Ym,y.CallableEntityClass=PS,y.CallerEntityClass=af,y.ChangeSet=b,y.ChangeSetChangeCaptureType=_c,y.ChangeSetEntityChangeType=A,y.ChildEntityState=OS,y.CommonStringValidationErrorCodes=dP,y.ComparisonOperatorTypes=ft,y.ConditionDependencyField=D1,y.ConditionState=zr,y.ContinueStatementDependencyField=E1,y.ContinueStatementState=Gt,y.CreateNewInputIds=Rm,y.CreateNewOutputIds=Dm,y.DRAGGABLE_CALLABLE_TYPES=cd,y.DRAGGABLE_CALLER_TYPES=pf,y.DRAGGABLE_ELEMENT_TYPES=Ha,y.DRAGGABLE_EXECUTABLE_TYPES=Lw,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Ya,y.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=pd,y.DataTypeCompatibilityTypes=wi,y.DataTypeDependencyField=Bc,y.DataTypeParentChildRelation=wt,y.DataTypeState=Zr,y.DefinitionEntityDependencyField=sd,y.DefinitionEntityState=dn,y.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=AS,y.ENTITIES_WITH_VALLUES_EXPLANATION=Zl,y.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=U,y.ENTITY_RECUSION_OPTIONS_DEFAULTS=W,y.ENTITY_TYPES=jw,y.ENTITY_WITH_DECLARATION_TYPES=Mw,y.ENTITY_WITH_LOGIC_SCOPE_TYPES=ht,y.ENTITY_WITH_NAMES_TYPES=cf,y.ENTITY_WITH_PARENT_TYPES=_w,y.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=df,y.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=Bw,y.ENTITY_WITH_VALUE_TYPES=lf,y.ENTRY_POINT_ENTITIES_EXPLANATION=La,y.ENTRY_POINT_TYPES=rt,y.EVENT_TYPES=qn,y.EXECUTABLE_TYPES=Nw,y.EXECUTION_OPERATIONS=bm,y.EndpointEntity=ww,y.EntityAction=Iw,y.EntityError=Ye,y.EntityErrorSeverity=O,y.EntityGenerationError=w,y.EntityGenerationErrorCode=R,y.EntityInstanceErrorCode=x,y.EntityOperations=et,y.EntityType=n,y.EntityWithLogicScopeClass=_S,y.EntityWithValueClass=VS,y.EntryPointEntityClass=wS,y.Events=of,y.ExecutionOperations=Qe,y.ExecutionTerminationType=A1,y.FunctionCallDependencyField=sP,y.FunctionCallState=an,y.FunctionDeclarationDependencyField=u1,y.FunctionDeclarationState=kr,y.GET_PROJECT_OPTIONS_DEFAULTS=Ja,y.GLOBAL_EVENT_DECLARATIONS=oI,y.GetLastInListOperationInputIds=yy,y.GetLastInListOperationOutputIds=my,y.GlobalEventNames=sr,y.GlobalEventState=Wr,y.HTTPOperations=Ut,y.HTTPStatucCodeValidationErrorCodes=Ow,y.HTTP_OPERATIONS=V0,y.InputMapDependencyField=j1,y.InputMapState=er,y.InstalledProjectState=Xr,y.InternalCallDependencyField=N1,y.InternalCallState=Qr,y.JoinListOperationInputIds=jh,y.JoinListOperationOutputIds=Uh,y.LIST_OPERATIONS=xy,y.ListOperations=ye,y.LiteralValueDependencyField=x1,y.LiteralValueState=en,y.LoopDependencyField=b1,y.LoopState=Sr,y.LoopTypes=ee,y.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=sn,y.NUMBER_OPERATIONS=Yf,y.NumberOperations=tt,y.OPERATION_DECLARATIONS=_0,y.OperationDependencyField=f1,y.OperationState=qr,y.OutputMapDependencyField=$1,y.OutputMapParentChildRelation=Zn,y.OutputMapState=tr,y.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=ql,y.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=rn,y.PASS_THROUGH_CALLABLE_TYPES=dt,y.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=uf,y.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=xc,y.ParallelExecutionOperation=Aw,y.PassThroughCallableEntityClass=CS,y.PersistedEntity=Dw,y.PersistedEntityMethods=hi,y.PrimitiveEntityState=ni,y.PrimitiveTypes=N,y.ProjectState=m,y.ProjectStateEvents=Bt,y.PropertyDependencyField=l1,y.PropertyState=xr,y.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=Ew,y.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=vW,y.ReturnDeclarationDependencyField=y1,y.ReturnDeclarationState=ri,y.ReturnStatementDependencyField=Mc,y.ReturnStatementState=Jr,y.STANDALONE_CONDITIONS=YT,y.STRING_OPERATIONS=Lh,y.ScopeCompatibilityType=id,y.SearchDependencyField=V1,y.SearchState=Kr,y.SequentialExecutionOperation=Rw,y.SequentialExecutionOperationInputIds=dm,y.SequentialExecutionOperationOutputIds=um,y.SharedEntityErrorCode=$,y.SharedStateFunctionality=vw,y.SplitListOperationInputIds=Kh,y.SplitListOperationOutputIds=Xh,y.StandaloneOperatorTypes=Ri,y.StringOperations=Ae,y.TERMINATION_TYPES=ot,y.Traverser=zl,y.USER_MANAGED_ENTITY_TYPES=ff,y.UserManagedEntityStateTemplate=bS,y.VALUE_READING_ENTITIES_EXPLANATION=Fc,y.VALUE_READING_TYPES=Pr,y.VALUE_WRITING_ENTITIES_EXPLANATION=Y1,y.VALUE_WRITING_TYPES=Et,y.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=gc,y.VARIABLE_TYPES=it,y.ValueAutogenerationType=vt,y.ValueDescriptorDependencyField=J1,y.ValueDescriptorParentChildRelation=L,y.ValueDescriptorState=ir,y.ValueReadingEntityClass=Or,y.ValueWritingEntityClass=qa,y.VariableDeclarationDependencyField=w1,y.VariableDeclarationState=Hr,y.VariableInputMapState=rW,y.VariableInstanceDependencyField=Lc,y.VariableInstanceState=Yr,y.VariableOutputMapState=aW,y.WaitOperation=bw,y.WaitOperationInputIds=im,y.WaitOperationOutputIds=rm,y.actionDescriptorValidation=YJ,y.appendToListOperation=eo,y.appendToListOperationElementToAppendArgument=Pd,y.appendToListOperationElementToAppendArgumentParentRef=Uy,y.appendToListOperationElementToAppendArgumentRef=By,y.appendToListOperationError=Fy,y.appendToListOperationErrorParentRef=gy,y.appendToListOperationListArgument=Od,y.appendToListOperationListArgumentParentRef=jy,y.appendToListOperationListArgumentRef=Vy,y.appendToListOperationListDataType=_y,y.appendToListOperationResultListDataType=Ly,y.appendToListOperationResultListReturn=Gy,y.appendToListOperationResultListReturnParentRef=$y,y.appendToListOperationResultListReturnRef=Ny,y.appendToListOperationSecondListDataType=My,y.applyNewScope=Q,y.argumentDeclarationValidation=lW,y.asGenerationActionExample=rr,y.booleanPrototype=ar,y.breakStatementValidation=pW,y.calculateNewParentBasedOnCallers=zc,y.capitalizeFirstLetter=_t,y.changeSetJSONRecordToUniqueIds=jJ,y.checkAreDataTypesCompatible=Ci,y.checkAreDefinitionEntitiesCompatibleAsDataType=SO,y.checkArePropertiesCompatibleAsDataType=WO,y.checkExtendsBaseEntity=rd,y.checkHasBaseEntity=gi,y.checkHasMetadataChanged=pt,y.checkImplementationsOverlap=Dr,y.checkImplementsBaseEntity=HW,y.checkIsBranchDependentButNotDirectlyOnBranch=Ua,y.checkIsBranchDependentOnBranch=_W,y.checkIsCallableEntityReachable=Za,y.checkIsCanvasEntity=zW,y.checkIsDetachedBranch=lw,y.checkIsDetachedBranchShallow=nf,y.checkIsGlobalVariable=WW,y.checkIsGloballyDeclared=rf,y.checkIsMethod=pw,y.checkIsNestedScope=td,y.checkScopeCompatibility=ka,y.cloneProject=XS,y.conditionValidation=HJ,y.continueStatementValidation=JJ,y.convertToAbstract=PW,y.convertToNonAbstract=wW,y.convertToNonStatic=VW,y.convertToStatic=CW,y.countedLoopActionDescriptor=gs,y.countedLoopActionDescriptorDynamicReturnDeclaration=pE,y.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=uE,y.countedLoopActionDescriptorStringArgumentDeclaration=dE,y.countedLoopActionDescriptorStringArgumentDeclarationDataType=oE,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=sE,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=nE,y.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=aE,y.countedLoopActionDescriptorStringArgumentDeclarationParentRef=lE,y.countedLoopBodyActionDescriptor=fo,y.countedLoopBodyActionDescriptorAnyDynamicArgument=mE,y.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=yE,y.countedLoopBodyActionDescriptorAnyDynamicReturn=EE,y.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=vE,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=xd,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=fE,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=cE,y.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=hE,y.createDefinitionEntityFromJSONObject=Hl,y.createEntityError=fe,y.createNestedDataTypeForEntity=lP,y.createNewInstanceOperation=cn,y.createNewInstanceOperationEntityToInstanciateArgument=Mm,y.createNewInstanceOperationEntityToInstanciateArgumentRef=Vm,y.createNewInstanceOperationEntityToInstanciateDataType=_m,y.createNewInstanceOperationError=Um,y.createNewInstanceOperationErrorParentRef=jm,y.createNewInstanceOperationNewEntityDataArgument=Cm,y.createNewInstanceOperationNewEntityDataArgumentDataType=wm,y.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Pm,y.createNewInstanceOperationNewEntityDataArgumentParentRef=Om,y.createNewInstanceOperationOutputEntityDeclaration=Lm,y.createNewInstanceOperationOutputEntityDeclarationParentRef=Nm,y.createNewInstanceOperationRef=Bm,y.createSemanticId=s1,y.createStateFromGenerationTargetType=IS,y.createStateFromType=st,y.createStateFromTypeAndSubscribe=V,y.cronJobBuiltInBaseEntity=Eo,y.cronJobBuiltInBaseEntityExpressionProperty=qT,y.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Zw,y.cronJobBuiltInBaseEntityExpressionPropertyRef=kT,y.cronJobBuiltInBaseEntityRef=ZT,y.cronJobTriggeredFunctionDeclarationBlueprint=tu,y.cronJobTriggeredFunctionDeclarationBlueprintParentRef=FT,y.dataTypeCompatibilityToErrorExplanation=rP,y.dataTypeValidation=gJ,y.datePrototype=Zi,y.dateValueAutogenerationSchema=vp,y.definitionEntityToZodSchema=_I,y.definitionEntityValidation=mS,y.deletePersistedEntityMethod=eu,y.deletePersistedEntityMethodParentRef=OT,y.deleteRootProject=ez,y.endpointBuiltInBaseEntity=ai,y.endpointBuiltInBaseEntityRef=DE,y.endpointBuiltInBaseEntityRefFour=aT,y.endpointBuiltInBaseEntityRefThree=NE,y.endpointBuiltInBaseEntityRefTwo=VE,y.endpointBuiltInCorsProperty=OE,y.endpointBuiltInCorsPropertyDataType=RE,y.endpointBuiltInCorsPropertyDataTypeRef=AE,y.endpointBuiltInCorsPropertyRef=bE,y.endpointBuiltInMethodProperty=Zd,y.endpointBuiltInMethodPropertyDataType=ME,y.endpointBuiltInMethodPropertyDataTypeRef=_E,y.endpointBuiltInMethodPropertyRef=BE,y.endpointBuiltInPathProperty=kd,y.endpointBuiltInPathPropertyDataType=CE,y.endpointBuiltInPathPropertyDataTypeRef=PE,y.endpointBuiltInPathPropertyRef=wE,y.endpointPathParamsArgumentDeclaration=Jd,y.endpointPathParamsArgumentDeclarationRef=ZE,y.endpointPathParamsVariableDataType=qE,y.endpointPathParamsVariableDataTypeRef=kE,y.endpointReachedTriggerActionDescriptor=Kd,y.endpointReachedTriggerActionDescriptorRef=JE,y.endpointReachedTriggerActionDescriptorRefFour=zE,y.endpointReachedTriggerActionDescriptorRefThree=SE,y.endpointReachedTriggerActionDescriptorRefTwo=WE,y.endpointRequestBodyArgumentDeclaration=Sd,y.endpointRequestBodyArgumentDeclarationRef=$E,y.endpointRequestBodyVariableDataType=GE,y.endpointRequestHeadersArgumentDeclaration=qd,y.endpointRequestHeadersArgumentDeclarationRef=jE,y.endpointRequestHeadersVariableDataType=UE,y.endpointRequestHeadersVariableDataTypeRef=LE,y.endpointRequestQueryParamsArgumentDeclaration=Wd,y.endpointRequestQueryParamsArgumentDeclarationRef=FE,y.endpointRequestQueryParamsVariableDataType=xE,y.endpointRequestQueryParamsVariableDataTypeRef=gE,y.endpointResponseBodyDataType=nT,y.endpointResponseBodyReturnDeclaration=Hd,y.endpointResponseBodyReturnDeclarationRef=rT,y.endpointResponseCodeDataType=HE,y.endpointResponseCodeReturnDeclaration=zd,y.endpointResponseCodeReturnDeclarationDefaultValueParentRef=XE,y.endpointResponseCodeReturnDeclarationRef=YE,y.endpointResponseHeadersDataType=tT,y.endpointResponseHeadersDataTypeRef=QE,y.endpointResponseHeadersReturnDeclaration=Yd,y.endpointResponseHeadersReturnDeclarationRef=eT,y.endpointReturnStatementRef=KE,y.endpointReturnStatementRefThree=sT,y.endpointReturnStatementRefTwo=iT,y.enrichFromKnownEntities=$a,y.enumOptionsProperty=Ef,y.enumOptionsPropertyDataType=mf,y.enumOptionsPropertyDataTypeRef=hf,y.enumOptionsPropertyRef=yf,y.enumPrototype=or,y.enumPrototypeRef=vf,y.executionBuiltInBaseEntity=To,y.executionBuiltInEntityAbortMethod=iu,y.executionBuiltInEntityAbortMethodParentRef=JT,y.filterOutDuplicateEntities=p,y.filterOutDuplicateErrors=z3,y.findEntityFromKeys=Wc,y.findReferenceToSelfInList=PP,y.findReferencesToSelfInProject=gW,y.flattenActionDescriptor=wP,y.flattenArgumentDeclaration=CP,y.flattenBreakStatement=VP,y.flattenBuiltInBaseEntity=_P,y.flattenCalls=Vi,y.flattenCanvasAncestorsUntil=_s,y.flattenCondition=BP,y.flattenContinueStatement=MP,y.flattenDataType=LP,y.flattenDefinitionEntity=NP,y.flattenDefinitionEntityExtensionAndImplementationTypes=tf,y.flattenDefinitionEntityExtensionTypes=ga,y.flattenDefinitionEntityExtensions=Qc,y.flattenDefinitionEntityImplementations=ef,y.flattenDefinitionEntityImplementionTypes=Ga,y.flattenDerivedCanvasEntities=ci,y.flattenDetachedBranch=uw,y.flattenElementCalls=Te,y.flattenElementCallsOnTheSameScope=GW,y.flattenEntity=j,y.flattenFunctionCall=jP,y.flattenFunctionDeclaration=UP,y.flattenGlobalEvent=$P,y.flattenInputMap=GP,y.flattenInstalledProject=gP,y.flattenInternalCall=FP,y.flattenLiteralValue=xP,y.flattenLoop=kP,y.flattenOperation=ZP,y.flattenOutputMap=qP,y.flattenPrimitiveEntity=JP,y.flattenProject=WP,y.flattenProjectElements=OP,y.flattenProperty=SP,y.flattenRelatedCanvasElementsOnTheLeft=sw,y.flattenRelatedCanvasElementsOnTheRight=nw,y.flattenReturnDeclaration=zP,y.flattenReturnStatement=YP,y.flattenSearch=HP,y.flattenValueDescriptor=KP,y.flattenVariableDeclaration=XP,y.flattenVariableInstance=QP,y.flattenVariableReads=DP,y.flattenVariableWrites=RP,y.flattenVariables=He,y.fromChangeSetToRecordChangeSet=rS,y.fromZodParseToEntityGenerationErrors=jc,y.functionCallValidation=OW,y.functionDeclarationValidation=GJ,y.generate=SV,y.generateActionExample=EW,y.generateExecutionDataType=OJ,y.generateIdFromStrategy=yt,y.generateMutablePropertiesExplanation=Fl,y.generateRandomBoolean=rA,y.generateRandomDate=LI,y.generateRandomDateAfter=BI,y.generateRandomDateBefore=MI,y.generateRandomDateBetweenRange=NI,y.generateRandomNumber=XI,y.generateRandomNumberAfter=YI,y.generateRandomNumberBefore=HI,y.generateRandomNumberBetweenRange=KI,y.generateRandomText=iA,y.generateRandomTextAfter=QI,y.generateRandomTextBefore=eA,y.generateRandomTextBetweenRange=tA,y.generateUniqueUUID=zI,y.getAllActionDescriptorsForConditions=Sl,y.getAllActionDescriptorsForGlobalEvents=Jl,y.getAllActionDescriptorsForLoops=Wl,y.getAllActionDescriptorsForOperations=bW,y.getAllBuiltInEntityIds=Gi,y.getAllGloballyDeclaredFunctionDeclarationsExplanation=eP,y.getBaseBuiltInEntities=St,y.getBaseSchemaBasedOnType=W1,y.getBuiltInEntityOwner=ln,y.getCallableEntityReferenceSchema=Vt,y.getCallableEntityTypeSchema=LD,y.getCalledBy=Ai,y.getCallerEntityReferenceSchema=XZ,y.getCallerEntityTypeSchema=KZ,y.getCalls=Hc,y.getCanvasEntitiesDerivedFromInternalCalls=rw,y.getCanvasEntitiesDerivedFromWrites=Bs,y.getCanvasEntityDerivedFromValueReadingEntity=ed,y.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=iw,y.getCanvasEntityReferenceSchema=yq,y.getCanvasEntityTypeSchema=hq,y.getChildrenEntityWithValues=MW,y.getColumnProperties=eS,y.getCommonAncestor=Yc,y.getCommonChildren=cP,y.getDatabaseEntities=XW,y.getDatabaseEntity=tS,y.getDeclaration=Gn,y.getDeclarationOutputedError=sS,y.getDeepestScope=fw,y.getDraggableCallableEntityReferenceSchema=UD,y.getDraggableCallableEntityTypeSchema=jD,y.getDraggableCallerEntityReferenceSchema=eq,y.getDraggableCallerEntityTypeSchema=QZ,y.getDraggableExecutableEntityReferenceSchema=nq,y.getDraggableExecutableEntityTypeSchema=rq,y.getDraggablePassThroughCallableEntityReferenceSchema=Cl,y.getDraggablePassThroughCallableEntityTypeSchema=wl,y.getDraggablePlayableEntityReferenceSchema=dq,y.getDraggablePlayableEntityTypeSchema=lq,y.getEntitiesCreatedSinceInitialization=ld,y.getEntityArgumentDeclarations=Xc,y.getEntityInputMaps=ew,y.getEntityOutputMaps=ZW,y.getEntityReferenceSchema=fq,y.getEntityReturnDeclarations=tw,y.getEntityTypeSchema=cq,y.getEntityWithLogicScopeReferenceSchema=Tr,y.getEntityWithLogicScopeTypeSchema=sq,y.getEntityWithValueReferenceSchema=ND,y.getEntityWithValueTypeSchema=HZ,y.getEntryPointEntityReferenceSchema=Pt,y.getEntryPointEntityTypeSchema=Gr,y.getEventEntityReferenceSchema=Ol,y.getEventEntityTypeSchema=Dl,y.getExecutableEntityReferenceSchema=iq,y.getExecutableEntityTypeSchema=tq,y.getExtendedBuiltInEntity=qW,y.getExtendedDefinitionEntity=ow,y.getFirstNonLoopScopeOwner=It,y.getGenerationTargetSchemaBasedOnType=S1,y.getHeadIfPartOfDetachedBranch=dw,y.getHighestScope=cw,y.getImplementedBuiltInEntity=JW,y.getIsInteractive=Fa,y.getLastInListOperation=Dd,y.getLastInListOperationError=Py,y.getLastInListOperationErrorParentRef=Oy,y.getLastInListOperationInputListArgument=by,y.getLastInListOperationInputListArgumentParentRef=Ay,y.getLastInListOperationInputListArgumentRef=vy,y.getLastInListOperationInputListDataType=Ey,y.getLastInListOperationOutputElementDataType=Iy,y.getLastInListOperationOutputElementReturn=Dy,y.getLastInListOperationOutputElementReturnParentRef=Ry,y.getLastInListOperationOutputElementReturnRef=Ty,y.getLinkedEntitiesFromArgumentDeclaration=$W,y.getLowestPersistedEntityImplementation=aw,y.getParentCallableEntity=fP,y.getParentCallerEntity=yP,y.getParentCanvasEntities=gt,y.getParentCanvasEntity=Rt,y.getParentCanvasEntityFromTransfer=Kl,y.getParentEntryPoint=BW,y.getParentPassthroughCallableEntity=hP,y.getPassThroughCallableEntityReferenceSchema=nt,y.getPassThroughCallableEntityTypeSchema=Pl,y.getPeristedEntities=KW,y.getPlayableEntityReferenceSchema=oq,y.getPlayableEntityTypeSchema=aq,y.getProject=QS,y.getPrototypeByType=xa,y.getRecusriveParentsIds=nd,y.getReferenceEntityId=B,y.getReferencedEntitiesStateOrErrors=kl,y.getReferencedEntityStateOrErrors=Uc,y.getReferencedIds=Ql,y.getRelatedCanvasElementsOnTheLeft=gn,y.getRelatedCanvasElementsOnTheLeftFromTransfer=FW,y.getRelatedCanvasElementsOnTheRight=on,y.getRootEntryPointScopeOwner=sf,y.getScopeOwner=zt,y.getStateClassFromType=iS,y.getTerminationReferenceSchema=pq,y.getTerminationTypeSchema=uq,y.getTouchedCanvasEntitiesFromChangeSet=nS,y.getUsedArgFromDeclaration=xW,y.getUsedReturnFromDeclaration=kW,y.getValueReadingEntityReferenceSchema=MD,y.getValueReadingEntityTypeSchema=Er,y.getValueWritingEntityReferenceSchema=YZ,y.getValueWritingEntityTypeSchema=Ra,y.getVariableFromInputMapping=vP,y.getVariableFromReturnVariablePointer=IP,y.getVariableReferenceSchema=$r,y.getVariableTypeSchema=Mn,y.getVariablesFromArgumentDeclarations=Xl,y.getVariablesFromInputMaps=EP,y.getVariablesFromOutputMapping=AP,y.getVariablesFromOutputMaps=bP,y.getVariablesFromReturnDeclarations=TP,y.getVariablesInSameOrHigherScope=bc,y.getWrites=Kc,y.globalEventValidation=WJ,y.groupCallsBasedOnParallelizableExecution=LW,y.handleAfterEntityImplementationSideEffects=oP,y.handleBeforeEntityImplementationSideEffects=aP,y.httpRequestBodyArgument=no,y.httpRequestBodyArgumentRef=l0,y.httpRequestBodyDataType=d0,y.httpRequestHeadersArgument=ro,y.httpRequestHeadersArgumentRef=a0,y.httpRequestHeadersDataType=o0,y.httpRequestMethodArgument=to,y.httpRequestMethodArgumentRef=n0,y.httpRequestMethodDataType=s0,y.httpRequestMethodDataTypeRef=i0,y.httpRequestOperation=js,y.httpRequestOperationErrorValueDescriptor=Md,y.httpRequestOperationErrorValueDescriptorDatatype=C0,y.httpRequestOperationErrorValueDescriptorRef=w0,y.httpRequestOperationRef=R0,y.httpRequestOperationRefEight=O0,y.httpRequestOperationRefFive=A0,y.httpRequestOperationRefFour=I0,y.httpRequestOperationRefNine=P0,y.httpRequestOperationRefSeven=D0,y.httpRequestOperationRefSix=b0,y.httpRequestOperationRefThree=T0,y.httpRequestOperationRefTwo=E0,y.httpRequestQueryParamsArgument=Bd,y.httpRequestQueryParamsArgumentRef=e0,y.httpRequestQueryParamsDataType=t0,y.httpRequestVariableURLArgument=io,y.httpRequestVariableURLArgumentRef=Xm,y.httpRequestVariableURLDataType=Qm,y.httpRequestVariableURLDataTypeRef=Hm,y.httpResponseBodyReturnDataType=v0,y.httpResponseBodyReturnDataTypeRef=y0,y.httpResponseBodyReturnReturn=oo,y.httpResponseBodyReturnReturnRef=m0,y.httpResponseCodeDataType=p0,y.httpResponseCodeReturn=so,y.httpResponseCodeReturnRef=u0,y.httpResponseHeadersDataType=h0,y.httpResponseHeadersDataTypeRef=c0,y.httpResponseHeadersReturn=ao,y.httpResponseHeadersReturnRef=f0,y.httpStatusCodeValueValidation=Pw,y.implement=Yl,y.inferArgumentDeclarationDataType=zO,y.inferDataType=$i,y.inferInputMapDataType=Tc,y.inferOutputMapDataType=Ac,y.inferPropertyDataType=KO,y.inferReturnDeclarationDataType=Ic,y.inferValueDescriptorDataType=XO,y.inferVariableDeclarationDataType=HO,y.inferVariableInstanceDataType=YO,y.initBaseProjectEntity=od,y.initProject=Vw,y.initProjectFromFetchResult=Cw,y.inputMapValidation=iW,y.installedProjectValidation=eW,y.internalCallValidation=tW,y.isPromise=Jc,y.iterateOverListActionDescriptorListArgumentDeclaration=lv,y.iterateOverListActionDescriptorListArgumentDeclarationDataType=av,y.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=sv,y.iterateOverListActionDescriptorListArgumentDeclarationParentRef=ov,y.iterateOverListLoopActionDescriptor=wr,y.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=uv,y.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=dv,y.iterateOverListLoopBodyActionDescriptor=Gs,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=Tv,y.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Ev,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Av,y.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=Iv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=co,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=cv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=pv,y.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=fv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=vv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=yv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=hv,y.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=mv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Pv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=Dv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Rv,y.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=Ov,y.iterateOverObjectKeysLoopActionDescriptor=Yn,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Cv,y.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=wv,y.iterateOverObjectKeysLoopBodyActionDescriptor=$d,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=$v,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Uv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=gv,y.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Gv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ud,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=_v,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Vv,y.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Bv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Nv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Mv,y.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Lv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=qv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=kv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=xv,y.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Zv,y.iterateOverObjectValuesLoopActionDescriptor=Hn,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Wv,y.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=Jv,y.iterateOverObjectValuesLoopBodyActionDescriptor=gd,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=tE,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=eE,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=rE,y.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=iE,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Gd,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=zv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Sv,y.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Yv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Qv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Kv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Hv,y.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Xv,y.iterateOverStringActionDescriptorDynamicReturnDeclaration=S0,y.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=W0,y.iterateOverStringActionDescriptorStringArgumentDeclaration=J0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=Z0,y.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=k0,y.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=q0,y.iterateOverStringLoopActionDescriptor=$s,y.iterateOverStringLoopBodyActionDescriptor=po,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=tv,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=ev,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=rv,y.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=iv,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ld,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=Y0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=z0,y.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=H0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=jd,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=X0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=K0,y.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Q0,y.joinListOperation=Ad,y.joinListOperationError=Hh,y.joinListOperationErrorParentRef=Yh,y.joinListOperationFirstListArgument=qh,y.joinListOperationFirstListArgumentParentRef=Zh,y.joinListOperationFirstListArgumentRef=$h,y.joinListOperationFirstListDataType=Gh,y.joinListOperationResultListDataType=kh,y.joinListOperationResultListReturn=zh,y.joinListOperationResultListReturnParentRef=Sh,y.joinListOperationResultListReturnRef=xh,y.joinListOperationSecondListArgument=Wh,y.joinListOperationSecondListArgumentParentRef=Jh,y.joinListOperationSecondListArgumentRef=gh,y.joinListOperationSecondListDataType=Fh,y.joinListWithLastSeparator=se,y.joinStringsOperation=Ls,y.joinStringsOperationDynamicStringArgument=mh,y.joinStringsOperationDynamicStringArgumentParentRef=yh,y.joinStringsOperationDynamicStringArgumentRef=fh,y.joinStringsOperationDynamicStringDataType=hh,y.joinStringsOperationError=ch,y.joinStringsOperationErrorParentRef=ph,y.joinStringsOperationFirstStringArgument=Xa,y.joinStringsOperationFirstStringArgumentParentRef=ih,y.joinStringsOperationFirstStringArgumentRef=Hf,y.joinStringsOperationFirstStringDataType=Kf,y.joinStringsOperationResultStringDataType=th,y.joinStringsOperationResultStringReturn=Ns,y.joinStringsOperationResultStringReturnParentRef=uh,y.joinStringsOperationResultStringReturnRef=eh,y.joinStringsOperationSecondStringArgument=Qa,y.joinStringsOperationSecondStringArgumentParentRef=dh,y.joinStringsOperationSecondStringArgumentRef=Xf,y.joinStringsOperationSecondStringDataType=Qf,y.joinStringsOperationSeparatorStringArgument=lh,y.joinStringsOperationSeparatorStringArgumentParentRef=oh,y.joinStringsOperationSeparatorStringArgumentRef=rh,y.joinStringsOperationSeparatorStringDataType=ah,y.joinStringsOperationSeparatorStringDataTypeDefaultValue=sh,y.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=nh,y.keyValuePrototype=Wn,y.literalValudValidation=dW,y.loopValidation=zJ,y.lowercaseFirstLetter=Na,y.manualFlowActionDescriptorDeclarationArgumentDeclaration=Nd,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=j0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=L0,y.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=U0,y.manualFlowLoopActionDescriptor=lo,y.manualFlowLoopActionDescriptorDynamicReturnDeclaration=N0,y.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=M0,y.manualFlowLoopBodyActionDescriptor=uo,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=G0,y.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=$0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=F0,y.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=g0,y.mapActionDescriptorToTypeItRepresents=YW,y.mergeEntityErrorsList=Y3,y.mergeListOfEntities=SW,y.methodDefaultValue=r0,y.mockClientProject=cp,y.moreThanOrEqualCondition=ts,y.moreThanOrEqualConditionLeftHandArgument=QT,y.moreThanOrEqualConditionLeftHandArgumentDataType=KT,y.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=HT,y.moreThanOrEqualConditionLeftHandArgumentParentRef=XT,y.moreThanOrEqualConditionRightHandArgument=rI,y.moreThanOrEqualConditionRightHandArgumentDataType=tI,y.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=eI,y.moreThanOrEqualConditionRightHandArgumentParentRef=iI,y.noSpacesOrDashesValueValidation=pP,y.noSpacesValueValidation=uP,y.notEmptyCondition=En,y.notEmptyConditionArgument=zT,y.notEmptyConditionRef=ST,y.nullPrototype=fd,y.numberAdditionOperation=Ka,y.numberAdditionOperationDynamicSummandArgument=Mf,y.numberAdditionOperationDynamicSummandArgumentType=Bf,y.numberAdditionOperationDynamicSummandArgumentTypeParentRef=_f,y.numberAdditionOperationError=Vf,y.numberAdditionOperationErrorParentRef=Cf,y.numberAdditionOperationFirstNumberArgument=hd,y.numberAdditionOperationFirstNumberArgumentRef=If,y.numberAdditionOperationFirstNumberDataType=Af,y.numberAdditionOperationRef=Pf,y.numberAdditionOperationRefThree=md,y.numberAdditionOperationRefTwo=wf,y.numberAdditionOperationResultNumberDataType=Of,y.numberAdditionOperationResultNumberReturn=vd,y.numberAdditionOperationResultNumberReturnRef=Df,y.numberAdditionOperationSecondNumberArgument=yd,y.numberAdditionOperationSecondNumberArgumentRef=bf,y.numberAdditionOperationSecondNumberDataType=Rf,y.numberPrototype=Ee,y.numberSubtractionOperation=Td,y.numberSubtractionOperationDynamicSubtrahendArgument=zf,y.numberSubtractionOperationDynamicSubtrahendArgumentType=Sf,y.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Wf,y.numberSubtractionOperationError=Jf,y.numberSubtractionOperationErrorParentRef=qf,y.numberSubtractionOperationFirstNumberArgument=gf,y.numberSubtractionOperationFirstNumberArgumentRef=Nf,y.numberSubtractionOperationFirstNumberDataType=Lf,y.numberSubtractionOperationRef=Ed,y.numberSubtractionOperationRefThree=kf,y.numberSubtractionOperationRefTwo=Ff,y.numberSubtractionOperationResultNumberDataType=Gf,y.numberSubtractionOperationResultNumberReturn=Zf,y.numberSubtractionOperationResultNumberReturnRef=$f,y.numberSubtractionOperationSecondNumberArgument=xf,y.numberSubtractionOperationSecondNumberArgumentRef=jf,y.numberSubtractionOperationSecondNumberDataType=Uf,y.numberValueAutogenerationSchema=mp,y.operationValidation=kJ,y.outputMapValidation=sW,y.parallelExecutionOperation=Bi,y.parallelExecutionOperationError=tm,y.parallelExecutionOperationErrorParentRef=em,y.parallelExecutionOperationListOfExecutionResultsDataType=Ky,y.parallelExecutionOperationListOfExecutionResultsReturn=Cd,y.parallelExecutionOperationListOfExecutionResultsReturnRef=Hy,y.parallelExecutionOperationListOfFunctionsArgument=wd,y.parallelExecutionOperationListOfFunctionsArgumentDatatype=Yy,y.parallelExecutionOperationListOfFunctionsArgumentRef=zy,y.parallelExecutionOperationListOfFunctionsBlueprint=Sy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=Jy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=qy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Zy,y.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=ky,y.parallelExecutionOperationListOfFunctionsBlueprintParentRef=Wy,y.parallelExecutionOperationRef=Xy,y.parallelExecutionOperationRefThree=Qy,y.persistedBuiltInBaseEntity=Nt,y.persistedBuiltInBaseEntityDatabaseProperty=Xn,y.persistedBuiltInBaseEntityDatabasePropertyDataType=CT,y.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=Fw,y.persistedBuiltInBaseEntityDatabasePropertyParentRef=VT,y.persistedBuiltInBaseEntityDatabasePropertyRef=wT,y.persistedBuiltInBaseEntityPrimaryKeyProperty=Qn,y.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=$T,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=BT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=_T,y.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=GT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=UT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=NT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=MT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=jT,y.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=LT,y.processOutputGlobalValueDescriptorDataType=uI,y.processOutputGlobalValueDescriptorReturn=Ao,y.processOutputGlobalValueDescriptorReturnRef=dI,y.projectPublicationCompletedGlobalEvent=Io,y.propertyToZodSchema=VI,y.propertyValidation=MJ,y.relationalDatabaseBuiltInBaseEntity=Ot,y.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Qd,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=RT,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=bT,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=DT,y.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=AT,y.relationalDatabaseBuiltInBaseEntityDefaultProperty=Xd,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=IT,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=ET,y.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=TT,y.relationalDatabaseBuiltInBaseEntityIdentifierProperty=ho,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=dT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=oT,y.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=lT,y.relationalDatabaseBuiltInBaseEntityMinSizeProperty=vo,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=vT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=yT,y.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=mT,y.relationalDatabaseBuiltInBaseEntityPasswordProperty=mo,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=fT,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=gw,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyDefaultValueParentRef=hT,y.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=cT,y.relationalDatabaseBuiltInBaseEntityRef=Kn,y.relationalDatabaseBuiltInBaseEntityUsernameProperty=yo,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=pT,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=Gw,y.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=uT,y.resolveActionDescriptorName=n1,y.resolveBaseEntityName=e1,y.resolveBuiltInBaseEntityDataTypeLabel=t1,y.resolveClonedEntityProject=mt,y.resolveConditionOperatorLabel=gl,y.resolveDataType=Ul,y.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Sc,y.resolveDataTypeLabel=Gl,y.resolveDefinitionEntityDataTypeLabel=_J,y.resolveEntityDataTypeLabel=VJ,y.resolveEntityName=F,y.resolveFirstCallsSecond=jW,y.resolveFirstWritesSecond=UW,y.resolvePrimaryKeyProperty=QW,y.resolvePrimitiveEntityName=r1,y.resolveSearchName=i1,y.resolveVariableScope=PJ,y.returnDeclarationValidation=ZJ,y.returnStatementValidation=qJ,y.searchStatementErrorGlobalValueDescriptor=su,y.searchStatementErrorGlobalValueDescriptorDataType=cI,y.searchStatementErrorGlobalValueDescriptorRef=pI,y.searchValidation=QJ,y.sequentialExecutionOperation=ur,y.sequentialExecutionOperationError=Am,y.sequentialExecutionOperationErrorParentRef=Im,y.sequentialExecutionOperationListOfExecutionResultsDataType=vm,y.sequentialExecutionOperationListOfExecutionResultsReturn=_d,y.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=Tm,y.sequentialExecutionOperationListOfExecutionResultsReturnRef=mm,y.sequentialExecutionOperationListOfFunctionsArgument=Vd,y.sequentialExecutionOperationListOfFunctionsArgumentDatatype=ym,y.sequentialExecutionOperationListOfFunctionsArgumentParentRef=Em,y.sequentialExecutionOperationListOfFunctionsArgumentRef=hm,y.sequentialExecutionOperationListOfFunctionsBlueprint=fm,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=cm,y.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=pm,y.softDeletePersistedEntityMethod=xw,y.softDeletePersistedEntityMethodParentRef=gT,y.sortCallsBasedOnExecutionDependencies=mP,y.sortChildrenEntitiesBasedOnExecutionDependencies=NW,y.splitListOperation=Rd,y.splitListOperationError=hy,y.splitListOperationErrorParentRef=fy,y.splitListOperationFirstOutputListDataType=ry,y.splitListOperationFirstOutputListReturn=dy,y.splitListOperationFirstOutputListReturnParentRef=ly,y.splitListOperationFirstOutputListReturnRef=bd,y.splitListOperationInputListArgument=sy,y.splitListOperationInputListArgumentParentRef=ny,y.splitListOperationInputListArgumentRef=Qh,y.splitListOperationInputListDataType=ey,y.splitListOperationSecondOutputListDataType=uy,y.splitListOperationSecondOutputListReturn=cy,y.splitListOperationSecondOutputListReturnParentRef=py,y.splitListOperationSplitIndexArgument=oy,y.splitListOperationSplitIndexArgumentParentRef=ay,y.splitListOperationSplitIndexArgumentRef=ty,y.splitListOperationSplitIndexDataType=iy,y.splitStringOperation=Id,y.splitStringOperationError=Nh,y.splitStringOperationErrorParentRef=Mh,y.splitStringOperationFirstPartResultStringDataType=bh,y.splitStringOperationFirstPartResultStringReturn=Bh,y.splitStringOperationFirstPartResultStringReturnParentRef=_h,y.splitStringOperationFirstPartResultStringReturnRef=Ah,y.splitStringOperationIndexArgument=Ch,y.splitStringOperationIndexArgumentParentRef=wh,y.splitStringOperationIndexArgumentRef=Th,y.splitStringOperationIndexDataType=Ih,y.splitStringOperationSecondPartResultStringDataType=Dh,y.splitStringOperationSecondPartResultStringReturn=Uw,y.splitStringOperationSecondPartResultStringReturnParentRef=Vh,y.splitStringOperationSecondPartResultStringReturnRef=Rh,y.splitStringOperationStringArgument=Ph,y.splitStringOperationStringArgumentParentRef=Oh,y.splitStringOperationStringArgumentRef=vh,y.splitStringOperationStringDataType=Eh,y.stringPrototype=ae,y.stringValueAutogenerationSchema=yp,y.suggestNewIdForEntity=Vc,y.test_primitive_entities_export=ZS,y.toCamelCase=wJ,y.toEntityState=bi,y.toKebabCase=QO,y.toLowerCaseKebabCase=$l,y.toPascalCase=CJ,y.untypedDataPrototype=Ct,y.updateErrorsList=Ke,y.urlDefaultValue=Km,y.uuidPrototype=lr,y.validateArgumentDeclarationName=wc,y.validateCalledByErrorIdInAction=IW,y.validateCalledByIdInAction=TW,y.validateCallers=Q1,y.validateConditionEntityDeclaration=RW,y.validateDataOperation=fn,y.validateDataOperationDataToValidateArgument=Fm,y.validateDataOperationDataToValidateArgumentParentRef=gm,y.validateDataOperationDataToValidateArgumentRef=$m,y.validateDataOperationDataToValidateDataType=Gm,y.validateDataOperationEntityToMatchTypeArgument=qm,y.validateDataOperationEntityToMatchTypeArgumentParentRef=Zm,y.validateDataOperationEntityToMatchTypeArgumentRef=xm,y.validateDataOperationEntityToMatchTypeDataType=km,y.validateDataOperationError=zm,y.validateDataOperationErrorParentRef=Sm,y.validateDataOperationOutputEntityDeclaration=Wm,y.validateDataOperationOutputEntityDeclarationParentRef=Jm,y.validateDefinitionEntityName=Rc,y.validateEntryCaller=X1,y.validateErrorCaller=K1,y.validateFunctionCallDeclaration=tP,y.validateFunctionDeclarationName=Dc,y.validateGeneratedEntityParentIsNotBuiltInEntity=yW,y.validateGeneration=fW,y.validateGenerationTarget=ut,y.validateGenerationUpdate=hW,y.validateLoopEntityDeclaration=DW,y.validateName=BJ,y.validateOperationEntityDeclaration=iP,y.validatePropertyName=Pc,y.validateReachability=Rr,y.validateReadsValueInActionPayload=AW,y.validateReferenceObject=xl,y.validateReferenceToOne=$c,y.validateReferences=bt,y.validateReturnDeclarationName=Cc,y.validateSuccessCaller=H1,y.validateValueReaderGenerationUpdate=ja,y.validateValueWritter=Zc,y.validateVariableDeclarationName=Oc,y.validateVariableInternalCallUse=qc,y.valueAutogenerationCurrentDateAndTimeSchema=pD,y.valueAutogenerationGenericSchema=dl,y.valueAutogenerationOptions=Ep,y.valueAutogenerationOptionsSchema=uD,y.valueAutogenerationRandomBooleanSchema=hp,y.valueAutogenerationRandomDateBetweenSchema=ID,y.valueAutogenerationRandomDateFromSchema=ED,y.valueAutogenerationRandomDateSchema=cl,y.valueAutogenerationRandomDateUntilSchema=TD,y.valueAutogenerationRandomNumberBetweenSchema=hD,y.valueAutogenerationRandomNumberFromSchema=cD,y.valueAutogenerationRandomNumberSchema=ul,y.valueAutogenerationRandomNumberUntilSchema=fD,y.valueAutogenerationRandomSchema=ma,y.valueAutogenerationRandomTextBetweenSchema=vD,y.valueAutogenerationRandomTextFromSchema=yD,y.valueAutogenerationRandomTextSchema=pl,y.valueAutogenerationRandomTextUntilSchema=mD,y.valueAutogenerationRangeValueTypesSchema=ya,y.valueAutogenerationUniqueSchema=fp,y.valueDescriptorValidation=cW,y.variableDeclarationValidation=KJ,y.variableInstanceValidation=XJ,y.waitOperation=Ht,y.waitOperationMillisecondsNumberArgument=pn,y.waitOperationMillisecondsNumberArgumentRef=nm,y.waitOperationMillisecondsNumberDataType=sm,y.waitOperationOperationError=lm,y.waitOperationOperationErrorParentRef=om,y.waitOperationRef=am,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|