@elyx-code/project-logic-tree 0.0.6410 → 0.0.6411

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 CHANGED
@@ -105165,7 +105165,7 @@ ${PI}`,
105165
105165
  )
105166
105166
  ), l = null) {
105167
105167
  const p = l || P.UUID.uuid(), e = Ot.new(a);
105168
- e.id = p, e.name = this.name, e.description = this.description, e.index = this.index, e.private = this.private, e.required = this.required, e.static = this.static, e.constant = this.constant, e.hidden = this.hidden, e.parent = i.toReference(), e.implements = this.toJSON();
105168
+ e.id = p, e.name = this.name, e.description = this.description, e.index = this.index, e.private = this.private, e.required = this.required, e.static = this.static, e.constant = this.constant, e.hidden = this.hidden, e.interactive = this.interactive, e.parent = i.toReference(), e.implements = this.toJSON();
105169
105169
  const y = ee(
105170
105170
  e,
105171
105171
  this.project
@@ -402,7 +402,7 @@ Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueIn
402
402
  Please provide a unique 'name' string.`,severity:q.Error,code:ae.NameNotUniqueInScope,issue:null}))}}return i}function pAe(d,u){switch(d.type){case f.DefinitionEntity:return Kb(d,u);case f.FunctionDeclaration:return kb(d,u);case f.VariableDeclaration:return qb(d,u);case f.Property:return Jb(d,u);case f.ArgumentDeclaration:return Zb(d,u);case f.ReturnDeclaration:return Hb(d,u);default:return[]}}function Wb(d,u){switch(d.type){case f.FunctionCall:case f.InternalCall:return ki(d.declaration,u).codeName}if(!Ig.includes(d.type))return null;const i=d;switch(d.type){case f.ActionDescriptor:case f.DefinitionEntity:case f.VariableDeclaration:case f.ValueDescriptor:case f.FunctionDeclaration:return d.codeName||null;case f.ArgumentDeclaration:case f.ReturnDeclaration:{if(d.implements){const a=ki(d.implements,u);return Wb(a,u)||null}return d.codeName||null}case f.InputMap:case f.OutputMap:case f.VariableInstance:{if(d.declaration){const a=ki(d.declaration,u);return Wb(a,u)||""}break}}return i.codeName||null}function DS(d,u,i){const l=`${Mm(d)}-${u}-id`;return i.instances[l]?N.UUID.uuid():l}function Yb(d,u){let i="",a=null;if(d.parent){const p=u.get(d.parent);p&&(a=p)}let l="";return a&&(l=`${Mm(ne(a,u))}-`),i=`${l}${Mm(ne(d,u))}-id`,u.instances[i]?N.UUID.uuid():i}function Gr(d,u,i="uuid"){return i==="semantic"?DS(ne(d,u),d.type,u):N.UUID.uuid()}const fAe=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function OS(d){return typeof d=="string"&&fAe.test(d)}function CS(d){var e;const u=ohe(),i=d.toJSON();u.safeParse(i).success;const l=$S(d);return(e=d.dataType)==null||e.validate(),[...l,...Io(d)]}function $S(d){const u=[];if(!d.implements)return u;const i=d.implements;if(!i.abstract){const l=ft({id:`${d.id}--${le.PropertyImplementsNonAbstact}`,message:`Property "${ne(d,d.project)}" with id "${d.id}" implements a non-abstract property "${ne(i,d.project)}" with id "${i.id}".`,issue:null,severity:q.Error,code:le.PropertyImplementsNonAbstact,entity:d});u.push(l.error)}if(d.static&&!i.static){const l=ft({id:`${d.id}--${le.NonStaticPropertyImplementsStatic}`,message:`Static property "${ne(d,d.project)}" with id "${d.id}" implements a non-static property "${ne(i,d.project)}" with id "${i.id}".`,issue:null,severity:q.Error,code:le.NonStaticPropertyImplementsStatic,entity:d});u.push(l.error)}if(!d.static&&i.static){const l=ft({id:`${d.id}--${le.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${ne(d,d.project)}" with id "${d.id}" implements a static property "${ne(i,d.project)}" with id "${i.id}".`,issue:null,severity:q.Error,code:le.StaticPropertyImplementsNonStatic,entity:d});u.push(l.error)}if(!Ws(d.dataType,i.dataType)){const l=ft({id:`${d.id}--${le.PropertyImplementsIncompatibleType}`,message:`Property "${ne(d,d.project)}" with id "${d.id}" implements a property "${ne(i,d.project)}" with id "${i.id}" that has an incompatible data type.`,issue:null,severity:q.Error,code:le.PropertyImplementsIncompatibleType,entity:d});u.push(l.error)}return vr(d.errors,u)}const hAe=Object.freeze(Object.defineProperty({__proto__:null,validate:CS,validateImplementation:$S},Symbol.toStringTag,{value:"Module"}));function yAe(d,u){const i=[];if(d.parent){const l=u.get(d.parent);if(!l)i.push(new ee({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.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 p=wo(l);if(p){const e=l!==p?`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because the entity belongs to a built-in '${p.type}' entity with id '${p.id}' (${ne(p,l.project)}) higher up in the tree.`:`The entity of type '${d.type}' with id '${d.id}' have 'parent' with id '${d.parent}' because it is a built-in entity of type ${p.type}.`;i.push(new ee({id:`${d.id}--${k.InvalidBuiltInEntityReference}`,code:k.InvalidBuiltInEntityReference,severity:q.Error,message:e,issue:null}))}else if(![f.DefinitionEntity].includes(l.type))i.push(new ee({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const y=Ni(l).filter(v=>!v.interactive);if(y.length){let v=y.length>1?`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${at(y.map(E=>ne(E,E.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${l.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${ne(y[0],y[0].project)}").`;v+=`
403
403
  ${To}`,i.push(new ee({id:`${d.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:q.Error,message:v,issue:null}))}else if(d.implements){const v=u.get(d.implements);if(d.id===d.implements)return i.push(new ee({id:`${d.id}--${d.implements}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.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})),i;if(!v)i.push(new ee({id:`${d.id}--${d.implements}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.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 E=l.properties.find(w=>{var A;return((A=w.implements)==null?void 0:A.id)===d.implements});E?i.push(new ee({id:`${d.id}--${ae.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:ae.PropertyOverwritesOtherSiblingWithSameImplementation,severity:q.Error,message:`The property with id "${d.id}" is trying to implement the property with id "${d.implements}", but the parent entity already has a property with id '${E.id}' that implements the same base property.`,issue:null})):[f.Property].includes(v.type)?v.abstract||i.push(new ee({id:`${d.id}--${d.implements}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new ee({id:`${d.id}--${d.implements}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const a=ni(d,{},u);return i.push(...a.errors),i}function PS(d,u){var e;const i=[],a=[],l=[],p=[];if(((e=d.implements)==null?void 0:e.id)===Ee["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id){let y=d.defaultValue;if(!d.defaultValue){const v=Gi.new(u);v.name=Q.EntityTemplate,v.parent=d.toReference();const E=te(v,d.project);E.hydrateAncestors(),E.addSelfToProject(u),u==null||u.add(E,S.Added),a.push(E),E.initChildren(u),y=E}if(!y.valueAsTypeSingle){const v=TS(d.project);v&&y.setValueAsTypeSingle(v,u)}}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:d}}var NS=(d=>(d.PropertyImplements="property-implements",d.PropertyExtends="property-extends",d.DataTypeEntity="data-type-entity",d))(NS||{});const Ct=class Ct extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"private");g(this,"abstract");g(this,"index");g(this,"static");g(this,"required");g(this,"constant",!1);g(this,"interactive",!1);g(this,"type",f.Property);g(this,"hidden",!1);g(this,"defaultValue",null);g(this,"dataType",null);g(this,"implements",null);g(this,"extends",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestion",!1);g(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.abstract=i.abstract,this.index=i.index,this.static=i.static,this.required=i.required||!1,this.codeName=i.codeName,this.hidden=i.hidden||!1,this.constant=i.constant||!1,this.interactive=i.interactive||!1,this.onProjectInitialized=this.onProjectInitialized.bind(this)}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.Property,name:"",codeName:null,description:"",dataType:null,implements:null,extends:null,private:!1,abstract:!1,static:!1,constant:!1,interactive:!0,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(i,a){const l=Z(i.parent),p=a.get(l);let e=null;if(i.implements){const w=Z(i.implements);e=a.get(w)}let y=null;if(i.extends){const w=Z(i.extends);y=a.get(w)}const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.Property,index:p.properties.length,private:i.private||!1,abstract:i.abstract||!1,static:i.static||!1,required:i.required||!1,constant:i.constant||!1,interactive:i.interactive||!1,hidden:!1,codeName:i.codeName||null,description:i.description||null,defaultValue:null,implements:e,extends:y,dataType:null,parent:p},E=te(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=yAe(l,a),y=Jb(l,a);return p.push(...e,...y,...Br(l)),{errors:p,modifiedData:l}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(a=>{var l;return a.id===((l=this.extends)==null?void 0:l.id)});return!!i&&i.id!==this.id&&!i.abstract}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.implements)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.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.
404
404
  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})),(i.readsValue||i.writesValue)&&a.push(new ee({id:`${this.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
405
- ${ym}`,issue:null})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return PS(this,a),a==null||a.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.off(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.on(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ct(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ct(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=Z(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(i.extends){const l=Z(i.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' 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 e=Z(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.extends){const e=Z(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);a.push(...y),l.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:U}=PS(this,i);return a.push(...A),l.push(...$),p.push(...V),e.push(...U),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],e=[];return this.parent.addProperty(this),a.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=te(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=te(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=te(this.initialData.extends,this.project);this.setExtends(a,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.abstract=i.abstract!==void 0?i.abstract:p.abstract,this.private=i.private!==void 0?i.private:p.private,this.index=i.index||(i.index!==0?p.index:0),this.static=i.static!==void 0?i.static:p.static,this.hidden=i.hidden!==void 0?i.hidden:p.hidden,this.constant=i.constant!==void 0?i.constant:p.constant,this.interactive=i.interactive!==void 0?i.interactive:p.interactive,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Ct.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Ct.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Ct.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Ct.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Ct.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Ct.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.DefinitionEntity&&(this.parent.removeProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===f.DefinitionEntity&&(this.parent.addProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p,e;return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,extends:((e=this.extends)==null?void 0:e.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:(()=>{var A;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),extends:(()=>{var A;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,p,e,y,v;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:((y=this.implements)==null?void 0:y.toReference(i))||null,extends:((v=this.extends)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i,a;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:(i=this.implements)==null?void 0:i.id,extends:(a=this.extends)==null?void 0:a.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){return this.errors=CS(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),l=null){const p=l||N.UUID.uuid(),e=Ct.new(a);e.id=p,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.hidden=this.hidden,e.parent=i.toReference(),e.implements=this.toJSON();const y=te(e,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,U;let e=Fr(a,this);const y=l||N.UUID.uuid();let v=a||this.parent;const E={hidden:!1,id:y,version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,extends:this.extends,parent:v},w=or(E,e);p&&w.subscribe(),w.hydrateAncestors(),p&&w.addSelfToProject(i),w.setParent(v,null),w.initChildren(i),i==null||i.add(w,S.Added);const A=((V=this.dataType)==null?void 0:V.clone(i,w,N.UUID.uuid(),p))||null;A&&w.setDataType(A,i);const $=(U=this.defaultValue)==null?void 0:U.clone(i,w,N.UUID.uuid(),p);return w.setDefaultValue($||null,i),this.implements&&w.setImplements(this.implements,i),w.addSelfToProject(null),i==null||i.attemptAutoclose("clone-entity",this.id),w}setDataType(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],l=[],p=[],e=[];if(this.implements){const v=this.implements;if(!this.dataType&&v.dataType){const E=v.dataType.clone(i,this,N.UUID.uuid(),!0);this.setDataType(E,i),l.push(E)}if(this.implements.defaultValue&&!this.defaultValue){const E=(y=this.implements.defaultValue)==null?void 0:y.clone(i,this,N.UUID.uuid(),!0);this.setDefaultValue(E||null,i),l.push(E)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}};g(Ct,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),g(Ct,"type",f.Property),g(Ct,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),g(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),g(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","interactive"]),g(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"index"]),g(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),g(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),g(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),g(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let ea=Ct;function VS(d){const u=xye(),i=d.toJSON();u.safeParse(i).success;const l=d.implements.flatMap(w=>mAe(d,w)),p=d.extends.flatMap(w=>vAe(d,w)),e=TAe(d),y=EAe(d);d.methods.flatMap(w=>w.validate());const v=[...l,...p,...e,...y,...BS(d)];return vr(d.errors,v)}function LS(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let l=[...d.properties];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function MS(d,u){const i=u.abstractMethods,a=[];let l=[...d.methods];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function mAe(d,u){const i=[];if(!u.abstract){const w=ft({id:d.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),l=[];let p=[...d.properties];a.forEach(w=>{const A=p.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?p=p.filter($=>$.id!==A.id):l.push(w)}),l.length&&l.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingPropertyImplementation+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingPropertyImplementation,entity:d});i.push(A.error)});const e=[];let y=[...d.methods];u.abstractMethods.forEach(w=>{const A=y.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?y=y.filter($=>$.id!==A.id):e.push(w)}),e.length&&e.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingMethodImplementation+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingMethodImplementation,entity:d});i.push(A.error)});const v=[];u.properties.forEach(w=>{const A=p.find($=>$.name===w.name);A&&v.push([A,w])}),v.length&&v.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)});const E=[];return u.methods.forEach(w=>{const A=y.find($=>$.name===w.name);A&&E.push([A,w])}),E.length&&E.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function vAe(d,u){const i=[],a=[];if(!d.abstract&&u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}d.properties.forEach(p=>{var y;const e=u.properties.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&a.push(p)}),a.length&&a.forEach(p=>{const e=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const l=[];return d.methods.forEach(p=>{var y;const e=u.methods.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&l.push(p)}),l.length&&l.forEach(p=>{const e=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName,message:`Method "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function EAe(d){const u=[];if(!d.properties.length){const i=ft({id:d.id+"--"+le.NoProperties,message:"No properties implemented",issue:null,severity:q.Warning,code:le.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function TAe(d){const u=[];if(d.abstract){if(d.methods.length){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const l=ft({id:d.id+"--"+le.StaticEntityWithNonStaticProperties+"--"+a.id,message:`Property "${a.name}" with id "${a.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:q.Error,code:le.StaticEntityWithNonStaticProperties,entity:d});u.push(l.error)}})}}else{if(d.abstractMethods.length){const i=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});u.push(a.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const a=ft({id:d.id+"--"+le.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,issue:null,severity:q.Error,code:le.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function IAe(d,u){const i=[],a=Ni(u);if(!u.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(e)}const l=d.implements.filter(e=>e.id!==u.id);if(d.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(e)}if(d.static&&!u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(e)}if(!d.static&&u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(e)}return l.length&&l.forEach(e=>{if(e.type===f.BuiltInBaseEntity){const y=a.filter(v=>v.id!==e.id);y.length&&y.forEach(v=>{if(v.id!==e.id){const E=new lr({id:d.id+"--"+v.id+"--"+e.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(E)}})}else{Ni(e).forEach(w=>{const A=a.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});i.push(V)}})});const v=ja(u.ownDeclaredProperties,e.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const E=ja(u.abstractMethods,[...e.abstractMethods,...e.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...E.errors)}}),R(d.extends.flatMap(e=>Ni(e))).forEach(e=>{if(!a.find(y=>y.id===e.id)){const y=new lr({id:d.id+"--"+u.id+"--"+e.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${u.name}" with id "${u.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:e});i.push(y)}}),i}function AAe(d,u,i=!1){const a=[],l=Ni(u);if(!d.abstract&&u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.abstract&&!u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!d.static&&u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.static&&!u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!rf(u)){const w=ft({id:d.id+"--"+u.id+"--"+le.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(w.error)}const e=d.extends.filter(w=>w.id!==u.id);e.length&&e.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=ft({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${$.name}" with id "${$.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V.error)}})}else{Ni(w).forEach(J=>{const ie=l.filter(X=>X.id!==J.id);ie.length&&ie.forEach(X=>{if(X.id!==J.id){const ue=new lr({id:d.id+"--"+X.id+"--"+J.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${J.name}" with id "${J.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:J});a.push(ue)}})});const $=!!Ni(w).find(J=>J.id===u.id);let V=[...w.properties];$&&(V=V.filter(J=>!u.properties.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));let U=[...w.methods];$&&(U=U.filter(J=>!u.methods.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));const G=ja(u.ownDeclaredProperties,V,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...G.errors);const K=ja(u.abstractMethods,U,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...K.errors)}}),i&&Me.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V)}})}else{Ni(w).forEach(U=>{const G=l.filter(K=>K.id!==U.id);G.length&&G.forEach(K=>{if(K.id!==U.id){const J=new lr({id:d.id+"--"+K.id+"--"+U.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${U.name}" with id "${U.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:U});a.push(J)}})});const $=ja(u.ownDeclaredProperties,w.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...$.errors);const V=ja(u.abstractMethods,[...w.abstractMethods,...w.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...V.errors)}});const y=ja(d.ownDeclaredProperties,u.ownDeclaredProperties,ae.PropertyOverwritesOtherSiblingWithSameImplementation,ae.PropertyOverwritesOtherSiblingWithSameName);a.push(...y.errors);const v=ja(u.methods,u.abstractMethods,ae.MethodOverwritesOtherSiblingWithSameImplementation,ae.MethodOverwritesOtherSiblingWithSameName);return a.push(...v.errors),R(d.extends.flatMap(w=>Ni(w))).forEach(w=>{if(!l.find(A=>A.id===w.id)){const A=new lr({id:d.id+"--"+u.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:w});a.push(A)}}),a}function bAe(d){const u=[];return d.implements.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function wAe(d){const u=[];if(d.implements.length){const i=new lr({id:d.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d});u.push(i)}return d.extends.forEach(i=>{if(!i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${i.name}" with id "${i.id}" which is non-abstract`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function RAe(d){const u=[];return d.extends.forEach(i=>{if(i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${i.name}" with id "${i.id}" which is static`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function _Ae(d){const u=[];return d.extends.forEach(i=>{if(i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${i.name}" with id "${i.id}" which is abstract`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function BS(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,issue:null,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const l=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!l.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,issue:null,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!l.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,issue:null,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,issue:null,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const w=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(w)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,issue:null,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const gAe=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:MS,getBasePropertiesNotImplemented:LS,validate:VS,validateCanBecomeAbstract:wAe,validateCanBecomeNonAbstract:_Ae,validateCanBecomeNonStatic:RAe,validateCanBecomeStatic:bAe,validateCanExtendEntity:AAe,validateCanImplementEntity:IAe,validateDefinitionEntityName:BS},Symbol.toStringTag,{value:"Module"}));function DAe(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new ee({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new ee({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):i.push(new ee({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new ee({id:`${d.id}--${a}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.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 l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):i.push(new ee({id:`${d.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`,issue:null})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.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})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),i}var Um=(d=>(d.Extends="extends",d.Implements="implements",d))(Um||{});const qt=class qt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"x");g(this,"y");g(this,"static");g(this,"abstract");g(this,"type",f.DefinitionEntity);g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"implements",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestedProperties",[]);g(this,"suggestedMethods",[]);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DefinitionEntity,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const E=Z(i.parent);l=a.get(E)}const p=[];i.implements&&i.implements.forEach(E=>{p.push(a.get(E)||a.getBuiltIn(E))});const e=[];i.extends&&i.extends.forEach(E=>{e.push(a.get(E)||a.getBuiltIn(E))});const y={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,properties:[],methods:[],abstractMethods:[],extends:e,implements:p,x:0,y:0,parent:l},v=te(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=DAe(l,a),y=Kb(l,a);p.push(...e,...y,...Br(l));const v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DataType){const E=v;E.entity&&p.push(new ee({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:q.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${E.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
405
+ ${ym}`,issue:null})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return PS(this,a),a==null||a.attemptAutoclose("on-property-received-project-initialized",this.id),this}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.remove({ignoreUpstream:!1},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,l),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.restore({},l);p.push(...E),e.push(...w),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.unsubscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.off(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,l,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(l=this.extends)==null?void 0:l.subscribeDependents)==null||p.call(l,[{entity:this,field:"property-extends"}]),(v=(y=(e=this.dataType)==null?void 0:e.entity)==null?void 0:y.subscribeDependents)==null||v.call(y,[{entity:this,field:"data-type-entity"}]),this.project.on(Vr.PROJECT_INITIALIZED,this.onProjectInitialized),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Ct(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.implements=this.implements,i.extends=this.extends,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent&&this.parent.type!==f.PrimitiveEntity&&this.parent.type!==f.BuiltInBaseEntity){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Ct(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,null);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=Z(i.implements),p=this.project.get(l);if(p)this.setImplements(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}if(i.extends){const l=Z(i.extends),p=this.project.get(l);if(p)this.setExtends(p,a);else if(l)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${l}" which is missing in the project`)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' 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 e=Z(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.extends){const e=Z(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Ti(this.type)} with id '${this.id}' has a 'extends' reference "${e}" which is missing in the project`)}return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);a.push(...y),l.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:U}=PS(this,i);return a.push(...A),l.push(...$),p.push(...V),e.push(...U),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],e=[];return this.parent.addProperty(this),a.push(this.parent),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}setImplements(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var l;return((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-implements",this.id),this}setExtends(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var l;return((l=this.extends)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=te(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=te(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=te(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=te(this.initialData.extends,this.project);this.setExtends(a,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.abstract=i.abstract!==void 0?i.abstract:p.abstract,this.private=i.private!==void 0?i.private:p.private,this.index=i.index||(i.index!==0?p.index:0),this.static=i.static!==void 0?i.static:p.static,this.hidden=i.hidden!==void 0?i.hidden:p.hidden,this.constant=i.constant!==void 0?i.constant:p.constant,this.interactive=i.interactive!==void 0?i.interactive:p.interactive,this.required=i.required!==void 0?i.required:p.required,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Ct.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Ct.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Ct.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Ct.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Ct.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await Ct.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];return this.parent.type===f.DefinitionEntity&&(this.parent.removeProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},a);l.push(...v),p.push(...E)}if(!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];if(i!=null&&i.hasAdded(this.id))return i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);l.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);l.push(...y)}return this.parent.type===f.DefinitionEntity&&(this.parent.addProperty(this),e.push(this.parent)),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((l=this.defaultValue)==null?void 0:l.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((l=this.defaultValue)==null?void 0:l.toFlatIds(i))||[],...((p=this.dataType)==null?void 0:p.toFlatIds(i))||[],...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,interactive:this.interactive,static:this.static,type:this.type,name:this.name}}toJSON(i=new Set){var a,l,p,e;return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((l=this.dataType)==null?void 0:l.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,extends:((e=this.extends)==null?void 0:e.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v,E,w;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,interactive:this.interactive,abstract:this.abstract,hidden:this.hidden,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,dataType:((w=this.dataType)==null?void 0:w.toJSONClone({...i,newId:null}))||null,implements:(()=>{var A;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),extends:(()=>{var A;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():((A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l,p,e,y,v;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,interactive:this.interactive,hidden:this.hidden,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,dataType:((e=this.dataType)==null?void 0:e.toReference(i))||null,implements:((y=this.implements)==null?void 0:y.toReference(i))||null,extends:((v=this.extends)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var l,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((l=this.defaultValue)==null?void 0:l.toFlatJSON(i))||[],...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[],...((e=this.implements)==null?void 0:e.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var i,a;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:(i=this.implements)==null?void 0:i.id,extends:(a=this.extends)==null?void 0:a.id,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var l,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((l=this.defaultValue)==null?void 0:l.toFlatGenerationTarget(i))||[],...((p=this.dataType)==null?void 0:p.toFlatGenerationTarget(i))||[]])}clearErrors(){var i,a;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),(a=this.dataType)==null||a.clearErrors(),this}validate(){return this.errors=CS(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var a,l;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((l=this.dataType)==null?void 0:l.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),l=null){const p=l||N.UUID.uuid(),e=Ct.new(a);e.id=p,e.name=this.name,e.description=this.description,e.index=this.index,e.private=this.private,e.required=this.required,e.static=this.static,e.constant=this.constant,e.hidden=this.hidden,e.interactive=this.interactive,e.parent=i.toReference(),e.implements=this.toJSON();const y=te(e,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var V,U;let e=Fr(a,this);const y=l||N.UUID.uuid();let v=a||this.parent;const E={hidden:!1,id:y,version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,index:this.index,private:this.private,constant:this.constant,interactive:this.interactive,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,extends:this.extends,parent:v},w=or(E,e);p&&w.subscribe(),w.hydrateAncestors(),p&&w.addSelfToProject(i),w.setParent(v,null),w.initChildren(i),i==null||i.add(w,S.Added);const A=((V=this.dataType)==null?void 0:V.clone(i,w,N.UUID.uuid(),p))||null;A&&w.setDataType(A,i);const $=(U=this.defaultValue)==null?void 0:U.clone(i,w,N.UUID.uuid(),p);return w.setDefaultValue($||null,i),this.implements&&w.setImplements(this.implements,i),w.addSelfToProject(null),i==null||i.attemptAutoclose("clone-entity",this.id),w}setDataType(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const l=this.dataType;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.dataType=i,this.subscribeToDependencies(),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-data-type",this.id),this}removeDataType(){return this.dataType=null,this}getDataType(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return i==null||i.attemptAutoclose("get-data-type",this.id),this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const l=this.defaultValue;return(l==null?void 0:l.id)!==(i==null?void 0:i.id)&&(l==null||l.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}syncWithImplementation(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],l=[],p=[],e=[];if(this.implements){const v=this.implements;if(!this.dataType&&v.dataType){const E=v.dataType.clone(i,this,N.UUID.uuid(),!0);this.setDataType(E,i),l.push(E)}if(this.implements.defaultValue&&!this.defaultValue){const E=(y=this.implements.defaultValue)==null?void 0:y.clone(i,this,N.UUID.uuid(),!0);this.setDefaultValue(E||null,i),l.push(E)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}};g(Ct,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),g(Ct,"type",f.Property),g(Ct,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),g(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),g(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","interactive"]),g(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"index"]),g(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),g(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),g(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),g(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),g(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let ea=Ct;function VS(d){const u=xye(),i=d.toJSON();u.safeParse(i).success;const l=d.implements.flatMap(w=>mAe(d,w)),p=d.extends.flatMap(w=>vAe(d,w)),e=TAe(d),y=EAe(d);d.methods.flatMap(w=>w.validate());const v=[...l,...p,...e,...y,...BS(d)];return vr(d.errors,v)}function LS(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let l=[...d.properties];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function MS(d,u){const i=u.abstractMethods,a=[];let l=[...d.methods];return i.forEach(p=>{const e=l.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?l=l.filter(y=>y.id!==e.id):a.push(p)}),a}function mAe(d,u){const i=[];if(!u.abstract){const w=ft({id:d.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),l=[];let p=[...d.properties];a.forEach(w=>{const A=p.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?p=p.filter($=>$.id!==A.id):l.push(w)}),l.length&&l.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingPropertyImplementation+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingPropertyImplementation,entity:d});i.push(A.error)});const e=[];let y=[...d.methods];u.abstractMethods.forEach(w=>{const A=y.find($=>{var V;return((V=$.implements)==null?void 0:V.id)===w.id});A?y=y.filter($=>$.id!==A.id):e.push(w)}),e.length&&e.forEach(w=>{const A=ft({id:d.id+"--"+le.MissingMethodImplementation+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${u.name}" with id "${u.id}" is not implemented when entity "${d.name}" with id "${d.id}" implements it`,issue:null,severity:q.Error,code:le.MissingMethodImplementation,entity:d});i.push(A.error)});const v=[];u.properties.forEach(w=>{const A=p.find($=>$.name===w.name);A&&v.push([A,w])}),v.length&&v.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Property "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)});const E=[];return u.methods.forEach(w=>{const A=y.find($=>$.name===w.name);A&&E.push([A,w])}),E.length&&E.forEach(([w])=>{const A=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName+"--"+w.id,message:`Method "${w.name}" with id "${w.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the base entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function vAe(d,u){const i=[],a=[];if(!d.abstract&&u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}d.properties.forEach(p=>{var y;const e=u.properties.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&a.push(p)}),a.length&&a.forEach(p=>{const e=ft({id:d.id+"--"+ae.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the property with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const l=[];return d.methods.forEach(p=>{var y;const e=u.methods.find(v=>{var E;return v.name===p.name&&((E=p.extends)==null?void 0:E.id)!==v.id});((y=p.implements)==null?void 0:y.id)!==(e==null?void 0:e.id)&&e&&l.push(p)}),l.length&&l.forEach(p=>{const e=ft({id:d.id+"--"+ae.MethodOverwritesOtherSiblingWithSameName,message:`Method "${p.name}" with id "${p.id}" of entity "${d.name}" with id "${d.id}" overwrites the method with the same name from the extended entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function EAe(d){const u=[];if(!d.properties.length){const i=ft({id:d.id+"--"+le.NoProperties,message:"No properties implemented",issue:null,severity:q.Warning,code:le.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function TAe(d){const u=[];if(d.abstract){if(d.methods.length){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=ft({id:d.id+"--"+le.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:q.Error,code:le.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const l=ft({id:d.id+"--"+le.StaticEntityWithNonStaticProperties+"--"+a.id,message:`Property "${a.name}" with id "${a.id}" of entity "${d.name}" with id "${d.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:q.Error,code:le.StaticEntityWithNonStaticProperties,entity:d});u.push(l.error)}})}}else{if(d.abstractMethods.length){const i=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=ft({id:d.id+"--"+le.AbstractPropertyInNonAbstractEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:q.Error,code:le.AbstractPropertyInNonAbstractEntity,entity:d,firstRelationship:i});u.push(a.error)}})}return d.static&&d.properties.some(i=>!i.static)&&d.properties.forEach(i=>{if(!i.static){const a=ft({id:d.id+"--"+le.NonStaticPropertyInStaticEntity+"--"+i.id,message:`Property "${i.name}" with id "${i.id}" of entity "${d.name}" with id "${d.id}" is not marked as static but the entity is marked as static`,issue:null,severity:q.Error,code:le.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function IAe(d,u){const i=[],a=Ni(u);if(!u.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(e)}const l=d.implements.filter(e=>e.id!==u.id);if(d.abstract){const e=new lr({id:d.id+"--"+u.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract and cannot implement built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(e)}if(d.static&&!u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is marked as static and cannot implement non-static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(e)}if(!d.static&&u.static){const e=new lr({id:d.id+"--"+u.id+"--"+le.NonStaticImplementingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as static and cannot implement static built-in entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(e)}return l.length&&l.forEach(e=>{if(e.type===f.BuiltInBaseEntity){const y=a.filter(v=>v.id!==e.id);y.length&&y.forEach(v=>{if(v.id!==e.id){const E=new lr({id:d.id+"--"+v.id+"--"+e.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${v.name}" with id "${v.id}" but also implements entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(E)}})}else{Ni(e).forEach(w=>{const A=a.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});i.push(V)}})});const v=ja(u.ownDeclaredProperties,e.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const E=ja(u.abstractMethods,[...e.abstractMethods,...e.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...E.errors)}}),R(d.extends.flatMap(e=>Ni(e))).forEach(e=>{if(!a.find(y=>y.id===e.id)){const y=new lr({id:d.id+"--"+u.id+"--"+e.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${u.name}" with id "${u.id}" but also extends entity "${e.name}" with id "${e.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:e});i.push(y)}}),i}function AAe(d,u,i=!1){const a=[],l=Ni(u);if(!d.abstract&&u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.abstract&&!u.abstract){const w=ft({id:d.id+"--"+u.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!d.static&&u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(d.static&&!u.static){const w=ft({id:d.id+"--"+u.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(w.error)}if(!rf(u)){const w=ft({id:d.id+"--"+u.id+"--"+le.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,issue:null,severity:q.Error,code:le.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(w.error)}const e=d.extends.filter(w=>w.id!==u.id);e.length&&e.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=ft({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${$.name}" with id "${$.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ExtendsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V.error)}})}else{Ni(w).forEach(J=>{const ie=l.filter(X=>X.id!==J.id);ie.length&&ie.forEach(X=>{if(X.id!==J.id){const ue=new lr({id:d.id+"--"+X.id+"--"+J.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${X.name}" with id "${X.id}" but also extends or implements entity "${J.name}" with id "${J.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:X,secondRelationship:J});a.push(ue)}})});const $=!!Ni(w).find(J=>J.id===u.id);let V=[...w.properties];$&&(V=V.filter(J=>!u.properties.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));let U=[...w.methods];$&&(U=U.filter(J=>!u.methods.find(ie=>{var X;return ie.id===J.id||ie.name===J.name||ie.id===((X=J.implements)==null?void 0:X.id)})));const G=ja(u.ownDeclaredProperties,V,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...G.errors);const K=ja(u.abstractMethods,U,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...K.errors)}}),i&&Me.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(w=>{if(w.type===f.BuiltInBaseEntity){const A=l.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new lr({id:d.id+"--"+$.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${$.name}" with id "${$.id}" but also implements entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});a.push(V)}})}else{Ni(w).forEach(U=>{const G=l.filter(K=>K.id!==U.id);G.length&&G.forEach(K=>{if(K.id!==U.id){const J=new lr({id:d.id+"--"+K.id+"--"+U.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${K.name}" with id "${K.id}" but also implements entity "${U.name}" with id "${U.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:K,secondRelationship:U});a.push(J)}})});const $=ja(u.ownDeclaredProperties,w.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...$.errors);const V=ja(u.abstractMethods,[...w.abstractMethods,...w.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...V.errors)}});const y=ja(d.ownDeclaredProperties,u.ownDeclaredProperties,ae.PropertyOverwritesOtherSiblingWithSameImplementation,ae.PropertyOverwritesOtherSiblingWithSameName);a.push(...y.errors);const v=ja(u.methods,u.abstractMethods,ae.MethodOverwritesOtherSiblingWithSameImplementation,ae.MethodOverwritesOtherSiblingWithSameName);return a.push(...v.errors),R(d.extends.flatMap(w=>Ni(w))).forEach(w=>{if(!l.find(A=>A.id===w.id)){const A=new lr({id:d.id+"--"+u.id+"--"+w.id+"--"+le.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${w.name}" with id "${w.id}" which is incompatible`,issue:null,severity:q.Error,code:le.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:w});a.push(A)}}),a}function bAe(d){const u=[];return d.implements.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends.forEach(i=>{if(!i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${i.name}" with id "${i.id}" which is non-static`,issue:null,severity:q.Error,code:le.StaticExtendingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function wAe(d){const u=[];if(d.implements.length){const i=new lr({id:d.id+"--"+le.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:q.Error,code:le.AbstractEntityImplements,entity:d});u.push(i)}return d.extends.forEach(i=>{if(!i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${i.name}" with id "${i.id}" which is non-abstract`,issue:null,severity:q.Error,code:le.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function RAe(d){const u=[];return d.extends.forEach(i=>{if(i.static){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${i.name}" with id "${i.id}" which is static`,issue:null,severity:q.Error,code:le.NonStaticExtendingStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function _Ae(d){const u=[];return d.extends.forEach(i=>{if(i.abstract){const a=new lr({id:d.id+"--"+i.id+"--"+le.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${i.name}" with id "${i.id}" which is abstract`,issue:null,severity:q.Error,code:le.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:i});u.push(a)}}),u}function BS(d){const u=[],i=d.name;if(!i){const $=ft({id:`${d.id}--${ae.EmptyName}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,issue:null,severity:q.Error,code:ae.EmptyName,entity:d});return u.push($.error),u}const l=[...d.project.functions,...d.project.entities.flatMap($=>$.methods)].filter($=>$.id!==d.id),p=i.trim(),e=!l.some($=>$.name===i||$.name===p);if(!e){const $=ft({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name. Entities of type ${d.type} must have valid names among all other entities of its type.`,issue:null,severity:q.Error,code:ae.NameNotUniqueInScope,entity:d});u.push($.error)}const y=jr(i);if(!!l.some($=>jr($.name)===y)&&e){const $=ft({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${y}". Entities of type ${d.type} must have valid names including their code name form.`,issue:null,severity:q.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});u.push($.error)}if(!/^[a-zA-Z_]/.test(i)){const $=ft({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,issue:null,severity:q.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});u.push($.error)}const w=i.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(w)){const $=ft({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Definition entity "${ne(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,issue:null,severity:q.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});u.push($.error)}return u}const gAe=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:MS,getBasePropertiesNotImplemented:LS,validate:VS,validateCanBecomeAbstract:wAe,validateCanBecomeNonAbstract:_Ae,validateCanBecomeNonStatic:RAe,validateCanBecomeStatic:bAe,validateCanExtendEntity:AAe,validateCanImplementEntity:IAe,validateDefinitionEntityName:BS},Symbol.toStringTag,{value:"Module"}));function DAe(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new ee({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new ee({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):i.push(new ee({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new ee({id:`${d.id}--${a}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.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 l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract||i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):i.push(new ee({id:`${d.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`,issue:null})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const l=u.get(a);l?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(l.type)?l.abstract&&i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.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})):i.push(new ee({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):i.push(new ee({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${a}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),i}var Um=(d=>(d.Extends="extends",d.Implements="implements",d))(Um||{});const qt=class qt extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"codeName",null);g(this,"description",null);g(this,"x");g(this,"y");g(this,"static");g(this,"abstract");g(this,"type",f.DefinitionEntity);g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"implements",[]);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"suggestedProperties",[]);g(this,"suggestedMethods",[]);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.static=i.static,this.abstract=i.abstract}static new(i=null){return{id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DefinitionEntity,name:"",codeName:null,description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let l=a;if(i.parent){const E=Z(i.parent);l=a.get(E)}const p=[];i.implements&&i.implements.forEach(E=>{p.push(a.get(E)||a.getBuiltIn(E))});const e=[];i.extends&&i.extends.forEach(E=>{e.push(a.get(E)||a.getBuiltIn(E))});const y={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,type:f.DefinitionEntity,codeName:i.codeName||null,description:i.description,static:i.static,abstract:i.abstract,properties:[],methods:[],abstractMethods:[],extends:e,implements:p,x:0,y:0,parent:l},v=te(y,a);return v.setParent(l,null),v}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[],e=DAe(l,a),y=Kb(l,a);p.push(...e,...y,...Br(l));const v=l.parent?a.get(l.parent):null;if(v&&v.type===f.DataType){const E=v;E.entity&&p.push(new ee({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:q.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${E.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
  ${Xn({describe_entity:E.entity.id})}
408
408
  Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:p,modifiedData:l}}get interactive(){return this.implements.length?this.implements.every(i=>i.interactive):!0}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[]),...this.implements.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[]),...this.implements.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R([...this.extends.reduce((i,a)=>[...[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract),...i],[]),...this.implements.reduce((i,a)=>[...[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract),...i],[])])}get allBaseMethodsFromExtendedAndImplementedEntities(){return R([...this.extends.reduce((i,a)=>a.type!==f.DefinitionEntity?[]:[...[...a.ownDeclaredMethods,...a.allBaseMethodsFromExtendedAndImplementedEntities].filter(p=>p.type!==f.ActionDescriptor),...i],[]),...this.implements.reduce((i,a)=>a.type!==f.DefinitionEntity?a.abstractMethods:[...[...a.ownDeclaredMethods,...a.allBaseMethodsFromExtendedAndImplementedEntities].filter(p=>p.type!==f.ActionDescriptor),...i],[])])}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[]),...this.implements.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return R(this.extends.reduce((i,a)=>{if(a.type!==f.DefinitionEntity)return[];const l=[...a.ownDeclaredMethods,...a.extendedMethodsFromOriginalParents].filter(p=>p.type!==f.ActionDescriptor);return[...i,...l]},[]))}get implementedMethodsFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.type===f.DefinitionEntity?a.methods:[],p=[...a.abstractMethods].filter(e=>!l.find(y=>y.name===e.name));return[...l,...p,...i]},[]),...this.implements.reduce((i,a)=>[...a.abstractMethods,...i],[])].filter(i=>i.type===f.ActionDescriptor))}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}get extendedMethods(){return this.methods.filter(i=>i.isExtendedMethod)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ee({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.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:a,modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];return a==="implements"&&this.removeImplementation(i),a==="extends"&&this.removeExtension(i),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];return a==="implements"&&this.addImplementation(i),a==="extends"&&this.addExtension(i),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{ls.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(i=>{ls.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(i=>{ls.includes(i.type)||i.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=N.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new qt(this,this.project);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.properties=[...this.properties],i.methods=[...this.methods],i.abstractMethods=[...this.abstractMethods],i.extends=[...this.extends],i.implements=[...this.implements],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new qt(E,this.project)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.properties=y.properties,this.methods=y.methods,this.abstractMethods=y.abstractMethods,this.extends=y.extends,this.implements=y.implements,this.parent=y.parent,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=Z(i.parent),p=this.project.get(l),e=this.parent;if(e&&e.id!==(p==null?void 0:p.id)&&this.removeFromParent(a),p)this.setParent(p,a);else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return i.extends.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&this.addExtension(e)}),i.implements.forEach(l=>{const p=Z(l),e=this.project.get(p);e&&this.addImplementation(e)}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];if(this.initialData.parent){const e=Z(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${e}' 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(e=>{const y=Z(e),v=this.project.get(y);v&&(this.addExtension(v),v.type!==f.BuiltInBaseEntity&&i.push(v))}),this.initialData.implements.forEach(e=>{const y=Z(e),v=this.project.get(y);v&&(this.addImplementation(v),v.type!==f.BuiltInBaseEntity&&i.push(v))}),{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],l=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncImplementationProperties(i);a.push(...y),l.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:U}=this.addExtendedProperties(i);a.push(...A),l.push(...$),p.push(...V),e.push(...U);const{updated:G,added:K,removed:J}=this.removeUnrecognizedProperties(i);a.push(...G),l.push(...K),p.push(...J);const{updated:ie,added:X,removed:ue,affected:re}=this.syncImplementationMethods(i);a.push(...ie),l.push(...X),p.push(...ue),e.push(...re);const{updated:fe,added:Y,removed:H,affected:ce}=this.addExtendedMethods(i);a.push(...fe),l.push(...Y),p.push(...H),e.push(...ce);const{updated:z,added:oe,removed:we}=this.removeUnrecognizedMethods(i);return a.push(...z),l.push(...oe),p.push(...we),this.addSuggestions(),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],p=[],e=[];if(this.parent.type===f.DataType){const y=this.parent;y.entity=this,a.push(y)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var l;return((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-parent",this.id),this}addExtension(i){return this.extends.includes(i)||this.extends.push(i),this}removeExtension(i){return this.extends=this.extends.filter(a=>a.id!==i.id),this}addImplementation(i){return this.implements.includes(i)||this.implements.push(i),this}removeImplementation(i){return this.implements=this.implements.filter(a=>a.id!==i.id),this}removeProperty(i){return this.properties=this.properties.filter(a=>a.id!==i.id),this}addMethod(i){return this.methods.includes(i)||(this.methods.push(i),this.suggestedMethods=this.suggestedMethods.filter(a=>a.name!==i.name)),this}removeMethod(i){return this.methods=this.methods.filter(a=>a.id!==i.id),this}addProperty(i){return this.properties.includes(i)||(this.properties.push(i),this.suggestedProperties=this.suggestedProperties.filter(a=>a.name!==i.name)),this}addSuggestedProperty(i){return this.suggestedProperties.includes(i)||this.suggestedProperties.push(i),this}addSuggestedMethod(i){return this.suggestedMethods.includes(i)||this.suggestedMethods.push(i),this}removeSuggestedProperty(i){return this.suggestedProperties=this.suggestedProperties.filter(a=>a.id!==i.id),this}removeSuggestedMethod(i){return this.suggestedMethods=this.suggestedMethods.filter(a=>a.id!==i.id),this}addAbstractMethod(i){return this.abstractMethods.includes(i)||this.abstractMethods.push(i),this}removeAbstractMethod(i){return this.abstractMethods=this.abstractMethods.filter(a=>a.id!==i.id),this}initChildren(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.methods=this.initialData.methods.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const l=te(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.extends=this.initialData.extends.map(a=>te(a,this.project)),this.implements=this.initialData.implements.map(a=>te(a,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-properties"))){const a=[],l=[],p=[],e=[];let y=[...this.properties];y=y.filter(E=>E.parent.id===this.id),y=y.filter(E=>!E.isExtendedProperty);const v=this.implementedPropertiesFromOriginalParents;return y=y.filter(E=>this.interactive&&!E.implements?!1:!v.find(w=>{var A;return w.id===((A=E.implements)==null?void 0:A.id)})),y.forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-methods"))){const a=[],l=[],p=[],e=[];let y=[...this.methods];y=y.filter(E=>E.parent.id===this.id),y=y.filter(E=>!E.isExtendedMethod);const v=this.implementedMethodsFromOriginalParents;return y=y.filter(E=>this.interactive&&!E.implements?!1:!v.find(w=>{var A;return w.id===((A=E.implements)==null?void 0:A.id)})),y.forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-methods"))){const a=[],l=[],p=[],e=[],y=this.methods,v=this.implementedMethodsFromOriginalParents,E=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return v.filter(A=>!E.find(V=>{var U;return((U=V.implements)==null?void 0:U.id)===A.id})).forEach(A=>{if(this.methods.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===A.id}))return;const V=this.methods.find(G=>{var ue,re;if(G.name===A.name&&!G.implements)return!0;const K=Es(this,Ue.CRON_JOB),J=Es(this,Ue.HTTP_ENDPOINT),ie=((ue=G.implements)==null?void 0:ue.id)===Ee["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,X=((re=G.implements)==null?void 0:re.id)===Ee["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(K&&!X&&!J&&ie||J&&!ie&&!K&&X)});if(V&&V.type===f.FunctionDeclaration){V.setImplements(A,i),V.metaSync({name:A.name},i),i==null||i.add(V,S.Updated),i==null||i.add(this,S.Updated);return}this.id==="new-endpoint-test-id-1234"&&console.log("Creating new method for",A.name);const U=A.implementAsFunctionDeclaration(i,this);l.push(U),i==null||i.add(U,S.Added),this.addMethod(U)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-properties"))){const a=[],l=[],p=[],e=[],y=this.properties,v=this.implementedPropertiesFromOriginalParents,E=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return v.filter(A=>!E.find(V=>{var U;return((U=V.implements)==null?void 0:U.id)===A.id})).forEach(A=>{if(this.properties.find(G=>{var K;return((K=G.implements)==null?void 0:K.id)===A.id}))return;const V=this.properties.find(G=>G.name===A.name&&!!G.abstract&&!G.implements);if(V){V.setImplements(A,i),V.metaSync({abstract:!1},i),V.afterAllChildrenInitialized(i);return}const U=A.implement(this,i,N.UUID.uuid());l.push(U),i==null||i.add(U,S.Added)}),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-extended-methods"))){const a=[],l=[],p=[],e=[],y=this.methods,E=this.extendedMethodsFromOriginalParents.filter(A=>A.type===f.FunctionDeclaration),w=new Set(y.filter(A=>{var $;return!!(($=A.extends)!=null&&$.id)}).map(A=>A.extends.id));return E.forEach(A=>{if(w.has(A.id))return;w.add(A.id);const $=A.clone(i,this,N.UUID.uuid());$.setExtends(A,i),$.initChildren(i),l.push($),i==null||i.add($,S.Added),this.addMethod($)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-extended-properties"))){const a=[],l=[],p=[],e=[],y=this.properties,v=this.extendedPropertiesFromOriginalParents,E=v.filter(A=>v.find(V=>{var U;return((U=V.implements)==null?void 0:U.id)===A.id})?!1:!A.abstract),w=new Set(y.filter(A=>{var $;return!!(($=A.extends)!=null&&$.id)}).map(A=>A.extends.id));return E.forEach(A=>{if(w.has(A.id))return;w.add(A.id);const $=A.clone(i,this,N.UUID.uuid());$.setExtends(A,i),$.initChildren(i),l.push($),i==null||i.add($,S.Added),this.addProperty($)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{LS(this,i).forEach(p=>{const e=p.toJSON();e.id=`_suggestion--parent--${this.id}--${p.id}`;const y=te(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),MS(this,i).forEach(p=>{const e=`_suggestion--parent--${this.id}--${p.id}`,y=p.implementAsFunctionDeclaration(null,this,e),v=te(y,this.project);if(v.suggestion=!0,v.setParent(this,null),v.initChildren(null),this.methods=this.methods.filter(E=>E.id!==e),v.inputs.forEach(E=>{E.suggestion=!0}),v.returnStatements.length){const E=v.returnStatements[0];E.suggestion=!0,E.outputs.forEach(w=>{w.suggestion=!0})}this.addSuggestedMethod(v)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.codeName=i.codeName!==void 0?i.codeName:p.codeName,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,this.static=i.static!==void 0?i.static:this.static,this.abstract=i.abstract!==void 0?i.abstract:this.abstract,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await qt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await qt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await qt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await qt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await qt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await qt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],l=[],p=[],e=[];if(this.parent.type===f.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===f.DataType&&this.parent.entity&&this.parent.entity.id===this.id){const y=this.parent.setEntity(null,i);a.push(y)}return i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(l),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const l=[],p=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(p.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(v=>{const{updated:E,removed:w,added:A}=v.entity.onDetachedDependencyRemoved(this,v.field,a);l.push(...E),p.push(...w),e.push(...A)}),this.properties.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.methods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.abstractMethods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.suggestedProperties.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),this.suggestedMethods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);l.push(...E),p.push(...w)}),!i){const v=this.removeFromParent(a);e.push(...v.added),l.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(l),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],l=[],p=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},i),Object.values(this.detachedDependents).forEach(y=>{const{updated:v,removed:E,added:w}=y.entity.onDetachedDependencyRestored(this,y.field,i);l.push(...v),p.push(...E),a.push(...w)}),this.properties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.methods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.abstractMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedProperties.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),this.suggestedMethods.forEach(y=>{const{updated:v}=y.restore({},i);l.push(...v)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(l),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.extends.flatMap(l=>l.toFlat(i)),...this.implements.flatMap(l=>l.toFlat(i)),...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.extends.flatMap(l=>l.toFlatIds(i)),...this.implements.flatMap(l=>l.toFlatIds(i)),...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i)),...this.parent.toFlatIds(i)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,codeName:this.codeName,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){return i.has(this.id)?this.toReference():(i.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,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),implements:this.implements.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var l,p,e,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||Gr(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(p=i.seenEntities)!=null&&p.has(a)||(e=i.seenEntities)!=null&&e.has(this.id)?this.toReference({seenEntityMaps:i.seenEntityMaps}):((y=i.seenEntities)==null||y.add(a),(v=i.seenEntities)==null||v.add(this.id),{id:a,version:N.UUID.uuid(),createdAt:i.timestamp||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,codeName:this.codeName,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(E=>E.toJSONClone({...i,newId:null})),methods:this.methods.map(E=>E.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map(E=>E.toJSONClone({...i,newId:null})),implements:this.implements.map(E=>E.type===f.BuiltInBaseEntity?E.toJSON():E.toJSONClone({...i,newId:null})),extends:this.extends.map(E=>E.type===f.BuiltInBaseEntity?E.toJSON():E.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,codeName:this.codeName,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(p=>p.toReference(i)),methods:this.methods.map(p=>p.toReference(i)),abstractMethods:this.abstractMethods.map(p=>p.toReference(i)),implements:this.implements.map(p=>p.toReference(i)),extends:this.extends.map(p=>p.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i)),...this.implements.flatMap(l=>l.toFlatJSON(i)),...this.extends.flatMap(l=>l.toFlatJSON(i)),...this.parent.toFlatJSON(i)])}toGenerationTarget(){const i=this.parent.type===f.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(a=>a.id),implements:this.implements.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.implements.filter(l=>l.type===f.DefinitionEntity).flatMap(l=>l.toFlatGenerationTarget(i)),...this.implements.filter(l=>l.type===f.DefinitionEntity).flatMap(l=>l.toFlatGenerationTarget(i)),...this.parent.toFlatGenerationTarget(i)])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){return this.errors=VS(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,l=null,p=!0){var G,K,J;let e=Fr(a,this);const y=this.toJSON(),v=l||N.UUID.uuid();y.properties=[],y.methods=[],y.abstractMethods=[];const E=v.split("-id"),w=E[E.length-1||0]||v;y.id=v,y.version=N.UUID.uuid(),y.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),y.author=(i==null?void 0:i.author)||"1",y.previousVersion=null,y.deleted=!1;const A=or(y,e);a&&A.setParent(a,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(G=this.properties)==null?void 0:G.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.properties=$;const V=(K=this.methods)==null?void 0:K.map((ie,X)=>ie.clone(i,A,w+"-method-"+X+"-id",p));A.methods=V;const U=(J=this.abstractMethods)==null?void 0:J.map((ie,X)=>ie.clone(i,A,w+"-abstract-method-"+X+"-id",p));return A.abstractMethods=U,i==null||i.attemptAutoclose("clone-entity",this.id),A}getFunctionDeclaration(i){return this.methods.find(a=>a.id===i)}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-definition-entity")),l){const p=Im(this,i,a,l);return a==null||a.attemptAutoclose("implement-definition-entity",this.id),p}getAllInteractiveMethods(){const i=this.implements.filter(l=>l.type===f.DefinitionEntity||l.type===f.BuiltInBaseEntity&&l.interactive);return R([...this.methods,...this.extends.flatMap(l=>l.getAllInteractiveMethods()),...i.flatMap(l=>l.getAllInteractiveMethods())])}inferFromInputs(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const l=[],p=[],e=[],y=[];if(this.parent.type!==f.DataType||!this.parent.inferred)return a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const v=[];i.forEach(A=>{v.find(V=>ne(V,this.project)===ne(A,this.project))||v.push(A)});const E=this.properties.filter(A=>!A.dataType);v.forEach(A=>{var ie,X,ue;const $=E.find(re=>ne(re,this.project)===ne(A,this.project));if(!$)return;const U=$i(A.parent).getMasterInputWithValueWritterFromAllInstances(A),G=yn(U,a),K=G==null?void 0:G.clone(a,$,N.UUID.uuid(),!0);K&&((ie=$.dataType)==null||ie.merge(K,a),K.id!==((X=$.dataType)==null?void 0:X.id)&&K.remove({ignoreUpstream:!1},a),$.dataType&&($.dataType.metaSync({inferred:!0,like:!0},a),$.setDataType($.dataType,a),a==null||a.add($,S.Affected)));let J=null;if(A.declaration&&$.id!==((ue=A.declaration)==null?void 0:ue.id)&&(J=A.declaration),A.setDeclaration($,a),a==null||a.add(A,S.Updated),J){const{updated:re,removed:fe}=J.remove({ignoreUpstream:!1},a);p.push(...re),e.push(...fe)}});const w=[];return v.forEach(A=>{if(!A.declaration){w.push(A);return}}),w.length===0?(a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(w.forEach(A=>{var X,ue,re,fe;const $=this.properties.find(Y=>ne(Y,this.project)===ne(A,this.project));if($){if(A.setDeclaration($,a),!$.getDataType(a)){const H=$i(A.parent).getMasterInputWithValueWritterFromAllInstances(A),ce=yn(H),z=ce==null?void 0:ce.clone(a,$,N.UUID.uuid(),!0);z&&((X=$.dataType)==null||X.merge(z,a),z.id!==((ue=$.dataType)==null?void 0:ue.id)&&z.remove({ignoreUpstream:!1},a),$.dataType&&($.dataType.metaSync({inferred:!0,like:!0},a),$.setDataType($.dataType,a),a==null||a.add($,S.Affected)))}return}const V=ea.new(a);V.parent=this.toReference(),V.index=A.index,V.name=ne(A,this.project),V.codeName=A.codeName,V.description=A.description;const U=te(V,this.project);U.hydrateAncestors(),a==null||a.add(U,S.Added),U.setParent(this,a),U.initChildren(a);const K=$i(A.parent).getMasterInputWithValueWritterFromAllInstances(A),J=yn(K),ie=J==null?void 0:J.clone(a,U,N.UUID.uuid(),!0);return ie&&((re=U.dataType)==null||re.merge(ie,a),ie.id!==((fe=U.dataType)==null?void 0:fe.id)&&ie.remove({ignoreUpstream:!1},a),U.dataType&&(U.dataType.metaSync({inferred:!0,like:!0},a),U.setDataType(U.dataType,a),a==null||a.add(U,S.Affected))),this.addProperty(U),A.setDeclaration(U,a),a==null||a.add(A,S.Updated),U}),a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:R(l),updated:R(p),removed:R(e),affected:R(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(a=>{var p;if(!Sb(a))return;const l=jr(a.name);i[l]=((p=a.getDefaultValue())==null?void 0:p.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(a=>{var e;if(!Sb(a))return;const l=jr(a.name),p=(e=this.project.requestActiveDynamicValue(a))==null?void 0:e.value;i[l]=(p==null?void 0:p.value)||null}),i}};g(qt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),g(qt,"type",f.DefinitionEntity),g(qt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.DataType]),g(qt,"PARENT_TYPES",[...qt.USER_MANAGED_PARENT_TYPES]),g(qt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract"]),g(qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(qt,"BASE_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,...qt.INMUTABLE_BASE_PROPERTIES]),g(qt,"MUTABLE_META_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,"x","y"]),g(qt,"INMUTABLE_META_PROPERTIES",[...qt.INMUTABLE_BASE_PROPERTIES]),g(qt,"META_PROPERTIES",[...qt.MUTABLE_META_PROPERTIES,...qt.INMUTABLE_META_PROPERTIES]),g(qt,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),g(qt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),g(qt,"UPSTREAM_PROPERTIES",[...qt.MUTABLE_UPSTREAM_PROPERTIES,...qt.INMUTABLE_UPSTREAM_PROPERTIES]),g(qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),g(qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),g(qt,"DOWNSTREAM_PROPERTIES",[...qt.MUTABLE_DOWNSTREAM_PROPERTIES,...qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),g(qt,"PROPERTIES",[...qt.META_PROPERTIES,...qt.UPSTREAM_PROPERTIES,...qt.DOWNSTREAM_PROPERTIES]);let ta=qt;function OAe(d){const u=phe(),i=d.toJSON();u.safeParse(i).success;const l=[];return vr(d.errors,l)}const cf=class cf extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"version");g(this,"name");g(this,"description",null);g(this,"type",f.BuiltInBaseEntity);g(this,"abstract",!1);g(this,"static");g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"interactive",!1);g(this,"errors",[]);g(this,"project");this.initialData=this.initialData||i,this.project=this.project||a,this.id=this.id||i.id,this.version=this.version||i.version,this.name=this.name||i.name,this.static=this.static||i.static,this.interactive=this.interactive||i.interactive,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.extends=this.initialData.extends.map(l=>te(l,this.project))}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...l]},[]))}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ve,...a){return await cf.repository.APILoad(this.id,...a),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i)),...this.extends.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i)),...this.extends.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i))})}toReference(i=ke){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ke){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(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:this.extends.map(a=>a.toReference())}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}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(i=>i.id)}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=OAe(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new F(this.project,N.sessionAuthor,L().toISOString(),null,!0,"implement-built-in-base-entity")),l){const p=Im(this,i,a,l);return a==null||a.attemptAutoclose("implement-built-in-base-entity",this.id),p}getAllInteractiveMethods(){const i=[];return this.interactive&&(i.push(...this.methods),this.extends.filter(l=>l.type===f.BuiltInBaseEntity&&l.interactive||l.type===f.PrimitiveEntity).forEach(l=>{l instanceof cf&&i.push(...l.getAllInteractiveMethods())})),R(i)}};g(cf,"repository",{APILoad:async(i,...a)=>null});let ra=cf;function CAe(d){const u=ihe(),i=d.toJSON();u.safeParse(i).success;const l=[];return vr(d.errors,l)}const Gm=class Gm extends Nr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"name");g(this,"description",null);g(this,"type",f.PrimitiveEntity);g(this,"static");g(this,"abstract");g(this,"properties",[]);g(this,"methods",[]);g(this,"abstractMethods",[]);g(this,"extends",[]);g(this,"errors",[]);g(this,"project");this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.static=i.static,this.abstract=i.abstract,this.properties=this.initialData.properties.map(l=>{const p=te(l,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(l=>{const p=te(l,this.project);return p.parent=this,p}),this.abstractMethods=this.initialData.abstractMethods.map(l=>{const p=te(l,this.project);return p.parent=this,p})}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...this.extends.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...l]},[]))}get extendedPropertiesFromOriginalParents(){return R(this.extends.reduce((i,a)=>{const l=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...l]},[]))}get implementedPropertiesFromOriginalParents(){return R([...this.extends.reduce((i,a)=>{const l=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!l.find(y=>y.name===e.name));return[...l,...p,...i]},[])])}get extendedProperties(){return this.properties.filter(i=>i.isExtendedProperty)}get ownDeclaredMethods(){return this.methods.filter(i=>!i.isExtendedMethod)}get ownDeclaredProperties(){return this.properties.filter(i=>!i.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(i=ve,...a){return await Gm.repository.APILoad(this.id,...a),this}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(l=>l.toFlat(i)),...this.methods.flatMap(l=>l.toFlat(i)),...this.abstractMethods.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(l=>l.toFlatIds(i)),...this.methods.flatMap(l=>l.toFlatIds(i)),...this.abstractMethods.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(a=>a.toJSON(i)),methods:this.methods.map(a=>a.toJSON(i)),abstractMethods:this.abstractMethods.map(a=>a.toJSON(i)),extends:this.extends.map(a=>a.toJSON(i))})}toReference(i=ke){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=ke){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(a=>a.toReference()),methods:this.methods.map(a=>a.toReference()),abstractMethods:this.abstractMethods.map(a=>a.toReference()),extends:this.extends.map(a=>a.toReference())}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(l=>l.toFlatJSON(i)),...this.methods.flatMap(l=>l.toFlatJSON(i)),...this.abstractMethods.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(i=>i.id)}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(l=>l.toFlatGenerationTarget(i)),...this.methods.flatMap(l=>l.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.properties.forEach(i=>i.clearErrors()),this.methods.forEach(i=>i.clearErrors()),this.abstractMethods.forEach(i=>i.clearErrors()),this}validate(){const i=CAe(this);return this.errors=i,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(a=>a.getErrors()),...this.methods.flatMap(a=>a.getErrors()),...this.abstractMethods.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const i=[];return i.push(...this.methods),this.extends.filter(l=>l.type===f.BuiltInBaseEntity&&l.interactive||l.type===f.PrimitiveEntity).forEach(l=>{l instanceof ra&&i.push(...l.getAllInteractiveMethods())}),R(i)}};g(Gm,"repository",{APILoad:async(i,...a)=>null});let es=Gm;function or(d,u){if(!d)throw new Error("Entity is null");const i=u.get(d.id);switch(d.type){case f.LiteralValue:return i||new Gi(d,u);case f.DefinitionEntity:return i||new ta(d,u);case f.PrimitiveEntity:return i||new es(d,u);case f.FunctionDeclaration:return i||new io(d,u);case f.GlobalEvent:return i||new ao(d,u);case f.DataType:return i||new hs(d,u);case f.Property:return i||new ea(d,u);case f.FunctionCall:return i||new Ao(d,u);case f.Condition:return i||new oo(d,u);case f.Operation:return i||new so(d,u);case f.VariableDeclaration:return i||new uo(d,u);case f.VariableInstance:return i||new lo(d,u);case f.OutputMap:return i||new mn(d,u);case f.ReturnDeclaration:return i||new Qi(d,u);case f.ArgumentDeclaration:return i||new Zn(d,u);case f.InputMap:return i||new Yn(d,u);case f.Project:return i||new N(d);case f.InstalledProject:return i||new po(d,u);case f.ActionDescriptor:return i||new wt(d,u);case f.ReturnStatement:return i||new no(d,u);case f.Loop:return i||new xi(d,u);case f.Search:return i||new co(d,u);case f.ValueDescriptor:return i||new vn(d,u);case f.BuiltInBaseEntity:return i||new ra(d,u);case f.InternalCall:return i||new fo(d,u);case f.ContinueStatement:return i||new Ci(d,u);case f.BreakStatement:return i||new ho(d,u);case f.GenericReference:return u.get(d.entityId);default:throw new Error("Invalid entity type: "+d.type)}}function te(d,u){if(!d)throw new Error("Entity is null");const i=or(d,u);return i.subscribe(),i}function $Ae(d,u){if(!d)throw new Error("Entity is null");switch(d.type){case f.LiteralValue:return Gi.fromGenerationTarget(d,u);case f.DefinitionEntity:return ta.fromGenerationTarget(d,u);case f.FunctionDeclaration:return io.fromGenerationTarget(d,u);case f.GlobalEvent:return ao.fromGenerationTarget(d,u);case f.DataType:return hs.fromGenerationTarget(d,u);case f.Property:return ea.fromGenerationTarget(d,u);case f.FunctionCall:return Ao.fromGenerationTarget(d,u);case f.Condition:return oo.fromGenerationTarget(d,u);case f.Operation:return so.fromGenerationTarget(d,u);case f.VariableDeclaration:return uo.fromGenerationTarget(d,u);case f.VariableInstance:return lo.fromGenerationTarget(d,u);case f.OutputMap:return mn.fromGenerationTarget(d,u);case f.ReturnDeclaration:return Qi.fromGenerationTarget(d,u);case f.ArgumentDeclaration:return Zn.fromGenerationTarget(d,u);case f.InputMap:return Yn.fromGenerationTarget(d,u);case f.InstalledProject:return po.fromGenerationTarget(d,u);case f.ReturnStatement:return no.fromGenerationTarget(d,u);case f.Loop:return xi.fromGenerationTarget(d,u);case f.Search:return co.fromGenerationTarget(d,u);case f.ActionDescriptor:return wt.fromGenerationTarget(d,u);case f.ValueDescriptor:return vn.fromGenerationTarget(d,u);case f.InternalCall:return fo.fromGenerationTarget(d,u);case f.ContinueStatement:return Ci.fromGenerationTarget(d,u);case f.BreakStatement:return ho.fromGenerationTarget(d,u);default:throw new Error("Invalid entity type: "+d.type)}}const ke={seenEntityMaps:new Map,seenEntities:new Set,timestamp:L().toISOString()};class US{constructor(){g(this,"initialData")}}const ve={cascade:!1},jS={APILoad:async(d,...u)=>null},PAe={APICreate:async(d,...u)=>d,APIUpdate:async(d,...u)=>d,APIDelete:async(d,...u)=>d,APIClone:async(d,...u)=>{},APILoadVersion:async(d,u,...i)=>null,...jS};class NAe{}class VAe extends US{}class LAe{}class MAe{}class BAe{}class zb{}class UAe extends zb{}class jAe extends zb{}class xAe{}class lf{static initReadsValue(u){if(u.initialData.readsValue&&u.initialData.readsValue.type!==f.GenericReference)u.readsValue=te(u.initialData.readsValue,u.project);else if(u.initialData.readsValue&&u.initialData.readsValue.type===f.GenericReference){const i=ki(u.initialData.readsValue,u.project);i&&(u.readsValue=i)}if(u.readsValue){if(mt.includes(u.readsValue.type)){let i=u.parent;Mr.includes(i.type)||(i=i.parent);const a=u.type===f.InputMap&&u.parent.type===f.Loop;a&&(i=u.parent.parent),u.readsValue.setParent(i,null),u.readsValue.initChildren(null),i&&i.type!==f.Project&&!a&&i.detachedChildren.includes(u)?i.replaceDetachedChild(u,u.readsValue):i&&i.type!==f.Project&&!a&&i.subscribeDetachedChild(u.readsValue)}u.readsValue.addValueReader(u,null)}return u.readsValue}}class df{static initWritesValues(u,i){const a=u.initialData.writesValues.reduce((p,e)=>{if(e.type===f.GenericReference||u.writesValues.some(v=>v.id===e.id))return p;const y=te(e,u.project);return y.setValueWriter(u,null),mt.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...p,y]},[]),l=[...u.writesValues];return u.writesValues=R([...l,...a]),u.writesValues}}class FAe{}var Vr=(d=>(d.PROJECT_INITIALIZED="project-initialized",d.CHANGE_SET_CLOSED="change-set-closed",d.EXPLICIT_DEFINITION_ENTITY_ADDED="explicit-definition-entity-added",d.EXPLICIT_DEFINITION_ENTITY_REMOVED="explicit-definition-entity-removed",d.EXPLICIT_DEFINITION_ENTITY_UPDATED="explicit-definition-entity-updated",d.PERSISTED_DEFINITION_ENTITY_ADDED="persisted-definition-entity-added",d.PERSISTED_DEFINITION_ENTITY_REMOVED="persisted-definition-entity-removed",d.PERSISTED_DEFINITION_ENTITY_UPDATED="persisted-definition-entity-updated",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_ADDED="relational-database-definition-entity-added",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_REMOVED="relational-database-definition-entity-removed",d.RELATIONAL_DATABASE_DEFINITION_ENTITY_UPDATED="relational-database-definition-entity-updated",d))(Vr||{});const Xb={...tb,events:new Kp},xS={requestActiveDynamicValue:d=>null,...Xb},pt=class pt extends Nr{constructor(i,a={...xS,events:new Kp}){super(i);g(this,"initialData");g(this,"id");g(this,"type",f.Project);g(this,"name",null);g(this,"description",null);g(this,"x");g(this,"y");g(this,"entities",[]);g(this,"projects",[]);g(this,"functions",[]);g(this,"events",[]);g(this,"variableDeclarations",[]);g(this,"variableInstances",[]);g(this,"conditions",[]);g(this,"operations",[]);g(this,"functionCalls",[]);g(this,"loops",[]);g(this,"searches",[]);g(this,"primitives",[]);g(this,"builtInBaseEntities",[]);g(this,"operationDeclarations",[]);g(this,"globalEventActionDescriptors",[]);g(this,"loopDeclarations",[]);g(this,"loopDeclarationsBodies",[]);g(this,"conditionDeclarations",[]);g(this,"valueDescriptors",[]);g(this,"dataTypes",[]);g(this,"project");g(this,"instances",{});g(this,"builtInInstances",{});g(this,"deletedInstances",{});g(this,"errors",[]);g(this,"references",[]);g(this,"history",[]);g(this,"undoableStackValueIndex",-1);g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);g(this,"onCloseChangeSetCallback",null);g(this,"onAddChangeSetCallback",null);g(this,"onDiscardChangeSetCallback",null);if(this.parentContext=a,this.initialData=i,this.id=i.id,this.name=i.name,this.description=i.description,this.x=0,this.y=0,this.instances[this.id]=this,!pt.UUID)throw new Error("UUID module is already initialized. Please inject a valid UUID module.")}static get UUID(){return this.parentContext.requestModule("uuid")}static new(i=null){return{id:pt.UUID.uuid(),version:pt.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||pt.sessionAuthor,previousVersion:null,deleted:!1,type:f.Project,name:"",description:"",entities:[],functions:[],events:[],projects:[],variableDeclarations:[],variableInstances:[],conditions:[],operations:[],functionCalls:[],loops:[],searches:[]}}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const p=[];return p.push(...Br(l)),{errors:p,modifiedData:l}}get off(){return this.parentContext.events.off}get on(){return this.parentContext.events.on}get emit(){return this.parentContext.events.emit}async closePendingChangeSets(){const i=this.history.find(a=>a.dirty&&!a.open);i&&await this.closeChangeSet(i)}async onCloseChangeSet(i){this.onCloseChangeSetCallback=i,await this.closePendingChangeSets()}onAddChangeSet(i){this.onAddChangeSetCallback=i}onDiscardChangeSet(i){this.onDiscardChangeSetCallback=i}async closeChangeSet(i){const a=this.history.findIndex(e=>e.id===i.id),l=this.history.slice(0,a),p=l[l.length-1];if(!(p!=null&&p.dirty)&&this.onCloseChangeSetCallback){(await this.onCloseChangeSetCallback(i)).success&&(i.dirty=!1,this.emit("change-set-closed",i),this.closePendingChangeSets());return}}toLatestChangeSet(i,a,l,p=!1,e="here-this"){if(!this.history.length)return new F(this,i,a,l,p,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new F(this,i,a,l,p,e))}addChangeSet(i){var p,e;if(!this.history.length)return this.undoableStackValueIndex=sA(this.undoableStackValueIndex,this.history,i),(p=this.onAddChangeSetCallback)==null||p.call(this,i,this.undoableStackValueIndex),i;const a=this.history.find(y=>y.id===(i==null?void 0:i.id));if(a)return a;const l=this.history.find(y=>y.open);if(l)throw Me.warn("Previous still open: ",l),Me.warn("New change set: ",i),new Error(`There is already an open change-set with id '${l.id}'.`);return this.undoableStackValueIndex=sA(this.undoableStackValueIndex,this.history,i),(e=this.onAddChangeSetCallback)==null||e.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var l;const a=this.history.findIndex(p=>p.id===(i==null?void 0:i.id));return a!==-1&&(this.history.splice(a,1),this.undoableStackValueIndex=this.undoableStackValueIndex-1,(l=this.onDiscardChangeSetCallback)==null||l.call(this,i)),this}validateGeneratedUpdate(i){return{errors:[],modifiedData:i}}subscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]||(this.detachedDependents[a.entity.id]=a)}),this}unsubscribeDependents(i){return i.forEach(a=>{this.detachedDependents[a.entity.id]&&delete this.detachedDependents[a.entity.id]}),this}syncDependents(i=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,l){const p=[],e=[],y=[],v=[];return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,l){const p=[],e=[],y=[],v=[];return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!L(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&L(i).isSame(L(this.createdAt))?this:(this.previousVersion=this.version,this.version=pt.UUID.uuid(),this.createdAt=L(i).toISOString()||L().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new pt(this);return i.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,i):new Map([[this.version,i]]),i.entities=[...this.entities],i.projects=[...this.projects],i.functions=[...this.functions],i.events=[...this.events],i.variableDeclarations=[...this.variableDeclarations],i.variableInstances=[...this.variableInstances],i.conditions=[...this.conditions],i.operations=[...this.operations],i.functionCalls=[...this.functionCalls],i.loops=[...this.loops],i.searches=[...this.searches],this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],p=[],e=[];return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this};if(!this.knownVersions){const E=new Map;for(const[w,A]of this.knownVersions||new Map){if(E.set(w,A),A.activeVersion=!1,A.knownVersions)for(const[$,V]of A.knownVersions)E.set($,V);A.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const E=await this.APILoadVersion({},i);if(!E)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new pt(E)}return this.metaSync(y.toShallowJSON(),null),this.previousVersion=y.previousVersion,this.version=y.version,this.createdAt=y.createdAt,this.author=y.author,this.deleted=y.deleted,this.entities=y.entities,this.projects=y.projects,this.functions=y.functions,this.events=y.events,this.variableDeclarations=y.variableDeclarations,this.variableInstances=y.variableInstances,this.conditions=y.conditions,this.operations=y.operations,this.functionCalls=y.functionCalls,this.loops=y.loops,this.searches=y.searches,{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){return this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],l=[],p=[];return{updated:R(i),added:R(a),removed:R(l),affected:R(p),self:this}}afterAllChildrenInitialized(i=null){const a=[],l=[],p=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}addSelfToProject(i){const a=[],l=[],p=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:R(a),added:R(l),removed:R(p),affected:R(e),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(i){return this.operationDeclarations.includes(i)}isGlobalEventActionDescriptor(i){return this.globalEventActionDescriptors.includes(i)}isLoopDeclaration(i){return this.loopDeclarations.includes(i)}isConditionDeclaration(i){return this.conditionDeclarations.includes(i)}initChildren(i=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.projects=this.initialData.projects.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableDeclarations=this.initialData.variableDeclarations.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.variableInstances=this.initialData.variableInstances.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.conditions=this.initialData.conditions.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.operations=this.initialData.operations.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.functions=this.initialData.functions.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.events=this.initialData.events.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.functionCalls=this.initialData.functionCalls.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.loops=this.initialData.loops.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.searches=this.initialData.searches.map(a=>{const l=te(a,this);return l.setParent(this,null),l.initChildren(i),l}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}subscribeInstance(i){return(!this.instances[i.id]||this.instances[i.id]!==i)&&(this.instances[i.id]=i),this}subscribeDeletedInstance(i){return(!this.deletedInstances[i.id]||this.deletedInstances[i.id]!==i)&&(this.deletedInstances[i.id]=i),this}subscribeBuiltInInstance(i){return(!this.builtInInstances[i.id]||this.builtInInstances[i.id]!==i)&&(this.builtInInstances[i.id]=i),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(i){return delete this.instances[i.id],this}unsubscribeDeletedInstance(i){return delete this.deletedInstances[i.id],this}findSubscribedBuiltInInstance(i){return this.builtInInstances[i.id]||null}get(i){return this.instances[i]||this.builtInInstances[i]||null}getDeleted(i){return this.deletedInstances[i]||null}getManaged(i){return this.getBuiltIn(i)?null:this.instances[i]||null}getBuiltIn(i){return this.builtInInstances[i]||null}findSubscribedInstanceFromReference(i){return this.instances[i.entityId]||null}findSubscribedBuiltInInstanceFromReference(i){return this.builtInInstances[i.entityId]||null}metaSync(i,a=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const l=Ur(this,i),p=this.toMeta();return this.name=i.name!==void 0?i.name:p.name,this.description=i.description!==void 0?i.description:p.description,this.x=i.x||p.x,this.y=i.y||p.y,super.metaSync(i),i.deleted===!0&&!p.deleted?a==null||a.add(this,S.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,S.Added):l&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await pt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await pt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await pt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await pt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await pt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...l){return await pt.repository.APILoadVersion(this.id,a,...l)}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new F(this.project,pt.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const i=new Set;return[...this.primitives.flatMap(a=>a.toFlatIds(i)),...this.builtInBaseEntities.flatMap(a=>a.toFlatIds(i)),...this.operationDeclarations.flatMap(a=>a.toFlatIds(i)),...this.globalEventActionDescriptors.flatMap(a=>a.toFlatIds(i)),...this.loopDeclarations.flatMap(a=>a.toFlatIds(i)),...this.conditionDeclarations.flatMap(a=>a.toFlatIds(i)),...this.valueDescriptors.flatMap(a=>a.toFlatIds(i)),...this.dataTypes.flatMap(a=>a.toFlatIds(i))]}getAllBuiltIn(){const i=new Set;return[...this.primitives.flatMap(a=>a.toFlat(i)),...this.builtInBaseEntities.flatMap(a=>a.toFlat(i)),...this.operationDeclarations.flatMap(a=>a.toFlat(i)),...this.globalEventActionDescriptors.flatMap(a=>a.toFlat(i)),...this.loopDeclarations.flatMap(a=>a.toFlat(i)),...this.conditionDeclarations.flatMap(a=>a.toFlat(i)),...this.valueDescriptors.flatMap(a=>a.toFlat(i)),...this.dataTypes.flatMap(a=>a.toFlat(i))]}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.entities.flatMap(l=>l.toFlat(i)),...this.functions.flatMap(l=>l.toFlat(i)),...this.events.flatMap(l=>l.toFlat(i)),...this.projects.flatMap(l=>l.toFlat(i)),...this.variableDeclarations.flatMap(l=>l.toFlat(i)),...this.variableInstances.flatMap(l=>l.toFlat(i)),...this.conditions.flatMap(l=>l.toFlat(i)),...this.operations.flatMap(l=>l.toFlat(i)),...this.functionCalls.flatMap(l=>l.toFlat(i)),...this.loops.flatMap(l=>l.toFlat(i)),...this.searches.flatMap(l=>l.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(l=>l.toFlatIds(i)),...this.functions.flatMap(l=>l.toFlatIds(i)),...this.events.flatMap(l=>l.toFlatIds(i)),...this.projects.flatMap(l=>l.toFlatIds(i)),...this.variableDeclarations.flatMap(l=>l.toFlatIds(i)),...this.variableInstances.flatMap(l=>l.toFlatIds(i)),...this.conditions.flatMap(l=>l.toFlatIds(i)),...this.operations.flatMap(l=>l.toFlatIds(i)),...this.functionCalls.flatMap(l=>l.toFlatIds(i)),...this.loops.flatMap(l=>l.toFlatIds(i)),...this.searches.flatMap(l=>l.toFlatIds(i))])}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(i=new Set){return i.has(this.id)?this.toReference():(i.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(a=>a.toJSON(i)),variableDeclarations:this.variableDeclarations.map(a=>a.toJSON(i)),variableInstances:this.variableInstances.map(a=>a.toJSON(i)),conditions:this.conditions.map(a=>a.toJSON(i)),operations:this.operations.map(a=>a.toJSON(i)),loops:this.loops.map(a=>a.toJSON(i)),searches:this.searches.map(a=>a.toJSON(i)),functions:this.functions.map(a=>a.toJSON(i)),events:this.events.map(a=>a.toJSON(i)),projects:this.projects.map(a=>a.toJSON(i)),functionCalls:this.functionCalls.map(a=>a.toJSON(i))})}toJSONClone(i={uuidStrategy:"uuid"}){const a=new Map,l=new Set,p=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(p.includes(e)){a.set(e,e);return}a.set(e,pt.UUID.uuid())}),l.add(this.id),{id:a.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(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:l,newId:null}))}}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+pt.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,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(p=>p.toReference(i)),functions:this.functions.map(p=>p.toReference(i)),events:this.events.map(p=>p.toReference(i)),projects:this.projects.map(p=>p.toReference(i)),variableDeclarations:this.variableDeclarations.map(p=>p.toReference(i)),variableInstances:this.variableInstances.map(p=>p.toReference(i)),conditions:this.conditions.map(p=>p.toReference(i)),operations:this.operations.map(p=>p.toReference(i)),functionCalls:this.functionCalls.map(p=>p.toReference(i)),loops:this.loops.map(p=>p.toReference(i)),searches:this.searches.map(p=>p.toReference(i))}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(l=>l.toFlatJSON(i)),...this.functions.flatMap(l=>l.toFlatJSON(i)),...this.events.flatMap(l=>l.toFlatJSON(i)),...this.projects.flatMap(l=>l.toFlatJSON(i)),...this.variableDeclarations.flatMap(l=>l.toFlatJSON(i)),...this.variableInstances.flatMap(l=>l.toFlatJSON(i)),...this.conditions.flatMap(l=>l.toFlatJSON(i)),...this.operations.flatMap(l=>l.toFlatJSON(i)),...this.functionCalls.flatMap(l=>l.toFlatJSON(i)),...this.loops.flatMap(l=>l.toFlatJSON(i)),...this.searches.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[...this.entities.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.events.flatMap(l=>l.toFlatGenerationTarget(i)),...this.projects.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(l=>l.toFlatGenerationTarget(i)),...this.conditions.flatMap(l=>l.toFlatGenerationTarget(i)),...this.operations.flatMap(l=>l.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.loops.flatMap(l=>l.toFlatGenerationTarget(i)),...this.searches.flatMap(l=>l.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.entities.forEach(i=>i.clearErrors()),this.projects.forEach(i=>i.clearErrors()),this.functions.forEach(i=>i.clearErrors()),this.events.forEach(i=>i.clearErrors()),this.variableDeclarations.forEach(i=>i.clearErrors()),this.variableInstances.forEach(i=>i.clearErrors()),this.conditions.forEach(i=>i.clearErrors()),this.operations.forEach(i=>i.clearErrors()),this.functionCalls.forEach(i=>i.clearErrors()),this.loops.forEach(i=>i.clearErrors()),this.searches.forEach(i=>i.clearErrors()),this}validate(){const i=Lye(),a=this.toJSON();return i.safeParse(a),this.validateChildren(),{success:!0,error:null,data:a}}validateChildren(){this.entities.forEach(i=>i.validate()),this.projects.forEach(i=>i.validate()),this.functions.forEach(i=>i.validate()),this.events.forEach(i=>i.validate()),this.variableDeclarations.forEach(i=>i.validate()),this.variableInstances.forEach(i=>i.validate()),this.conditions.forEach(i=>i.validate()),this.operations.forEach(i=>i.validate()),this.functionCalls.forEach(i=>i.validate()),this.loops.forEach(i=>i.validate()),this.searches.forEach(i=>i.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(a=>a.getErrors()),...this.projects.flatMap(a=>a.getErrors()),...this.functions.flatMap(a=>a.getErrors()),...this.events.flatMap(a=>a.getErrors()),...this.variableDeclarations.flatMap(a=>a.getErrors()),...this.variableInstances.flatMap(a=>a.getErrors()),...this.conditions.flatMap(a=>a.getErrors()),...this.operations.flatMap(a=>a.getErrors()),...this.functionCalls.flatMap(a=>a.getErrors()),...this.loops.flatMap(a=>a.getErrors()),...this.searches.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(i){return this.entities.find(a=>a.id===i)||null}addDefinitionEntity(i){return this.entities.includes(i)||this.entities.push(i),i}addFunctionDeclaration(i){return this.functions.includes(i)||this.functions.push(i),i}addFunctionCall(i){return this.functionCalls.includes(i)||this.functionCalls.push(i),i}addVariableDeclaration(i){return this.variableDeclarations.includes(i)||this.variableDeclarations.push(i),i}addVariableInstance(i){return this.variableInstances.includes(i)||this.variableInstances.push(i),i}addInstalledProject(i){return this.projects.includes(i)||this.projects.push(i),this}addGlobalEvent(i){return this.events.includes(i)||this.events.push(i),this}addCondition(i){return this.conditions.includes(i)||this.conditions.push(i),this}addOperation(i){return this.operations.includes(i)||this.operations.push(i),this}addLoop(i){return this.loops.includes(i)||this.loops.push(i),this}addSearch(i){return this.searches.includes(i)||this.searches.push(i),this}removeDefinitionEntity(i){const a=this.entities.findIndex(l=>l.id===i.id);if(a>-1){const l=this.entities[a];return this.entities.splice(a,1),l}return null}removeCondition(i){const a=this.conditions.findIndex(l=>l.id===i.id);if(a>-1){const l=this.conditions[a];return this.conditions.splice(a,1),l}return null}removeOperation(i){const a=this.operations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.operations[a];return this.operations.splice(a,1),l}return null}removeLoop(i){const a=this.loops.findIndex(l=>l.id===i.id);if(a>-1){const l=this.loops[a];return this.loops.splice(a,1),l}return null}removeSearch(i){const a=this.searches.findIndex(l=>l.id===i.id);if(a>-1){const l=this.searches[a];return this.searches.splice(a,1),l}return null}removeFunctionCall(i){const a=this.functionCalls.findIndex(l=>l.id===i.id);if(a>-1){const l=this.functionCalls[a];return this.functionCalls.splice(a,1),l}return null}removeVariableInstance(i){const a=this.variableInstances.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableInstances[a];return this.variableInstances.splice(a,1),l}return null}removeVariableDeclaration(i){const a=this.variableDeclarations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),l}return null}removeFunctionDeclaration(i){const a=this.functions.findIndex(l=>l.id===i.id);if(a>-1){const l=this.functions[a];return this.functions.splice(a,1),l}return null}removeInstalledProject(i){const a=this.projects.findIndex(l=>l.id===i.id);if(a>-1){const l=this.projects[a];return this.projects.splice(a,1),l}return null}removeGlobalEvent(i){const a=this.events.findIndex(l=>l.id===i.id);if(a>-1){const l=this.events[a];return this.events.splice(a,1),l}return null}removeTopLevelVariableDeclaration(i){if(i.type!==f.VariableDeclaration)return null;const a=this.variableDeclarations.findIndex(l=>l.id===i.id);if(a>-1){const l=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),l}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(a=>a.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.ReturnStatement||e.type===f.ContinueStatement||e.type===f.BreakStatement)]},[])]}getFunctionDeclaration(i){return this.functions.find(a=>a.id===i)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.functionCalls.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.conditions.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.operations.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.loops.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[]),...this.searches.reduce((a,l)=>{const p=yr(l);return[...a,...p]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((a,l)=>[...a,...l.methods.flatMap(p=>{const y=_t(p).filter(v=>v.type===f.VariableInstance);return[...a,...y]})],[]),...this.getEntryPoints().reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.functionCalls.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.conditions.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.operations.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.loops.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.searches.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[])]}getVariableDeclarations(){return R([...this.variableDeclarations,...this.entities.reduce((a,l)=>[...a,...l.methods.flatMap(p=>{const y=_t(p).filter(v=>v.type===f.VariableDeclaration);return[...a,...y]})],[]),...this.getEntryPoints().reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.functionCalls.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.conditions.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.operations.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.loops.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.searches.reduce((a,l)=>{const e=yr(l).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.searches.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.functionCalls.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.conditions.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.operations.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.loops.reduce((a,l)=>{const p=_t(l);return[...a,...p.filter(e=>e.type===f.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),a=this.getVariableDeclarations();return i.forEach(l=>{if(!l.declaration){const p=l.initialData,e=p.declaration.entityId||p.declaration.id,y=a.find(v=>v.id===e);y&&l.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Ue.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i){var l,p;const a=(p=(l=this.parentContext).requestActiveDynamicValue)==null?void 0:p.call(l,i);if(!a){const e=i.getDefaultValue();return e?{value:e,type:Ae.DefaultValue,inheritanceLink:null,valueOwner:i}:null}return a||null}requestModule(i){if(this.parentContext.requestModule){const a=this.parentContext.requestModule(i);return!a&&i==="uuid"?Yu:a||null}return i==="uuid"?Yu:null}undo(){Me.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex-1,Me.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex+1],a=this.history[this.undoableStackValueIndex];return Me.log("Current change set: ",i==null?void 0:i.toJSON()),Me.log("Change set to restore: ",a==null?void 0:a.toJSON()),rA(i||"initial",a||"initial",this)}redo(){Me.log("Undoing, from: ",this.undoableStackValueIndex),this.undoableStackValueIndex=this.undoableStackValueIndex+1,Me.log("To: ",this.undoableStackValueIndex);const i=this.history[this.undoableStackValueIndex-1],a=this.history[this.undoableStackValueIndex];return Me.log("Current change set: ",i==null?void 0:i.toJSON()),Me.log("Change set to restore: ",a.toJSON()),rA(i||"initial",a||"initial",this)}applyExternalChangeSet(i){const a=i.payload,l=this.addChangeSet(new F(this,i.userAuthor,i.emittedAt,this)),p=a.updated[this.id];if(!p)throw new Error("Project root not found in change set transfer. Cannot apply changes.");const e={...a.added,...a.updated,...a.removed},y=[...Object.keys(a.added),...Object.keys(a.updated),...Object.keys(a.removed)];y.forEach(E=>{var w;if(!e[E]){Me.warn(`Entity '${E}' not found in change set transfer. Cannot apply changes.`);const A=(w=this.get(E))==null?void 0:w.toShallowJSON();throw A?Me.warn("Entity in project: ",A):Me.warn("Entity not in project"),new Error(`Entity '${E}' not found in change set transfer. Cannot apply changes.`)}});const v=new Qn(p);return v.flatRecord=e,v.order=y,v.orderEntities(),Me.log("All entities: ",v.order.map((E,w)=>`${w+1}: ${e[E].type} - ${E}`).join(`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6410",
3
+ "version": "0.0.6411",
4
4
  "author": "Sergio Herrero",
5
5
  "license": "UNLICENSED",
6
6
  "description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",