@elyx-code/project-logic-tree 0.0.6480 → 0.0.6481
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.d.ts +5 -5
- package/dist/index.js +11600 -11597
- package/dist/index.umd.cjs +5 -5
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -18,7 +18,7 @@ ${F}`})):p.push(new ne({id:`${o.id}--${ae.NoOverlapWithImplementedSignature}`,co
|
|
|
18
18
|
Adding a new argument would make the implementation invalid. There are no arguments in the descriptor with the same name.
|
|
19
19
|
${B}
|
|
20
20
|
${F}`}))}}}return p.push(...e.errors,...y,...Vr(o)),{errors:p,modifiedData:o}}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 ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.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.
|
|
21
|
-
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.`})),{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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];return a==="implements"&&(this.setImplements(null,o),p.push(this)),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];return a==="implements"&&(this.setImplements(i,o),p.push(this)),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,o,p,e;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"implements"}]),(e=(p=(o=this.dataType)==null?void 0:o.entity)==null?void 0:p.unsubscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,a,o,p,e;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"implements"}]),(e=(p=(o=this.dataType)==null?void 0:o.entity)==null?void 0:p.subscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),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 Pt(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.implements=this.implements,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.writesValues=[...this.writesValues],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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,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.implements=y.implements,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.writesValues=y.writesValues,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(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 o=J(i.parent),p=this.project.get(o),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 '${o}' 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 o=J(i.implements),p=this.project.get(o);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(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'`);if(this.initialData.implements){const e=J(this.initialData.implements),y=this.project.get(e);y&&(this.setImplements(y,null),i.push(y))}return{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);return a.push(...y),o.push(...v),p.push(...E),e.push(...w),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent.addInputDeclaration(this,i),e.push(this.parent),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,S.Affected),this)}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(o=>o.id!==i.id),a==null||a.add(this,S.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var o;return((o=this.implements)==null?void 0:o.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}initChildren(i=this.project.addChangeSet(new G(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=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=se(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return nf.initWritesValues(this,this.parent),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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),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.required=i.required!==void 0?i.required:this.required,this.constant=!0,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):o&&(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,...o){return await Pt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.removeInputDeclaration(this,i),e.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.writesValues.forEach(v=>{o.push(v),v.readsValue=null}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);o.push(...v.updated),p.push(...v.removed)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}if(this.writesValues.forEach(y=>{o.push(y),y.setValueWriter(this,i)}),e.push(this.parent),this.parent.addInputDeclaration(this,i),this.dataType){const{updated:y}=this.dataType.restore({},i);o.push(...y)}return i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...this.writesValues.flatMap(e=>e.toFlat(i)),...((p=this.dataType)==null?void 0:p.toFlat(i))||[]])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.toFlatIds(i))||[],...this.writesValues.flatMap(e=>e.toFlatIds(i)),...((p=this.dataType)==null?void 0:p.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,required:this.required,constant:!0,type:this.type,name:this.name}}toJSON(i=new Set){var a,o,p;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,name:this.name,type:this.type,index:this.index,codeName:this.codeName,description:this.description,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((o=this.dataType)==null?void 0:o.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,writesValues:this.writesValues.map(e=>e.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Se){var o,p,e,y,v,E,w,A;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,codeName:this.codeName,description:this.description,required:this.required,constant:!0,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:((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null,writesValues:this.writesValues.map($=>$.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e,y;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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,required:this.required,constant:!0,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),implements:((e=this.implements)==null?void 0:e.toReference(i))||null,dataType:((y=this.dataType)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.toFlatJSON(i))||[],...this.writesValues.flatMap(e=>e.toFlatJSON(i)),...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,codeName:this.codeName,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(e=>e.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(){const i=$U(this);return this.errors=i,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((o=this.dataType)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var $,V;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.dataType=null,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 E=dr(y,e);a?E.setParent(a,null):E.setParent(this.parent,null),p&&E.subscribe(),E.initChildren(i),i==null||i.add(E,S.Added);const w=($=this.dataType)==null?void 0:$.clone(i,E,N.UUID.uuid(),p);E.setDataType(w||null,i);const A=(V=this.defaultValue)==null?void 0:V.clone(i,E,N.UUID.uuid(),p);return E.defaultValue=A||null,i==null||i.attemptAutoclose("clone-entity",this.id),E}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const o=this.dataType;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.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}syncWithImplementation(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){const a=[],o=[],p=[],e=[];if(!this.implements)return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:R(o),updated:R(a),removed:R(p),affected:R(e),self:this};const y=this.implements.getDataType(i);if(!y)return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:R(o),updated:R(a),removed:R(p),affected:R(e),self:this};let v=this.getDataType(i);return v?v&&v.merge(y,i):v=y.clone(i,this),this.setDataType(v,i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:R(o),updated:R(a),removed:R(p),affected:R(e),self:this}}};_(Pt,"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,...o)=>null}),_(Pt,"type",f.ArgumentDeclaration),_(Pt,"USER_MANAGED_PARENT_TYPES",[...Dt]),_(Pt,"PARENT_TYPES",[...Pt.USER_MANAGED_PARENT_TYPES]),_(Pt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","required","constant"]),_(Pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Pt,"BASE_PROPERTIES",[...Pt.MUTABLE_BASE_PROPERTIES,...Pt.INMUTABLE_BASE_PROPERTIES]),_(Pt,"MUTABLE_META_PROPERTIES",[...Pt.MUTABLE_BASE_PROPERTIES,"index"]),_(Pt,"INMUTABLE_META_PROPERTIES",[...Pt.INMUTABLE_BASE_PROPERTIES]),_(Pt,"META_PROPERTIES",[...Pt.MUTABLE_META_PROPERTIES,...Pt.INMUTABLE_META_PROPERTIES]),_(Pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Pt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),_(Pt,"UPSTREAM_PROPERTIES",[...Pt.MUTABLE_UPSTREAM_PROPERTIES,...Pt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),_(Pt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Pt,"DOWNSTREAM_PROPERTIES",[...Pt.MUTABLE_DOWNSTREAM_PROPERTIES,...Pt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Pt,"PROPERTIES",[...Pt.META_PROPERTIES,...Pt.UPSTREAM_PROPERTIES,...Pt.DOWNSTREAM_PROPERTIES]);let Kn=Pt;function VU(d){const u=xhe(d),i=jhe(d),a=ms(d);d.inputs.forEach(p=>p.validate()),a.forEach(p=>p.validate());const o=[...u,...i,...LU(d),...sb(d)];return Er(d.errors,o)}function xhe(d){const u=[];if(!d.calls.length&&!d.extends){const i=Rt({id:`${d.id}--${re.ScopeWithoutLogic}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" does not have any logic defined. So it doesn't do anything.`,severity:H.Warning,code:re.ScopeWithoutLogic,entity:d});u.push(i.error)}return Er(d.errors,u)}function jhe(d){const u=[];return d.implements,Er(d.errors,u)}function LU(d){const u=d.parent.type===f.DefinitionEntity?d.parent.methods.filter(o=>o.id!==d.id):[],a=[...d.project.functions,...u].filter(o=>o.id!==d.id);return Hp(d,[xr],a)}const Ghe=Object.freeze(Object.defineProperty({__proto__:null,validate:VU,validateFunctionDeclarationName:LU},Symbol.toStringTag,{value:"Module"}));var MU=(d=>(d.FunctionDeclarationImplements="function-declaration-implements",d.FunctionDeclarationExtends="function-declaration-extends",d))(MU||{});const Nt=class Nt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"collapsed");_(this,"private");_(this,"index",null);_(this,"type",f.FunctionDeclaration);_(this,"implements",null);_(this,"extends",null);_(this,"inputs",[]);_(this,"calls",[]);_(this,"parent");_(this,"detachedChildren",[]);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.collapsed=i.collapsed,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.index=i.index}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.FunctionDeclaration,name:"",codeName:null,description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const E=J(i.parent);o=a.get(E)}let p=null;if(i.implements){const E=J(i.implements);p=a.get(E)}let e=null;if(i.extends){const E=J(i.extends);e=a.get(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.FunctionDeclaration,index:o.type===f.DefinitionEntity?o.methods.length:null,codeName:i.codeName||null,description:i.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:p,extends:e,x:0,y:0,parent:o},v=se(y,a);return v.setParent(o,null),v}static validateGenerationTarget(i,a){var A;let o=JSON.parse(JSON.stringify(i));const p=[],e=ti(o,{parent:{list:!1,types:[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop],optional:!0},implements:{list:!1,types:[f.ActionDescriptor],optional:!0}},a);o=e.modifiedData;const y=Rb(o,a),v=o.parent?a.get(o.parent):null;if(v&&v.type===f.DefinitionEntity){const $=v,B=Vi($).filter(K=>!K.interactive),F=$.methods.find(K=>{var q;return((q=K.implements)==null?void 0:q.id)===o.implements});if(F&&p.push(new ne({id:`${o.id}--${ae.MethodOverwritesOtherSiblingWithSameImplementation}`,code:ae.MethodOverwritesOtherSiblingWithSameImplementation,severity:H.Error,message:`The '${f.FunctionDeclaration}' with id "${o.id}" is trying to implement the '${f.ActionDescriptor}' with id "${o.implements}", but the parent definition-entity already has a ${f.FunctionDeclaration} with id '${F.id}' that implements the same base method.
|
|
21
|
+
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.`})),{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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];return a==="implements"&&(this.setImplements(null,o),p.push(this)),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];return a==="implements"&&(this.setImplements(i,o),p.push(this)),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,o,p,e;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"implements"}]),(e=(p=(o=this.dataType)==null?void 0:o.entity)==null?void 0:p.unsubscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),this}subscribeToDependencies(){var i,a,o,p,e;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"implements"}]),(e=(p=(o=this.dataType)==null?void 0:o.entity)==null?void 0:p.subscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),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 Pt(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.implements=this.implements,i.defaultValue=this.defaultValue,i.dataType=this.dataType,i.writesValues=[...this.writesValues],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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,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.implements=y.implements,this.defaultValue=y.defaultValue,this.dataType=y.dataType,this.writesValues=y.writesValues,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(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 o=J(i.parent),p=this.project.get(o),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 '${o}' 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 o=J(i.implements),p=this.project.get(o);p&&this.setImplements(p,a)}return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(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'`);if(this.initialData.implements){const e=J(this.initialData.implements),y=this.project.get(e);y&&(this.setImplements(y,null),i.push(y))}return{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);return a.push(...y),o.push(...v),p.push(...E),e.push(...w),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent.addInputDeclaration(this,i),e.push(this.parent),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,S.Affected),this)}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(o=>o.id!==i.id),a==null||a.add(this,S.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var o;return((o=this.implements)==null?void 0:o.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}initChildren(i=this.project.addChangeSet(new G(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=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType&&(this.dataType=se(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(i)),this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}return nf.initWritesValues(this,this.parent),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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,i),p=this.toMeta();return this.index=i.index||(i.index!==0?p.index:0),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.required=i.required!==void 0?i.required:this.required,this.constant=!0,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):o&&(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,...o){return await Pt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.removeInputDeclaration(this,i),e.push(this.parent),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.writesValues.forEach(v=>{o.push(v),v.readsValue=null}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected)}if(this.dataType){const v=this.dataType.remove({ignoreUpstream:!0},a);o.push(...v.updated),p.push(...v.removed)}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}if(this.writesValues.forEach(y=>{o.push(y),y.setValueWriter(this,i)}),e.push(this.parent),this.parent.addInputDeclaration(this,i),this.dataType){const{updated:y}=this.dataType.restore({},i);o.push(...y)}return i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...this.writesValues.flatMap(e=>e.toFlat(i)),...((p=this.dataType)==null?void 0:p.toFlat(i))||[]])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.toFlatIds(i))||[],...this.writesValues.flatMap(e=>e.toFlatIds(i)),...((p=this.dataType)==null?void 0:p.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,required:this.required,constant:!0,type:this.type,name:this.name}}toJSON(i=new Set){var a,o,p;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,name:this.name,type:this.type,index:this.index,codeName:this.codeName,description:this.description,required:this.required,constant:!0,defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,dataType:((o=this.dataType)==null?void 0:o.toJSON(i))||null,implements:((p=this.implements)==null?void 0:p.toJSON(i))||null,writesValues:this.writesValues.map(e=>e.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Se){var o,p,e,y,v,E,w,A;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,codeName:this.codeName,description:this.description,required:this.required,constant:!0,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:((A=this.implements)==null?void 0:A.toJSONClone({...i,newId:null}))||null,writesValues:this.writesValues.map($=>$.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e,y;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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,required:this.required,constant:!0,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,writesValues:this.writesValues.map(v=>v.toReference(i)),implements:((e=this.implements)==null?void 0:e.toReference(i))||null,dataType:((y=this.dataType)==null?void 0:y.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.toFlatJSON(i))||[],...this.writesValues.flatMap(e=>e.toFlatJSON(i)),...((p=this.dataType)==null?void 0:p.toFlatJSON(i))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,codeName:this.codeName,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(e=>e.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(){const i=$U(this);return this.errors=i,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((o=this.dataType)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var $,V;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.dataType=null,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 E=dr(y,e);a?E.setParent(a,null):E.setParent(this.parent,null),p&&E.subscribe(),E.initChildren(i),i==null||i.add(E,S.Added);const w=($=this.dataType)==null?void 0:$.clone(i,E,N.UUID.uuid(),p);E.setDataType(w||null,i);const A=(V=this.defaultValue)==null?void 0:V.clone(i,E,N.UUID.uuid(),p);return E.defaultValue=A||null,i==null||i.attemptAutoclose("clone-entity",this.id),E}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const o=this.dataType;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.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}syncWithImplementation(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){const a=[],o=[],p=[],e=[];if(!this.implements)return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:R(o),updated:R(a),removed:R(p),affected:R(e),self:this};const y=this.implements.getDataType(i);if(!y)return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:R(o),updated:R(a),removed:R(p),affected:R(e),self:this};let v=this.getDataType(i);return v?v&&v.merge(y,i):v=y.clone(i,this),this.setDataType(v,i),i==null||i.attemptAutoclose("sync-with-implementation",this.id),{added:R(o),updated:R(a),removed:R(p),affected:R(e),self:this}}};_(Pt,"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,...o)=>null}),_(Pt,"type",f.ArgumentDeclaration),_(Pt,"USER_MANAGED_PARENT_TYPES",[...Dt]),_(Pt,"PARENT_TYPES",[...Pt.USER_MANAGED_PARENT_TYPES]),_(Pt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","required","constant"]),_(Pt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Pt,"BASE_PROPERTIES",[...Pt.MUTABLE_BASE_PROPERTIES,...Pt.INMUTABLE_BASE_PROPERTIES]),_(Pt,"MUTABLE_META_PROPERTIES",[...Pt.MUTABLE_BASE_PROPERTIES,"index"]),_(Pt,"INMUTABLE_META_PROPERTIES",[...Pt.INMUTABLE_BASE_PROPERTIES]),_(Pt,"META_PROPERTIES",[...Pt.MUTABLE_META_PROPERTIES,...Pt.INMUTABLE_META_PROPERTIES]),_(Pt,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Pt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),_(Pt,"UPSTREAM_PROPERTIES",[...Pt.MUTABLE_UPSTREAM_PROPERTIES,...Pt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Pt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),_(Pt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Pt,"DOWNSTREAM_PROPERTIES",[...Pt.MUTABLE_DOWNSTREAM_PROPERTIES,...Pt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Pt,"PROPERTIES",[...Pt.META_PROPERTIES,...Pt.UPSTREAM_PROPERTIES,...Pt.DOWNSTREAM_PROPERTIES]);let Kn=Pt;function VU(d){const u=xhe(d),i=jhe(d),a=ms(d);d.inputs.forEach(p=>p.validate()),a.forEach(p=>p.validate());const o=[...u,...i,...LU(d),...sb(d)];return Er(d.errors,o)}function xhe(d){const u=[];if(!d.calls.length&&!d.extends){const i=Rt({id:`${d.id}--${re.ScopeWithoutLogic}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" does not have any logic defined. So it doesn't do anything.`,severity:H.Warning,code:re.ScopeWithoutLogic,entity:d});u.push(i.error)}return Er(d.errors,u)}function jhe(d){const u=[];return d.implements,Er(d.errors,u)}function LU(d,u){const i=d.parent.type===f.DefinitionEntity?d.parent.methods.filter(p=>p.id!==d.id):[],o=[...d.project.functions,...i].filter(p=>p.id!==d.id);return Hp(d,[xr],o,u)}const Ghe=Object.freeze(Object.defineProperty({__proto__:null,validate:VU,validateFunctionDeclarationName:LU},Symbol.toStringTag,{value:"Module"}));var MU=(d=>(d.FunctionDeclarationImplements="function-declaration-implements",d.FunctionDeclarationExtends="function-declaration-extends",d))(MU||{});const Nt=class Nt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"collapsed");_(this,"private");_(this,"index",null);_(this,"type",f.FunctionDeclaration);_(this,"implements",null);_(this,"extends",null);_(this,"inputs",[]);_(this,"calls",[]);_(this,"parent");_(this,"detachedChildren",[]);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.private=i.private,this.collapsed=i.collapsed,this.x=i.x,this.y=i.y,this.codeName=i.codeName,this.index=i.index}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.FunctionDeclaration,name:"",codeName:null,description:"",collapsed:!1,private:!1,index:null,implements:null,extends:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const E=J(i.parent);o=a.get(E)}let p=null;if(i.implements){const E=J(i.implements);p=a.get(E)}let e=null;if(i.extends){const E=J(i.extends);e=a.get(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.FunctionDeclaration,index:o.type===f.DefinitionEntity?o.methods.length:null,codeName:i.codeName||null,description:i.description||null,collapsed:!1,private:!1,calls:[],inputs:[],implements:p,extends:e,x:0,y:0,parent:o},v=se(y,a);return v.setParent(o,null),v}static validateGenerationTarget(i,a){var A;let o=JSON.parse(JSON.stringify(i));const p=[],e=ti(o,{parent:{list:!1,types:[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop],optional:!0},implements:{list:!1,types:[f.ActionDescriptor],optional:!0}},a);o=e.modifiedData;const y=Rb(o,a),v=o.parent?a.get(o.parent):null;if(v&&v.type===f.DefinitionEntity){const $=v,B=Vi($).filter(K=>!K.interactive),F=$.methods.find(K=>{var q;return((q=K.implements)==null?void 0:q.id)===o.implements});if(F&&p.push(new ne({id:`${o.id}--${ae.MethodOverwritesOtherSiblingWithSameImplementation}`,code:ae.MethodOverwritesOtherSiblingWithSameImplementation,severity:H.Error,message:`The '${f.FunctionDeclaration}' with id "${o.id}" is trying to implement the '${f.ActionDescriptor}' with id "${o.implements}", but the parent definition-entity already has a ${f.FunctionDeclaration} with id '${F.id}' that implements the same base method.
|
|
22
22
|
A ${f.FunctionDeclaration} that has a parent of type '${f.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${f.ActionDescriptor}' more than once.
|
|
23
23
|
${f.ActionDescriptor} entities inside a ${f.DefinitionEntity} are considered abstract methods that can be implemented by ${f.FunctionDeclaration} entities inside the same parent.
|
|
24
24
|
If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${f.ActionDescriptor} signature, otherwise the implementation will have a validation error.`})),!o.implements&&B.length){let K=B.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${$.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${st(B.map(q=>Y(q,q.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${$.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${Y(B[0],B[0].project)}").`;K+=`
|
|
@@ -76,7 +76,7 @@ You shouldn't have to manually update a 'parent' property. The equivalent result
|
|
|
76
76
|
${mm(a)}`})):p.push(new ne({id:`${i.id}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${f.Condition}' entities.
|
|
77
77
|
${mm(a)}`})):p.push(new ne({id:`${i.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:H.Error,message:`Entity of type '${i.type}' with id '${i.id}' is missing the 'declaration' property. This property is required for a '${i.type}' entity and must point to one of the built-in action descriptors reserved for '${f.Condition}' entities.
|
|
78
78
|
${mm(a)}`})),{errors:p,modifiedData:o}}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
79
|
-
If an entity is called by another, they must be in the same scope, which means they have the same parent.`})),{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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),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 Yt(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.inputs=[...this.inputs],i.declaration=this.declaration,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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 Yt(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.inputs=y.inputs,this.declaration=y.declaration,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){var o,p;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,i.parent){const e=J(i.parent),y=this.project.get(e),v=this.parent;if(v&&v.id!==(y==null?void 0:y.id)&&this.removeFromParent(a),y)this.setParent(y,a),this.addSelfToProject(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 '${e}' 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.declaration){const e=J(i.declaration),y=this.project.get(e);y&&this.setDeclaration(y)}return(o=i.andChildrenGroup)==null||o.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addToAndGroup(v,a),v.setParent(this,a))}),[...this.andChildrenGroup||[]].forEach(e=>{var v;((v=i.andChildrenGroup)==null?void 0:v.find(E=>J(E)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),(p=i.orChildrenGroup)==null||p.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addToOrGroup(v,a),v.setParent(this,a))}),[...this.orChildrenGroup||[]].forEach(e=>{var v;((v=i.orChildrenGroup)==null?void 0:v.find(E=>J(E)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),i.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addEntryCaller(v,a),v.addCall(this,a))}),[...this.calledByEntry].forEach(e=>{i.calledByEntry.find(v=>J(v)===e.id)||(this.removeCaller(e,a),e.removeCall(this,a))}),i.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addSuccessCaller(v,a),v.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(e=>{i.calledBySuccess.find(v=>J(v)===e.id)||(this.removeCaller(e,a),e.removeCall(this,a))}),i.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addErrorCaller(v,a),v.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(e=>{i.calledBySuccess.find(v=>J(v)===e.id)||(this.removeCaller(e,a),e.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(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.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),o.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project?this.project.addCondition(this):this.parent.type===f.Condition&&(this.parent.declaration.id===Kr.And?this.parent.addToAndGroup(this,i):this.parent.declaration.id===Kr.Or&&this.parent.addToOrGroup(this,i)),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&He(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&He(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=se(this.initialData.declaration,this.project),this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.successCalls=this.initialData.successCalls.map(a=>{const o=se(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=se(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,i),p=this.toMeta();return this.x=i.x!==void 0?i.x:p.x,this.y=i.y!==void 0?i.y:p.y,this.index=i.index!==void 0?i.index:p.index,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):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Yt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Yt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Yt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),e.push(this.parent)):((y=this.parent)==null?void 0:y.type)===f.Condition?this.parent.removeChildGroup(this):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:w}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...w)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:w}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...w)}),this.inputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlat(i)))||[],...this.inputs.flatMap(e=>e.toFlat(i)),...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.calledBy.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatIds(i)))||[],...this.inputs.flatMap(e=>e.toFlatIds(i)),...this.successCalls.flatMap(e=>e.toFlatIds(i)),...this.errorCalls.flatMap(e=>e.toFlatIds(i)),...this.calledBy.flatMap(e=>e.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;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,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(i),andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(p=>p.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(p=>p.toJSON(i)))||null,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),inputs:this.inputs.map(p=>p.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Se){var o,p,e,y,v,E,w;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(),andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(A=>A.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((w=this.orChildrenGroup)==null?void 0:w.map(A=>A.toJSONClone({...i,newId:null})))||null,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toReference(i),andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(y=>y.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(y=>y.toReference(i)))||null,inputs:this.inputs.map(y=>y.toReference(i)),successCalls:this.successCalls.map(y=>y.toReference(i)),errorCalls:this.errorCalls.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatJSON(i)))||[],...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.inputs.flatMap(e=>e.toFlatGenerationTarget(i)),...this.successCalls.flatMap(e=>e.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(o=>o.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(o=>o.clearErrors()),this.inputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),this}validate(){const i=HU(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var F,K,q;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];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=dr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(F=this.andChildrenGroup)==null?void 0:F.map(ie=>ie.clone(i,A,N.UUID.uuid(),p)),V=(K=this.orChildrenGroup)==null?void 0:K.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.andChildrenGroup=$||null,A.orChildrenGroup=V||null;const B=(q=this.inputs)==null?void 0:q.map((ie,W)=>ie.clone(i,A,w+"-input-map-"+W+"-id",p));return A.inputs=B,i==null||i.attemptAutoclose("clone-entity",this.id),A}addToAndGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-to-and-group"))){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),a==null||a.add(i,S.Affected)),a==null||a.attemptAutoclose("add-to-and-group",this.id),this}addToOrGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-to-or-group"))){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),a==null||a.add(i,S.Affected)),a==null||a.attemptAutoclose("add-to-or-group",this.id),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===le.FixedArguments&&!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(B=>{B.index>=A.index&&B.metaSync({index:B.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=se($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};_(Yt,"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,...o)=>null}),_(Yt,"type",f.Condition),_(Yt,"USER_MANAGED_PARENT_TYPES",[...Nr,f.Project,f.Condition]),_(Yt,"PARENT_TYPES",[...Yt.USER_MANAGED_PARENT_TYPES]),_(Yt,"MUTABLE_BASE_PROPERTIES",["operator"]),_(Yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","index"]),_(Yt,"BASE_PROPERTIES",[...Yt.MUTABLE_BASE_PROPERTIES,...Yt.INMUTABLE_BASE_PROPERTIES]),_(Yt,"MUTABLE_META_PROPERTIES",["x","y"]),_(Yt,"INMUTABLE_META_PROPERTIES",[...Yt.INMUTABLE_BASE_PROPERTIES]),_(Yt,"META_PROPERTIES",[...Yt.MUTABLE_META_PROPERTIES,...Yt.INMUTABLE_META_PROPERTIES]),_(Yt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),_(Yt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),_(Yt,"UPSTREAM_PROPERTIES",[...Yt.MUTABLE_UPSTREAM_PROPERTIES,...Yt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup","successCalls","errorCalls","inputsDeclarations","inputs"]),_(Yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Yt,"DOWNSTREAM_PROPERTIES",[...Yt.MUTABLE_DOWNSTREAM_PROPERTIES,...Yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Yt,"PROPERTIES",[...Yt.META_PROPERTIES,...Yt.UPSTREAM_PROPERTIES,...Yt.DOWNSTREAM_PROPERTIES]);let ro=Yt;function WU(d){var o;(o=d.dataType)==null||o.validate(),d.inputs.forEach(p=>p.validate()),d.outputs.forEach(p=>p.validate()),d.internalCalls.forEach(p=>p.validate());const i=[...$a(d),...vo(d),...YU(d),...Pa(d)],a=rb(d);return i.push(...a),Er(d.errors,i)}function YU(d){const i=[...d.project.getVariableDeclarations()].filter(a=>a.id!==d.id);return Hp(d,[xr],i)}const Qhe=Object.freeze(Object.defineProperty({__proto__:null,validate:WU,validateVariableDeclarationName:YU},Symbol.toStringTag,{value:"Module"}));function zU(d){d.inputs.forEach(o=>o.validate()),d.outputs.forEach(o=>o.validate()),d.internalCalls.forEach(o=>o.validate());const i=[...$a(d),...vo(d),...Pa(d)],a=rb(d);return i.push(...a),Er(d.errors,i)}const eye=Object.freeze(Object.defineProperty({__proto__:null,validate:zU},Symbol.toStringTag,{value:"Module"}));var OI=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(OI||{});const xt=class xt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",f.VariableInstance);_(this,"catchesError",!1);_(this,"defaultValue",null);_(this,"writesValues",[]);_(this,"readsValue",null);_(this,"declaration");_(this,"inputs",[]);_(this,"outputs",[]);_(this,"error",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"successCalls",[]);_(this,"errorCalls",[]);_(this,"internalCalls",[]);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);_(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y,this.catchesError=i.catchesError||!1}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.VariableInstance,catchesError:!0,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],error:null,x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const V=J(i.parent);o=a.get(V)}const p=J(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const B=J(V);return a.get(B)}),v=i.calledBySuccess.map(V=>{const B=J(V);return a.get(B)}),E=i.calledByError.map(V=>{const B=J(V);return a.get(B)});let w=null;if(i.readsValue){const V=J(i.readsValue);w=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,catchesError:i.catchesError||!1,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:w,inputs:[],outputs:[],writesValues:[],error:null,x:0,y:0,parent:o},$=se(A,a);return $.setParent(o,null),$}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=ti(o,{parent:{list:!1,types:[...Nr,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return o=e.modifiedData,p.push(...e.errors,...Vr(o)),{errors:p,modifiedData:o}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=Zp(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
79
|
+
If an entity is called by another, they must be in the same scope, which means they have the same parent.`})),{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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.parent.unsubscribeDependents([{entity:this,field:"parent"}]),this}subscribeToDependencies(){var i;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),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 Yt(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.inputs=[...this.inputs],i.declaration=this.declaration,i.andChildrenGroup=this.andChildrenGroup?[...this.andChildrenGroup]:this.andChildrenGroup,i.orChildrenGroup=this.orChildrenGroup?[...this.orChildrenGroup]:this.orChildrenGroup,i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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 Yt(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.inputs=y.inputs,this.declaration=y.declaration,this.andChildrenGroup=y.andChildrenGroup,this.orChildrenGroup=y.orChildrenGroup,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"update-with-shallow-transfer"))){var o,p;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,i.parent){const e=J(i.parent),y=this.project.get(e),v=this.parent;if(v&&v.id!==(y==null?void 0:y.id)&&this.removeFromParent(a),y)this.setParent(y,a),this.addSelfToProject(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 '${e}' 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.declaration){const e=J(i.declaration),y=this.project.get(e);y&&this.setDeclaration(y)}return(o=i.andChildrenGroup)==null||o.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addToAndGroup(v,a),v.setParent(this,a))}),[...this.andChildrenGroup||[]].forEach(e=>{var v;((v=i.andChildrenGroup)==null?void 0:v.find(E=>J(E)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),(p=i.orChildrenGroup)==null||p.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addToOrGroup(v,a),v.setParent(this,a))}),[...this.orChildrenGroup||[]].forEach(e=>{var v;((v=i.orChildrenGroup)==null?void 0:v.find(E=>J(E)===e.id))||(this.removeChildGroup(e,a),e.removeFromParent(a))}),i.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addEntryCaller(v,a),v.addCall(this,a))}),[...this.calledByEntry].forEach(e=>{i.calledByEntry.find(v=>J(v)===e.id)||(this.removeCaller(e,a),e.removeCall(this,a))}),i.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addSuccessCaller(v,a),v.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(e=>{i.calledBySuccess.find(v=>J(v)===e.id)||(this.removeCaller(e,a),e.removeCall(this,a))}),i.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&(this.addErrorCaller(v,a),v.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(e=>{i.calledBySuccess.find(v=>J(v)===e.id)||(this.removeCaller(e,a),e.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(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.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E}=this.syncInputs(i);return a.push(...y),o.push(...v),p.push(...E),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project?this.project.addCondition(this):this.parent.type===f.Condition&&(this.parent.declaration.id===Kr.And?this.parent.addToAndGroup(this,i):this.parent.declaration.id===Kr.Or&&this.parent.addToOrGroup(this,i)),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i){return this}removeOutput(i){return this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&He(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&He(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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}removeChildGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-child-group"))){if(this.andChildrenGroup){const o=this.andChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.andChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}if(this.orChildrenGroup){const o=this.orChildrenGroup.findIndex(p=>p.id===i.id);o!==-1&&(this.orChildrenGroup.splice(o,1),a==null||a.add(this,S.Updated))}return a==null||a.attemptAutoclose("remove-child-group",this.id),this}setDeclaration(i){return this.declaration=i,this}initChildren(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=se(this.initialData.declaration,this.project),this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o})),this.successCalls=this.initialData.successCalls.map(a=>{const o=se(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=se(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.inputs=this.initialData.inputs.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,i),p=this.toMeta();return this.x=i.x!==void 0?i.x:p.x,this.y=i.y!==void 0?i.y:p.y,this.index=i.index!==void 0?i.index:p.index,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):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Yt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Yt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Yt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Yt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Yt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Yt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){var y;const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeCondition(this),e.push(this.parent)):((y=this.parent)==null?void 0:y.type)===f.Condition?this.parent.removeChildGroup(this):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(v=>{const{removed:E,updated:w}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...w)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(v=>{const{removed:E,updated:w}=v.remove({ignoreUpstream:!0},a);p.push(...E),o.push(...w)}),this.inputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.andChildrenGroup&&this.andChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.orChildrenGroup&&this.orChildrenGroup.forEach(y=>{const{updated:v,added:E}=y.restore({},i);o.push(...v),a.push(...E)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),this.parent.type===f.Project&&this.project.addCondition(this),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlat(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlat(i)))||[],...this.inputs.flatMap(e=>e.toFlat(i)),...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.calledBy.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatIds(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatIds(i)))||[],...this.inputs.flatMap(e=>e.toFlatIds(i)),...this.successCalls.flatMap(e=>e.toFlatIds(i)),...this.errorCalls.flatMap(e=>e.toFlatIds(i)),...this.calledBy.flatMap(e=>e.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o;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,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(i),andChildrenGroup:((a=this.andChildrenGroup)==null?void 0:a.map(p=>p.toJSON(i)))||null,orChildrenGroup:((o=this.orChildrenGroup)==null?void 0:o.map(p=>p.toJSON(i)))||null,successCalls:this.successCalls.map(p=>p.toJSON(i)),errorCalls:this.errorCalls.map(p=>p.toJSON(i)),calledBySuccess:this.calledBySuccess.map(p=>p.toReference()),calledByError:this.calledByError.map(p=>p.toReference()),calledByEntry:this.calledByEntry.map(p=>p.toReference()),inputs:this.inputs.map(p=>p.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=Se){var o,p,e,y,v,E,w;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toJSON(),andChildrenGroup:((E=this.andChildrenGroup)==null?void 0:E.map(A=>A.toJSONClone({...i,newId:null})))||null,orChildrenGroup:((w=this.orChildrenGroup)==null?void 0:w.map(A=>A.toJSONClone({...i,newId:null})))||null,successCalls:this.successCalls.map(A=>A.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map(A=>A.toJSONClone({...i,newId:null})),calledBySuccess:this.calledBySuccess.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map(A=>A.toReference({seenEntityMaps:i.seenEntityMaps})),inputs:this.inputs.map(A=>A.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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,index:this.index,x:this.x,y:this.y,declaration:this.declaration.toReference(i),andChildrenGroup:((p=this.andChildrenGroup)==null?void 0:p.map(y=>y.toReference(i)))||null,orChildrenGroup:((e=this.orChildrenGroup)==null?void 0:e.map(y=>y.toReference(i)))||null,inputs:this.inputs.map(y=>y.toReference(i)),successCalls:this.successCalls.map(y=>y.toReference(i)),errorCalls:this.errorCalls.map(y=>y.toReference(i)),calledBySuccess:this.calledBySuccess.map(y=>y.toReference(i)),calledByError:this.calledByError.map(y=>y.toReference(i)),calledByEntry:this.calledByEntry.map(y=>y.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatJSON(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatJSON(i)))||[],...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.andChildrenGroup)==null?void 0:o.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...((p=this.orChildrenGroup)==null?void 0:p.flatMap(e=>e.toFlatGenerationTarget(i)))||[],...this.inputs.flatMap(e=>e.toFlatGenerationTarget(i)),...this.successCalls.flatMap(e=>e.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(e=>e.toFlatGenerationTarget(i))])}clearErrors(){var i,a;return this.errors=[],(i=this.andChildrenGroup)==null||i.forEach(o=>o.clearErrors()),(a=this.orChildrenGroup)==null||a.forEach(o=>o.clearErrors()),this.inputs.forEach(o=>o.clearErrors()),this.successCalls.forEach(o=>o.clearErrors()),this.errorCalls.forEach(o=>o.clearErrors()),this}validate(){const i=HU(this);return this.errors=i,{success:!0}}getErrors(){return[...this.errors,...this.inputs.flatMap(a=>a.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var F,K,q;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[];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=dr(y,e);a?A.setParent(a,null):A.setParent(this.parent,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(F=this.andChildrenGroup)==null?void 0:F.map(ie=>ie.clone(i,A,N.UUID.uuid(),p)),V=(K=this.orChildrenGroup)==null?void 0:K.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.andChildrenGroup=$||null,A.orChildrenGroup=V||null;const B=(q=this.inputs)==null?void 0:q.map((ie,W)=>ie.clone(i,A,w+"-input-map-"+W+"-id",p));return A.inputs=B,i==null||i.attemptAutoclose("clone-entity",this.id),A}addToAndGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-to-and-group"))){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(i)||(this.andChildrenGroup.push(i),a==null||a.add(i,S.Affected)),a==null||a.attemptAutoclose("add-to-and-group",this.id),this}addToOrGroup(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-to-or-group"))){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(i)||(this.orChildrenGroup.push(i),a==null||a.add(i,S.Affected)),a==null||a.attemptAutoclose("add-to-or-group",this.id),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-inputs"))){const a=[],o=[],p=[],e=[];return this.inputs.forEach(v=>{if(!this.declaration.inputs.find(w=>{var A;return w.id===((A=v.declaration)==null?void 0:A.id)})){const w=v.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),this.inputs.filter((v,E)=>{const w=this.inputs.findIndex($=>$.declaration===v.declaration&&$!==v);if(w===-1)return!1;const A=this.inputs[w];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>w:!!L(A==null?void 0:A.createdAt).isAfter(v.createdAt)}).forEach(v=>{const E=v.remove({ignoreUpstream:!1},i);p.push(...E.removed),a.push(...E.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const a=[],o=[],p=[],e=[],y=this.declaration.inputs.filter(A=>A.parentRelationType===le.FixedArguments&&!this.inputs.find($=>$.declaration.id===A.id));this.inputs.sort((A,$)=>A.index-$.index),y.forEach(A=>{this.inputs.forEach(B=>{B.index>=A.index&&B.metaSync({index:B.index+1},i)});const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,declaration:A.toJSON(),readsValue:null,defaultValue:null,index:A.index,name:null,codeName:null,description:null,parent:this.toReference()},V=se($,this.project);V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),V.addSelfToProject(i)}),this.inputs.sort((A,$)=>A.index-$.index);const{updated:v,added:E,removed:w}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...w),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return[]}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return[]}};_(Yt,"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,...o)=>null}),_(Yt,"type",f.Condition),_(Yt,"USER_MANAGED_PARENT_TYPES",[...Nr,f.Project,f.Condition]),_(Yt,"PARENT_TYPES",[...Yt.USER_MANAGED_PARENT_TYPES]),_(Yt,"MUTABLE_BASE_PROPERTIES",["operator"]),_(Yt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion","index"]),_(Yt,"BASE_PROPERTIES",[...Yt.MUTABLE_BASE_PROPERTIES,...Yt.INMUTABLE_BASE_PROPERTIES]),_(Yt,"MUTABLE_META_PROPERTIES",["x","y"]),_(Yt,"INMUTABLE_META_PROPERTIES",[...Yt.INMUTABLE_BASE_PROPERTIES]),_(Yt,"META_PROPERTIES",[...Yt.MUTABLE_META_PROPERTIES,...Yt.INMUTABLE_META_PROPERTIES]),_(Yt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),_(Yt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),_(Yt,"UPSTREAM_PROPERTIES",[...Yt.MUTABLE_UPSTREAM_PROPERTIES,...Yt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Yt,"MUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup","successCalls","errorCalls","inputsDeclarations","inputs"]),_(Yt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Yt,"DOWNSTREAM_PROPERTIES",[...Yt.MUTABLE_DOWNSTREAM_PROPERTIES,...Yt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Yt,"PROPERTIES",[...Yt.META_PROPERTIES,...Yt.UPSTREAM_PROPERTIES,...Yt.DOWNSTREAM_PROPERTIES]);let ro=Yt;function WU(d){var o;(o=d.dataType)==null||o.validate(),d.inputs.forEach(p=>p.validate()),d.outputs.forEach(p=>p.validate()),d.internalCalls.forEach(p=>p.validate());const i=[...$a(d),...vo(d),...YU(d),...Pa(d)],a=rb(d);return i.push(...a),Er(d.errors,i)}function YU(d,u){const a=[...d.project.getVariableDeclarations()].filter(o=>o.id!==d.id);return Hp(d,[xr],a,u)}const Qhe=Object.freeze(Object.defineProperty({__proto__:null,validate:WU,validateVariableDeclarationName:YU},Symbol.toStringTag,{value:"Module"}));function zU(d){d.inputs.forEach(o=>o.validate()),d.outputs.forEach(o=>o.validate()),d.internalCalls.forEach(o=>o.validate());const i=[...$a(d),...vo(d),...Pa(d)],a=rb(d);return i.push(...a),Er(d.errors,i)}const eye=Object.freeze(Object.defineProperty({__proto__:null,validate:zU},Symbol.toStringTag,{value:"Module"}));var OI=(d=>(d.Parent="parent",d.DataTypeEntity="data-type-entity",d.VarDeclaration="var-declaration",d))(OI||{});const xt=class xt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",f.VariableInstance);_(this,"catchesError",!1);_(this,"defaultValue",null);_(this,"writesValues",[]);_(this,"readsValue",null);_(this,"declaration");_(this,"inputs",[]);_(this,"outputs",[]);_(this,"error",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"successCalls",[]);_(this,"errorCalls",[]);_(this,"internalCalls",[]);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);_(this,"_codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y,this.catchesError=i.catchesError||!1}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.VariableInstance,catchesError:!0,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],error:null,x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const V=J(i.parent);o=a.get(V)}const p=J(i.declaration),e=a.get(p),y=i.calledByEntry.map(V=>{const B=J(V);return a.get(B)}),v=i.calledBySuccess.map(V=>{const B=J(V);return a.get(B)}),E=i.calledByError.map(V=>{const B=J(V);return a.get(B)});let w=null;if(i.readsValue){const V=J(i.readsValue);w=a.get(V)}const A={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableInstance,catchesError:i.catchesError||!1,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:w,inputs:[],outputs:[],writesValues:[],error:null,x:0,y:0,parent:o},$=se(A,a);return $.setParent(o,null),$}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=ti(o,{parent:{list:!1,types:[...Nr,f.Project],optional:!0},declaration:{list:!1,types:[f.VariableDeclaration]}},a);return o=e.modifiedData,p.push(...e.errors,...Vr(o)),{errors:p,modifiedData:o}}get codeName(){var i;return(i=this.declaration)==null?void 0:i.codeName}get codeNativeValueValidation(){var i;return this._codeNativeValueValidation||((i=this.declaration)==null?void 0:i.codeNativeValueValidation)||null}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=Zp(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
80
80
|
If an entity is called by another, they must be in the same scope, which means they have the same parent.
|
|
81
81
|
Specifically for variables, their scope is also calculated from their value readers and value writters.
|
|
82
82
|
You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`})),{errors:a,modifiedData:o}}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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:w,removed:A}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];if(a==="parent"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}if(a==="var-declaration"){const{updated:E,added:w,removed:A}=this.restore({},o);p.push(...E),e.push(...w),y.push(...A)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a,o,p,e,y,v;return(a=(i=this.parent)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"parent"}]),(e=(p=(o=this.declaration.dataType)==null?void 0:o.entity)==null?void 0:p.unsubscribeDependents)==null||e.call(p,[{entity:this,field:"data-type-entity"}]),(v=(y=this.declaration)==null?void 0:y.unsubscribeDependents)==null||v.call(y,[{entity:this,field:"var-declaration"}]),this}subscribeToDependencies(){var i,a,o,p;return(i=this.parent)==null||i.subscribeDependents([{entity:this,field:"parent"}]),(p=(o=(a=this.declaration.dataType)==null?void 0:a.entity)==null?void 0:o.subscribeDependents)==null||p.call(o,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),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 xt(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.inputs=[...this.inputs],i.outputs=[...this.outputs],i.internalCalls=[...this.internalCalls],i.successCalls=[...this.successCalls],i.errorCalls=[...this.errorCalls],i.writesValues=[...this.writesValues],i.readsValue=this.readsValue,i.defaultValue=this.defaultValue,i.declaration=this.declaration,i.calledBySuccess=[...this.calledBySuccess],i.calledByError=[...this.calledByError],i.calledByEntry=[...this.calledByEntry],i.error=this.error,i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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 xt(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.inputs=y.inputs,this.outputs=y.outputs,this.internalCalls=y.internalCalls,this.successCalls=y.successCalls,this.errorCalls=y.errorCalls,this.writesValues=y.writesValues,this.readsValue=y.readsValue,this.defaultValue=y.defaultValue,this.declaration=y.declaration,this.calledBySuccess=y.calledBySuccess,this.calledByError=y.calledByError,this.calledByEntry=y.calledByEntry,this.error=y.error,this.parent=y.parent,{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(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 o=J(i.parent),p=this.project.get(o),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 '${o}' 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.readsValue){const o=J(i.readsValue),p=this.project.get(o),e=this.readsValue;e&&e.id!==(p==null?void 0:p.id)&&this.removeValueWriter(a),p&&this.setValueWriter(p,a)}if(i.declaration){const o=J(i.declaration),p=this.project.get(o);p&&this.setDeclaration(p)}return i.calledByEntry.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addEntryCaller(e,a),e.addCall(this,a))}),[...this.calledByEntry].forEach(o=>{i.calledByEntry.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledBySuccess.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addSuccessCaller(e,a),e.addSuccessCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),i.calledByError.forEach(o=>{const p=J(o),e=this.project.get(p);e&&(this.addErrorCaller(e,a),e.addErrorCall(this,a))}),[...this.calledBySuccess].forEach(o=>{i.calledBySuccess.find(e=>J(e)===o.id)||(this.removeCaller(o,a),o.removeCall(this,a))}),this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),this}hydrateAncestors(){const i=[],a=[],o=[],p=[];if(this.initialData.parent){const e=J(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'`);if(this.initialData.readsValue){const e=J(this.initialData.readsValue),y=this.project.get(e);y&&(this.setValueWriter(y,null),i.push(y))}if(this.initialData.declaration){const e=J(this.initialData.declaration),y=this.project.get(e);y&&(this.setDeclaration(y),i.push(y))}return this.initialData.calledByEntry.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addEntryCaller(v,null)}),this.initialData.calledBySuccess.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addSuccessCaller(v,null)}),this.initialData.calledByError.forEach(e=>{const y=J(e),v=this.project.get(y);v&&this.addErrorCaller(v,null)}),{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){var Ce;const a=[],o=[],p=[],e=[];if(this.initialized=!0,!this.declaration.dataType||(Ce=this.declaration.dataType)!=null&&Ce.inferred){const{added:$e,updated:qe,removed:xe,affected:ot}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(i);o.push(...$e),a.push(...qe),p.push(...xe),e.push(...ot)}const{added:y,updated:v,removed:E,affected:w}=this.syncInputs(i);o.push(...y),a.push(...v),p.push(...E),e.push(...w);const{added:A,updated:$,removed:V,affected:B}=this.syncOutputs(i);o.push(...A),a.push(...$),p.push(...V),e.push(...B);const{added:F,updated:K,removed:q,affected:ie}=this.generateUnusedInternalCalls(i);o.push(...F),a.push(...K),p.push(...q),e.push(...ie);const{added:W,updated:de,removed:Q,affected:ce}=this.removeUnrecognizedInputs(i);o.push(...W),a.push(...de),p.push(...Q),e.push(...ce);const{added:X,updated:z,removed:pe,affected:te}=this.removeUnrecognizedOutputs(i);o.push(...X),a.push(...z),p.push(...pe),e.push(...te);const{added:ue,updated:Ie,removed:Ue,affected:Pe}=this.removeUnrecognizedInternalCalls(i);return o.push(...ue),a.push(...Ie),p.push(...Ue),e.push(...Pe),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],p=[],e=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,i),a.push(this.readsValue)),this.writesValues.forEach(y=>{y.setValueWriter(this,i),a.push(y)}),this.successCalls.forEach(y=>{y.addSuccessCaller(this,i),a.push(y)}),this.errorCalls.forEach(y=>{y.addErrorCaller(this,i),a.push(y)}),this.calledBySuccess.forEach(y=>{y.addSuccessCall(this,i),a.push(y)}),this.calledByError.forEach(y=>{y.addErrorCall(this,i),a.push(y)}),this.calledByEntry.forEach(y=>{y.addCall(this,i),a.push(y)}),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(i=>i.readsValue||i.defaultValue)}get unusedInputs(){return this.inputs.filter(i=>!i.readsValue&&!i.defaultValue)}get usedOutputs(){return this.outputs.filter(i=>i.writesValues.length)}get unusedOutputs(){return this.outputs.filter(i=>!i.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(i=>!!i.calledBy.length)}get unusedInternalCalls(){const i=this.usedInternalCalls;return this.internalCalls.filter(o=>!(i.find(y=>y.id===o.id)||i.find(y=>y.declaration===o.declaration)))}removeInternalCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-variable-instance-internal-call"))){const o=this.internalCalls.findIndex(p=>p.id===i.id);return o>-1&&(this.internalCalls.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-variable-instance-internal-call",this.id),this}removeInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-input",this.id),this}addInput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input",this.id),this):(this.inputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-input",this.id),this)}addOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-output"))){return this.outputs.includes(i)?(a==null||a.attemptAutoclose("add-output",this.id),this):(this.outputs.push(i),a==null||a.add(this,S.Affected),a==null||a.attemptAutoclose("add-output",this.id),this)}removeOutput(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-output"))){const o=this.outputs.findIndex(p=>p.id===i.id);return o>-1&&(this.outputs.splice(o,1),a&&(a==null||a.add(this,S.Affected))),a==null||a.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-caller")),o=!1){return this.calledBySuccess.find(p=>p.id===i.id)||(this.calledBySuccess.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-caller")),o=!1){return this.calledByError.find(p=>p.id===i.id)||(this.calledByError.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-error-caller",this.id),this}addEntryCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-entry-caller")),o=!1){return this.calledByEntry.find(p=>p.id===i.id)||(this.calledByEntry.push(i),a==null||a.add(this,S.Updated),o&&He(this,a)),a==null||a.attemptAutoclose("add-entry-caller",this.id),this}addErrorCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-error-call")),o=!1){return this.errorCalls.find(p=>p.id===i.id)||(this.errorCalls.push(i),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-success-call")),o=!1){return this.successCalls.find(p=>p.id===i.id)||(this.successCalls.push(i),o&&He(this,a),a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("add-success-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call")),o=!1){const p=this.successCalls.findIndex(y=>y.id===i.id);p>-1&&(this.successCalls.splice(p,1),a==null||a.add(this,S.Affected));const e=this.errorCalls.findIndex(y=>y.id===i.id);return e>-1&&(this.errorCalls.splice(e,1),a==null||a.add(this,S.Affected)),o&&He(this,a),a==null||a.attemptAutoclose("remove-call",this.id),this}removeCaller(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-caller")),o=!1){return this.calledBySuccess=this.calledBySuccess.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByError=this.calledByError.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),this.calledByEntry=this.calledByEntry.filter(p=>p.id!==i.id?!0:(a==null||a.add(this,S.Updated),a==null||a.add(p,S.Affected),!1)),o&&He(this,a),a==null||a.attemptAutoclose("remove-caller",this.id),this}addValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(i)?(a==null||a.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(i),a==null||a.add(this,S.Affected),this)}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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}initChildren(i=this.project.addChangeSet(new G(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=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.declaration.type===f.GenericReference){const a=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!a)return this;this.declaration=a}else this.declaration=se(this.initialData.declaration,this.project),this.declaration.initChildren(i);return nf.initWritesValues(this,this.parent),sf.initReadsValue(this),this.initialData.inputs.forEach(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),this.addInput(o,null),o}),this.initialData.outputs.forEach(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),this.addOutput(o,i),o}),this.successCalls=this.initialData.successCalls.map(a=>{const o=se(a,this.project);if(o.addSuccessCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.errorCalls=this.initialData.errorCalls.map(a=>{const o=se(a,this.project);if(o.addErrorCaller(this),[f.BreakStatement,f.ContinueStatement].includes(o.type))o.setParent(this.parent.parent,null),o.initChildren(i);else if(o.type===f.ReturnStatement){const p=Hr(this,this.project);o.setParent(p,null),o.initChildren(i)}else o.type!==f.InternalCall&&(o.setParent(this.parent,null),o.initChildren(i));return o}),this.internalCalls=this.initialData.internalCalls.reduce((a,o)=>{if(o.type===f.GenericReference){const p=this.project.findSubscribedInstanceFromReference(o);if(!p)return a;const e=p;return e.setParent(this,null),[...a,e]}else{const p=se(o,this.project);return p.setParent(this,null),p.initChildren(i),[...a,p]}},[]),this.initialData.error&&(this.error=se(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(i)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this}setValueWriter(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==i&&(this.readsValue=i,a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,i==null||i.add(this,S.Updated)),i==null||i.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(i)?(this.writesValues=this.writesValues.filter(o=>o.id!==i.id),a==null||a.add(this,S.Affected),this):(a==null||a.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(this,i),p=this.toMeta();return this.x=i.x||p.x,this.y=i.y||p.y,this.catchesError=i.catchesError!==void 0?i.catchesError:this.catchesError,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):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await xt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await xt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await xt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await xt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await xt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await xt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],p=[],e=[];return this.parent.type===f.Project?(this.parent.removeVariableInstance(this),e.push(this.parent)):this.parent.detachedChildren.includes(this)&&this.parent.unsubscribeDetachedChild(this),i==null||i.attemptAutoclose("remove-from-parent",this.id),{added:R(p),updated:R(a),removed:R(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.readsValue&&(o.push(this.readsValue),this.readsValue.removeValueReader(this,a)),this.writesValues.forEach(v=>{o.push(v),v.setValueWriter(null,a)}),this.inputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.outputs.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.successCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.errorCalls.forEach(v=>{o.push(v),v.removeCaller(this,a)}),this.internalCalls.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.push(...v.updated),p.push(...v.removed),y.push(...v.affected),this.calledBy.forEach(E=>{o.push(E),E.removeCall(this,a)})}return a==null||a.attemptAutoclose("remove-entity",this.id),{added:R(e),updated:R(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}return this.readsValue&&(o.push(this.readsValue),this.readsValue.addValueReader(this,i)),this.writesValues.forEach(y=>{o.push(y),y.setValueWriter(this,i)}),this.inputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.outputs.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.successCalls.forEach(y=>{o.push(y),y.addSuccessCaller(this,i)}),this.errorCalls.forEach(y=>{o.push(y),y.addErrorCaller(this,i)}),this.internalCalls.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.calledBySuccess.forEach(y=>{o.push(y),y.addSuccessCall(this,i)}),this.calledByError.forEach(y=>{o.push(y),y.addErrorCall(this,i)}),this.calledByEntry.forEach(y=>{o.push(y),y.addCall(this,i)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...this.writesValues.flatMap(e=>e.toFlat(i)),...((p=this.readsValue)==null?void 0:p.toFlat(i))||[],...this.successCalls.flatMap(e=>e.toFlat(i)),...this.errorCalls.flatMap(e=>e.toFlat(i)),...this.inputs.flatMap(e=>e.toFlat(i)),...this.outputs.flatMap(e=>e.toFlat(i)),...this.internalCalls.flatMap(e=>e.toFlat(i))])}toFlatIds(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.toFlatIds(i))||[],...this.writesValues.flatMap(p=>p.toFlatIds(i)),...this.successCalls.flatMap(p=>p.toFlatIds(i)),...this.errorCalls.flatMap(p=>p.toFlatIds(i)),...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.outputs.flatMap(p=>p.toFlatIds(i)),...this.internalCalls.flatMap(p=>p.toFlatIds(i))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,catchesError:this.catchesError,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(i=new Set){var a,o,p;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,catchesError:this.catchesError,type:this.type,declaration:this.declaration.toJSON(i),defaultValue:((a=this.defaultValue)==null?void 0:a.toJSON(i))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference())||null,writesValues:this.writesValues.map(e=>e.toJSON(i)),inputs:this.inputs.map(e=>e.toJSON(i)),outputs:this.outputs.map(e=>e.toJSON(i)),successCalls:this.successCalls.map(e=>e.toJSON(i)),errorCalls:this.errorCalls.map(e=>e.toJSON(i)),internalCalls:this.internalCalls.map(e=>e.toJSON(i)),calledBySuccess:this.calledBySuccess.map(e=>e.toReference()),calledByError:this.calledByError.map(e=>e.toReference()),calledByEntry:this.calledByEntry.map(e=>e.toReference()),parent:this.parent.toReference(),error:((p=this.error)==null?void 0:p.toJSON(i))||null,x:this.x,y:this.y})}toJSONClone(i=Se){var o,p,e,y,v,E,w,A;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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(),previousVersion:null,author:this.author,deleted:this.deleted,catchesError:this.catchesError,type:this.type,defaultValue:((E=this.defaultValue)==null?void 0:E.toJSONClone({...i,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:i.seenEntityMaps}),readsValue:((w=this.readsValue)==null?void 0:w.toReference({seenEntityMaps:i.seenEntityMaps}))||null,writesValues:this.writesValues.map($=>$.toJSONClone({...i,newId:null})),inputs:this.inputs.map($=>$.toJSONClone({...i,newId:null})),outputs:this.outputs.map($=>$.toJSONClone({...i,newId:null})),successCalls:this.successCalls.map($=>$.toJSONClone({...i,newId:null})),errorCalls:this.errorCalls.map($=>$.toJSONClone({...i,newId:null})),internalCalls:this.internalCalls.map($=>this.calledBy.length||this.readsValue?$.toJSONClone({...i,newId:null}):$.toReference({seenEntityMaps:i.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map($=>$.toReference({seenEntityMaps:i.seenEntityMaps})),calledByError:this.calledByError.map($=>$.toReference({seenEntityMaps:i.seenEntityMaps})),calledByEntry:this.calledByEntry.map($=>$.toReference({seenEntityMaps:i.seenEntityMaps})),error:((A=this.error)==null?void 0:A.toJSONClone({...i,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps}),x:this.x,y:this.y})}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e,y,v;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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,catchesError:this.catchesError,type:this.type,x:this.x,y:this.y,defaultValue:((p=this.defaultValue)==null?void 0:p.toReference(i))||null,declaration:((e=this.declaration)==null?void 0:e.toReference(i))||null,readsValue:((y=this.readsValue)==null?void 0:y.toReference(i))||null,writesValues:this.writesValues.map(E=>E.toReference(i)),inputs:this.inputs.map(E=>E.toReference(i)),outputs:this.outputs.map(E=>E.toReference(i)),successCalls:this.successCalls.map(E=>E.toReference(i)),errorCalls:this.errorCalls.map(E=>E.toReference(i)),calledBySuccess:this.calledBySuccess.map(E=>E.toReference(i)),calledByError:this.calledByError.map(E=>E.toReference(i)),calledByEntry:this.calledByEntry.map(E=>E.toReference(i)),internalCalls:this.internalCalls.map(E=>E.toReference(i)),error:((v=this.error)==null?void 0:v.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.toFlatJSON(i))||[],...((p=this.declaration)==null?void 0:p.toFlatJSON(i))||[],...this.writesValues.flatMap(e=>e.toFlatJSON(i)),...this.successCalls.flatMap(e=>e.toFlatJSON(i)),...this.errorCalls.flatMap(e=>e.toFlatJSON(i)),...this.inputs.flatMap(e=>e.toFlatJSON(i)),...this.outputs.flatMap(e=>e.toFlatJSON(i)),...this.internalCalls.flatMap(e=>e.toFlatJSON(i)),...this.calledBy.flatMap(e=>e.toFlatJSON(i))])}toGenerationTarget(){const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(a=>a.id),calledBySuccess:this.calledBySuccess.map(a=>a.id),calledByError:this.calledByError.map(a=>a.id),parent:i}}toFlatGenerationTarget(i=new Set){var o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.toFlatGenerationTarget(i))||[],...((p=this.declaration)==null?void 0:p.toFlatGenerationTarget(i))||[],...((e=this.readsValue)==null?void 0:e.toFlatGenerationTarget(i))||[],...this.writesValues.flatMap(y=>y.toFlatGenerationTarget(i)),...this.successCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.errorCalls.flatMap(y=>y.toFlatGenerationTarget(i)),...this.inputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.outputs.flatMap(y=>y.toFlatGenerationTarget(i)),...this.internalCalls.flatMap(y=>y.toFlatGenerationTarget(i))])}clearErrors(){var i;return this.errors=[],(i=this.defaultValue)==null||i.clearErrors(),this.inputs.forEach(a=>a.clearErrors()),this.outputs.forEach(a=>a.clearErrors()),this.successCalls.forEach(a=>a.clearErrors()),this.errorCalls.forEach(a=>a.clearErrors()),this.internalCalls.forEach(a=>a.clearErrors()),this}validate(){const i=zU(this);return this.errors=i,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...this.inputs.flatMap(p=>p.getErrors()),...this.internalCalls.flatMap(p=>p.getErrors()),...this.outputs.flatMap(p=>p.getErrors()),...((o=this.readsValue)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var i;return this.defaultValue||((i=this.declaration)==null?void 0:i.defaultValue)||null}setDefaultValue(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.remove({ignoreUpstream:!0},a),this.defaultValue=i,a==null||a.add(this,S.Affected)),a==null||a.attemptAutoclose("set-default-value",this.id),this}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var B,F,K,q;let e=Ur(a,this);const y=this.toJSON(),v=o||N.UUID.uuid();y.inputs=[],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 E=dr(y,e);a?E.setParent(a,null):E.setParent(this.parent,null),p&&E.subscribe(),E.initChildren(i),i==null||i.add(E,S.Added);const w=(B=this.defaultValue)==null?void 0:B.clone(i,E,N.UUID.uuid(),p);E.defaultValue=w||null;const A=(F=this.inputs)==null?void 0:F.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.inputs=A;const $=(K=this.outputs)==null?void 0:K.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));E.outputs=$;const V=(q=this.internalCalls)==null?void 0:q.map(ie=>ie.clone(i,E,N.UUID.uuid(),p));return E.internalCalls=V,i==null||i.attemptAutoclose("clone-entity",this.id),E}addInternalCall(i){return this.internalCalls.find(a=>a===i)||this.internalCalls.push(i),this}setDeclaration(i){return this.declaration!==i&&(this.declaration=i),this}removeUnrecognizedInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-inputs"))){const a=[],o=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.inputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.inputs].forEach(y=>{var E;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-instance-outputs"))){const a=[],o=[],p=[],e=[];return this.declaration.dataType&&!this.declaration.dataType.isObject()?[...this.outputs].forEach(y=>{const v=y.remove({ignoreUpstream:!1},i);p.push(...v.removed),a.push(...v.updated)}):this.declaration.dataType&&this.declaration.dataType.hasStrictObjectStructure()&&[...this.outputs].forEach(y=>{var E;if(!y.declaration){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated);return}if(![...((E=this.declaration.dataType)==null?void 0:E.entity).allProperties].find(w=>y.declaration===w)){const w=y.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}}),i==null||i.attemptAutoclose("remove-unrecognized-variable-instance-outputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedInternalCalls(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-variable-declaration-internal-calls"))){var v;const a=[],o=[],p=[],e=[];if(!this.declaration.dataType||!this.declaration.dataType.entity||![f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type))[...this.internalCalls].forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)});else if(this.declaration.dataType&&this.declaration.dataType.entity&&[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const E=[...((v=this.declaration.dataType)==null?void 0:v.entity).allMethods];[...this.internalCalls].forEach(w=>{if(!w.declaration){const $=w.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}if(!E.find($=>w.declaration===$)){const $=w.remove({ignoreUpstream:!1},i);p.push(...$.removed),a.push(...$.updated);return}})}return this.internalCalls.filter((E,w)=>{const A=this.internalCalls.findIndex(V=>V.declaration===E.declaration&&V!==E);if(A===-1)return!1;const $=this.internalCalls[A];return L($==null?void 0:$.createdAt).isSame(L(E.createdAt))?w>A:!!L($==null?void 0:$.createdAt).isAfter(E.createdAt)}).forEach(E=>{const w=E.remove({ignoreUpstream:!1},i);p.push(...w.removed),a.push(...w.updated)}),i==null||i.attemptAutoclose("remove-unrecognized-variable-declaration-internal-calls",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncInputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-inputs"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList){const y=[...this.declaration.dataType.entity.properties];y.filter(A=>!A.getDataType(i)).forEach(A=>{const $=this.inputs.find(F=>Y(F,this.project)===Y(A,this.project));if(!$)return;const V=this.declaration.getMasterInputWithValueWritterFromAllInstances($);if(!V)return;const B=pn(V);A.setDataType(B,i),$.setDeclaration(A,i)}),y.filter(A=>!this.inputs.find($=>{var V;return((V=$.declaration)==null?void 0:V.id)===A.id})).forEach(A=>{const $={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.InputMap,parent:this.toReference(),name:null,description:null,codeName:null,declaration:A,defaultValue:null,index:A.index,readsValue:null},V=se($,this.project);return V.setParent(this,i),V.initChildren(i),i==null||i.add(V,S.Added),this.addInput(V,i),V}),this.inputs.filter(A=>!A.declaration).forEach(A=>{const $=y.find(V=>Y(V,this.project)===Y(A,this.project));$&&A.setDeclaration($,i)})}}else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-inputs",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}syncOutputs(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-variable-instance-outputs"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.properties].filter(E=>!this.outputs.find(w=>w.declaration===E)).map(E=>{const w={id:N.UUID.uuid(),version:N.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.OutputMap,parent:this.toReference(),defaultValue:null,declaration:E,index:E.index,writesValues:[]},A=se(w,this.project);return A.setParent(this,i),A.initChildren(i),i==null||i.add(A,S.Added),this.addOutput(A,i),A});else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("sync-variable-instance-outputs",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}generateUnusedInternalCalls(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"generate-unused-internal-calls"))){const a=[],o=[],p=[],e=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[f.DefinitionEntity,f.PrimitiveEntity,f.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&!this.declaration.dataType.isList&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(E=>!this.internalCalls.find(A=>{var V,B,F,K,q;return(((V=A.declaration)==null?void 0:V.id)||((F=(B=A.initialData)==null?void 0:B.declaration)==null?void 0:F.entityId)||((q=(K=A.initialData)==null?void 0:K.declaration)==null?void 0:q.id))===E.id})).map(E=>{const w=E.createInternalCall(i,this);return i==null||i.add(w,S.Added),this.addInternalCall(w),w});else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return i==null||i.attemptAutoclose("generate-unused-internal-calls",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this}}getDataType(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"get-data-type"))){var a;return((a=this.declaration)==null?void 0:a.getDataType(i))||null}getUnusedInputs(){return this.inputs.filter(i=>i.suggestion||!i.readsValue&&!i.defaultValue)}getUnusedOutputs(){return this.outputs.filter(i=>i.suggestion||!i.writesValues.length)}getUsedInputs(){return this.inputs.filter(i=>!i.suggestion&&(i.readsValue||i.defaultValue))}getUsedOutputs(){return this.outputs.filter(i=>!i.suggestion&&i.writesValues.length)}};_(xt,"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,...o)=>null}),_(xt,"type",f.VariableInstance),_(xt,"USER_MANAGED_PARENT_TYPES",[...Nr,f.Project]),_(xt,"PARENT_TYPES",[...xt.USER_MANAGED_PARENT_TYPES]),_(xt,"MUTABLE_BASE_PROPERTIES",["catchesError"]),_(xt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(xt,"BASE_PROPERTIES",[...xt.MUTABLE_BASE_PROPERTIES,...xt.INMUTABLE_BASE_PROPERTIES]),_(xt,"MUTABLE_META_PROPERTIES",[...xt.MUTABLE_BASE_PROPERTIES,"x","y"]),_(xt,"INMUTABLE_META_PROPERTIES",[...xt.INMUTABLE_BASE_PROPERTIES]),_(xt,"META_PROPERTIES",[...xt.MUTABLE_META_PROPERTIES,...xt.INMUTABLE_META_PROPERTIES]),_(xt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),_(xt,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),_(xt,"UPSTREAM_PROPERTIES",[...xt.MUTABLE_UPSTREAM_PROPERTIES,...xt.INMUTABLE_UPSTREAM_PROPERTIES]),_(xt,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),_(xt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(xt,"DOWNSTREAM_PROPERTIES",[...xt.MUTABLE_DOWNSTREAM_PROPERTIES,...xt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(xt,"PROPERTIES",[...xt.META_PROPERTIES,...xt.UPSTREAM_PROPERTIES,...xt.DOWNSTREAM_PROPERTIES]);let io=xt;var XU=(d=>(d.Parent="parent",d.DataTypeEntity="variable-data-type-entity",d.DataType="variable-data-type",d))(XU||{});const jt=class jt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"required",!1);_(this,"constant",!1);_(this,"x");_(this,"y");_(this,"type",f.VariableDeclaration);_(this,"catchesError",!1);_(this,"defaultValue",null);_(this,"dataType",null);_(this,"writesValues",[]);_(this,"readsValue",null);_(this,"inputs",[]);_(this,"outputs",[]);_(this,"error",null);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"successCalls",[]);_(this,"errorCalls",[]);_(this,"internalCalls",[]);_(this,"parent");_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);_(this,"codeNativeValueValidation",null);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.description=i.description,this.constant=i.constant,this.codeName=i.codeName,this.required=i.required,this.x=i.x,this.y=i.y,this.catchesError=i.catchesError||!1}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.VariableDeclaration,catchesError:!0,name:"",codeName:null,description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],error:null,x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const A=J(i.parent);o=a.get(A)}const p=i.calledByEntry.map(A=>{const $=J(A);return a.get($)}),e=i.calledBySuccess.map(A=>{const $=J(A);return a.get($)}),y=i.calledByError.map(A=>{const $=J(A);return a.get($)});let v=null;if(i.readsValue){const A=J(i.readsValue);v=a.get(A)}const E={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.VariableDeclaration,catchesError:i.catchesError||!1,name:i.name,defaultValue:null,codeName:i.codeName||null,description:i.description||null,constant:i.constant||!1,required:i.required||!1,calledByEntry:p,calledBySuccess:e,calledByError:y,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:v,inputs:[],outputs:[],writesValues:[],error:null,x:0,y:0,parent:o},w=se(E,a);return w.setParent(o,null),w}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=ti(o,{parent:{list:!1,types:[...Nr,f.Project],optional:!0}},a);o=e.modifiedData;const y=gb(o,a);return p.push(...e.errors,...y,...Vr(o)),{errors:p,modifiedData:o}}get variableInstances(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===OI.VarDeclaration&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];let o=JSON.parse(JSON.stringify(i));const p=Zp(o,this);return o=p.modifiedData,a.push(...p.errors),i.parent&&a.push(new ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
|
|
@@ -386,7 +386,7 @@ The only use for declaring global callable entities is for a 'variable-declarati
|
|
|
386
386
|
Or for a logic that the user is going to manually test themselves by clicking on the user-interface.`,entity:d}));else{const i=tf(d);if(!i.reachable&&i.entryPoint){let a=`This '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" is not reachable from the project's closest entry point '${i.entryPoint.type}' "${Y(i.entryPoint,d.project)}".`;a+=`
|
|
387
387
|
This is because there are termination statements in the call chain before reaching this '${d.type}'.
|
|
388
388
|
If a caller entity calls a termination statement, it will always prevent all other calls from executing.`;let o=`
|
|
389
|
-
This '${d.type}' is blocked `;i.blocks.forEach((p,e)=>{const y=p.blockedByCaller,v=p.blockedByCalling;e===0?o+="by ":e===i.blocks.length-1&&(o+="and by "),o+=`its ancestor "${Y(y,d.project)}" with id "${y.id}" that calls a '${v.type}' entity with id "${v.id}"`,e<i.blocks.length-1?o+=", ":o+="."}),u.push(new ir({id:`${d.id}--${ae.UnreachableEntity}`,code:ae.UnreachableEntity,severity:H.Warning,message:`${a}${o}`,entity:d}))}}return Er(d.errors,u)}function vo(d){const u=[];if(d.type===f.InputMap&&Tt.includes(d.parent.type)&&d.parent.internalCalls.some(a=>!!a.calledBy.length))return u;const i=d.project.requestActiveDynamicValue(d);if((i==null?void 0:i.type)===Ae.Missing){const a=Rt({id:`${d.id}--${re.MissingRequiredValue}`,message:`The '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" is missing its required value before it can be executed or published.`,severity:H.Error,code:re.MissingRequiredValue,entity:d});u.push(a.error)}return u}function rb(d){const u=[];if(!d.internalCalls.length)return u;const i=d.internalCalls.some(a=>a.calledBy.length||a.successCalls.length||a.errorCalls.length||a.getUsedInputs().length||a.getUsedOutputs().length);if(d.readsValue&&i){const a=Rt({id:`${d.id}--${re.VariableReadsValueAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" reads a value. A variable with internal calls can't read a value.`,severity:H.Error,code:re.VariableReadsValueAndInternalCall,entity:d});u.push(a.error)}if(d.writesValues.length&&i){const a=Rt({id:`${d.id}--${re.VariableWritesValuesAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" writes values. A variable with internal calls can't write a value.`,severity:H.Error,code:re.VariableWritesValuesAndInternalCall,entity:d});u.push(a.error)}if(d.getUsedInputs().length&&i){const a=Rt({id:`${d.id}--${re.VariableHasInputsAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" has inputs. A variable with internal calls can't have inputs.`,severity:H.Error,code:re.VariableHasInputsAndInternalCall,entity:d});u.push(a.error)}if(d.getUsedOutputs().length&&i){const a=Rt({id:`${d.id}--${re.VariableHasOutputsAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" has outputs. A variable with internal calls can't have outputs.`,severity:H.Error,code:re.VariableHasOutputsAndInternalCall,entity:d});u.push(a.error)}if(d.calledBy.length&&i){const a=Rt({id:`${d.id}--${re.VariableIsCalledAndHasInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" is called by other entities. A variable with internal calls can't be called by other entities.`,severity:H.Error,code:re.VariableIsCalledAndHasInternalCall,entity:d});u.push(a.error)}if([...d.successCalls,...d.errorCalls].length&&i){const a=Rt({id:`${d.id}--${re.VariableCallsOthersAndHasInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" calls other entities. A variable with internal calls can't call other entities.`,severity:H.Error,code:re.VariableCallsOthersAndHasInternalCall,entity:d});u.push(a.error)}return u}function XTe(d){const u=d.variableDeclarations,i=d.events.flatMap(e=>[e,...yt(e)]),a=d.functions.flatMap(e=>d.instancesList.find(y=>y.type===f.FunctionCall&&y.declaration.id===e.id)?[e,...yt(e)]:[]),o=d.entities.flatMap(e=>[e,...d.entities.reduce((y,v)=>[...y,...v.methods.flatMap(E=>[E,...yt(E)])],[])]);return JT([...u,...i,...a,...o].flatMap(e=>e.getErrors()))}function ib(d){var i,a,o,p;if(d.type!==f.InternalCall){if(!Dt.includes(d.parent.type))return!1;const e=d.parent;return!(!((i=e.implements)!=null&&i.outputs.length)||!((a=e.implements)!=null&&a.outputs.some(y=>y.required)))}if(!Dt.includes(d.parent.parent.type))return!1;const u=d.parent.parent;return!(!((o=u.implements)!=null&&o.outputs.length)||!((p=u.implements)!=null&&p.outputs.some(e=>e.required)))}function sb(d){var o,p;const u=[];if(!((o=d.implements)!=null&&o.outputs.length)||!((p=d.implements)!=null&&p.outputs.some(e=>e.required)))return u;if(yt(d).filter(e=>hr.includes(e.type)||!ib(e)?!1:!!(!e.successCalls.length&&!e.errorCalls.length&&e.calledBy.length)).length){const e=Rt({id:`${d.id}--${re.LackingReturnStatementOnSomeBranches}`,message:`The '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" is missing the required return statement by its implementation on some branches.`,severity:H.Error,code:re.LackingReturnStatementOnSomeBranches,entity:d});u.push(e.error)}return u}function Pa(d){const u=[];if(!xi.includes(d.type)||hr.includes(d.type)||Dt.includes(d.type)||!ib(d))return u;if(!d.successCalls.length&&!d.errorCalls.length&&d.calledBy.length){const i=Rt({id:`${d.id}--${re.LastCalledEntityMustBeReturnEntity}`,message:`The '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" cannot be the last entity of the branch. A return statement must be the last entity on all branches of its parent entry-point.`,severity:H.Error,code:re.LastCalledEntityMustBeReturnEntity,entity:d});u.push(i.error)}return u}const v5=["class","function","if","else","for","while","do","switch","case","default","break","continue","return","try","catch","finally","throw","import","export","as","from","in","instanceof","typeof","yield","await","async","this","new","delete","void","with","const","let","var","public","private","protected","static","get","set","constructor","extends","implements","interface","namespace","package","abstract","readonly","module"];function Hp(d,u=[xr],i=[]){const
|
|
389
|
+
This '${d.type}' is blocked `;i.blocks.forEach((p,e)=>{const y=p.blockedByCaller,v=p.blockedByCalling;e===0?o+="by ":e===i.blocks.length-1&&(o+="and by "),o+=`its ancestor "${Y(y,d.project)}" with id "${y.id}" that calls a '${v.type}' entity with id "${v.id}"`,e<i.blocks.length-1?o+=", ":o+="."}),u.push(new ir({id:`${d.id}--${ae.UnreachableEntity}`,code:ae.UnreachableEntity,severity:H.Warning,message:`${a}${o}`,entity:d}))}}return Er(d.errors,u)}function vo(d){const u=[];if(d.type===f.InputMap&&Tt.includes(d.parent.type)&&d.parent.internalCalls.some(a=>!!a.calledBy.length))return u;const i=d.project.requestActiveDynamicValue(d);if((i==null?void 0:i.type)===Ae.Missing){const a=Rt({id:`${d.id}--${re.MissingRequiredValue}`,message:`The '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" is missing its required value before it can be executed or published.`,severity:H.Error,code:re.MissingRequiredValue,entity:d});u.push(a.error)}return u}function rb(d){const u=[];if(!d.internalCalls.length)return u;const i=d.internalCalls.some(a=>a.calledBy.length||a.successCalls.length||a.errorCalls.length||a.getUsedInputs().length||a.getUsedOutputs().length);if(d.readsValue&&i){const a=Rt({id:`${d.id}--${re.VariableReadsValueAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" reads a value. A variable with internal calls can't read a value.`,severity:H.Error,code:re.VariableReadsValueAndInternalCall,entity:d});u.push(a.error)}if(d.writesValues.length&&i){const a=Rt({id:`${d.id}--${re.VariableWritesValuesAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" writes values. A variable with internal calls can't write a value.`,severity:H.Error,code:re.VariableWritesValuesAndInternalCall,entity:d});u.push(a.error)}if(d.getUsedInputs().length&&i){const a=Rt({id:`${d.id}--${re.VariableHasInputsAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" has inputs. A variable with internal calls can't have inputs.`,severity:H.Error,code:re.VariableHasInputsAndInternalCall,entity:d});u.push(a.error)}if(d.getUsedOutputs().length&&i){const a=Rt({id:`${d.id}--${re.VariableHasOutputsAndInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" has outputs. A variable with internal calls can't have outputs.`,severity:H.Error,code:re.VariableHasOutputsAndInternalCall,entity:d});u.push(a.error)}if(d.calledBy.length&&i){const a=Rt({id:`${d.id}--${re.VariableIsCalledAndHasInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" is called by other entities. A variable with internal calls can't be called by other entities.`,severity:H.Error,code:re.VariableIsCalledAndHasInternalCall,entity:d});u.push(a.error)}if([...d.successCalls,...d.errorCalls].length&&i){const a=Rt({id:`${d.id}--${re.VariableCallsOthersAndHasInternalCall}`,message:`Variable "${Y(d,d.project)}" with id "${d.id}" calls other entities. A variable with internal calls can't call other entities.`,severity:H.Error,code:re.VariableCallsOthersAndHasInternalCall,entity:d});u.push(a.error)}return u}function XTe(d){const u=d.variableDeclarations,i=d.events.flatMap(e=>[e,...yt(e)]),a=d.functions.flatMap(e=>d.instancesList.find(y=>y.type===f.FunctionCall&&y.declaration.id===e.id)?[e,...yt(e)]:[]),o=d.entities.flatMap(e=>[e,...d.entities.reduce((y,v)=>[...y,...v.methods.flatMap(E=>[E,...yt(E)])],[])]);return JT([...u,...i,...a,...o].flatMap(e=>e.getErrors()))}function ib(d){var i,a,o,p;if(d.type!==f.InternalCall){if(!Dt.includes(d.parent.type))return!1;const e=d.parent;return!(!((i=e.implements)!=null&&i.outputs.length)||!((a=e.implements)!=null&&a.outputs.some(y=>y.required)))}if(!Dt.includes(d.parent.parent.type))return!1;const u=d.parent.parent;return!(!((o=u.implements)!=null&&o.outputs.length)||!((p=u.implements)!=null&&p.outputs.some(e=>e.required)))}function sb(d){var o,p;const u=[];if(!((o=d.implements)!=null&&o.outputs.length)||!((p=d.implements)!=null&&p.outputs.some(e=>e.required)))return u;if(yt(d).filter(e=>hr.includes(e.type)||!ib(e)?!1:!!(!e.successCalls.length&&!e.errorCalls.length&&e.calledBy.length)).length){const e=Rt({id:`${d.id}--${re.LackingReturnStatementOnSomeBranches}`,message:`The '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" is missing the required return statement by its implementation on some branches.`,severity:H.Error,code:re.LackingReturnStatementOnSomeBranches,entity:d});u.push(e.error)}return u}function Pa(d){const u=[];if(!xi.includes(d.type)||hr.includes(d.type)||Dt.includes(d.type)||!ib(d))return u;if(!d.successCalls.length&&!d.errorCalls.length&&d.calledBy.length){const i=Rt({id:`${d.id}--${re.LastCalledEntityMustBeReturnEntity}`,message:`The '${d.type}' entity "${Y(d,d.project)}" with id "${d.id}" cannot be the last entity of the branch. A return statement must be the last entity on all branches of its parent entry-point.`,severity:H.Error,code:re.LastCalledEntityMustBeReturnEntity,entity:d});u.push(i.error)}return u}const v5=["class","function","if","else","for","while","do","switch","case","default","break","continue","return","try","catch","finally","throw","import","export","as","from","in","instanceof","typeof","yield","await","async","this","new","delete","void","with","const","let","var","public","private","protected","static","get","set","constructor","extends","implements","interface","namespace","package","abstract","readonly","module"];function Hp(d,u=[xr],i=[],a){const o=[],p=a??d.name;if(!p){const A=Rt({id:`${d.id}--${ae.EmptyName}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" does not have a name. Entities of type ${d.type} must have valid names.`,severity:H.Error,code:ae.EmptyName,entity:d});return o.push(A.error),o}const e=p.trim(),y=!i.some(A=>A.name===p||A.name===e);if(!y){const A=Rt({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Action "${Y(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.`,severity:H.Error,code:ae.NameNotUniqueInScope,entity:d});o.push(A.error)}if(u.forEach(A=>{const $=A(p);if(!!i.some(F=>A(F.name||"")===$)&&y){const F=Rt({id:`${d.id}--${ae.NameAsResolvedCodeNameNotUniqueInScope}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" does not have a unique name once it is resolved as it will appear in code: "${$}". Entities of type ${d.type} must have valid names including their code name form.`,severity:H.Error,code:ae.NameAsResolvedCodeNameNotUniqueInScope,entity:d});o.push(F.error)}if(v5.find(F=>F===$)){const F=Rt({id:`${d.id}--${ae.NameIsForbiddenKeyword}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" has a name that is a forbidden keyword: "${$}". Entities of type ${d.type} must not use reserved keywords as names.`,severity:H.Error,code:ae.NameIsForbiddenKeyword,entity:d});o.push(F.error)}}),!/^[a-zA-Z_]/.test(p)){const A=Rt({id:`${d.id}--${ae.NameMustStartWithLetterOrUnderscore}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" has a name that does not start with a letter or underscore.`,severity:H.Error,code:ae.NameMustStartWithLetterOrUnderscore,entity:d});o.push(A.error)}const E=p.substring(1);if(!/^[a-zA-Z0-9_ ]*$/.test(E)){const A=Rt({id:`${d.id}--${ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces}`,message:`Action "${Y(d,d.project)}" with id "${d.id}" has a name that contains invalid characters. It can only contain letters, numbers, underscores and spaces.`,severity:H.Error,code:ae.NameCanOnlyContainLettersNumbersUnderscoreAndSpaces,entity:d});o.push(A.error)}return o}function E5(d){var a;d.inputs.forEach(o=>o.validate()),d.outputs.forEach(o=>o.validate()),(a=d.error)==null||a.validate();const i=[...$a(d),...Pa(d)];return Er(d.errors,i)}const QTe=Object.freeze(Object.defineProperty({__proto__:null,validate:E5},Symbol.toStringTag,{value:"Module"}));var T5=(d=>(d.Parent="parent",d.Declaration="declaration",d))(T5||{});const Qt=class Qt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"x");_(this,"y");_(this,"type",f.FunctionCall);_(this,"catchesError",!1);_(this,"successCalls",[]);_(this,"errorCalls",[]);_(this,"process",null);_(this,"declaration");_(this,"inputs",[]);_(this,"outputs",[]);_(this,"calledBySuccess",[]);_(this,"calledByError",[]);_(this,"calledByEntry",[]);_(this,"error",null);_(this,"parent");_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);this.initialData=i,this.project=a,this.id=i.id,this.x=i.x,this.y=i.y,this.catchesError=i.catchesError||!1}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.FunctionCall,catchesError:!0,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const $=J(i.parent);o=a.get($)}const p=J(i.declaration),e=a.get(p),y=i.calledByEntry.map($=>{const V=J($);return a.get(V)}),v=i.calledBySuccess.map($=>{const V=J($);return a.get(V)}),E=i.calledByError.map($=>{const V=J($);return a.get(V)}),w={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.FunctionCall,catchesError:i.catchesError||!1,declaration:e.toReference(),calledByEntry:y,calledBySuccess:v,calledByError:E,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:o},A=se(w,a);return A.setParent(o,null),A}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=ti(o,{parent:{list:!1,types:[...Nr,f.Project],optional:!0}},a);o=e.modifiedData,p.push(...e.errors,...Vr(o));const y=J(o.declaration);if(y){const v=h5(y,a);p.push(...v)}else{const v=a.functions.length?`
|
|
390
390
|
All global 'function-declaration' entity ids are:
|
|
391
391
|
- ${a.functions.map(E=>`${E.id} (${Y(E,a)})`).join(`
|
|
392
392
|
- `)}.`:`
|
|
@@ -399,10 +399,10 @@ Please provide a unique 'name' string.`,severity:H.Error,code:ae.NameNotUniqueIn
|
|
|
399
399
|
Please provide a unique 'name' string.`,severity:H.Error,code:ae.NameNotUniqueInScope}))}return i}function _b(d,u){const i=[];d.name||i.push(new ne({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:ae.EmptyName}));const a=J(d.parent);if(!a)i.push(new ne({id:`${d.id}--parent-reference--${k.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${d.id}" and type "${d.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:H.Error,code:k.InvalidReferenceObjectStructure}));else{const o=u.get(a);if(!o)i.push(new ne({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:H.Error,code:k.ReferencedEntityNotFound}));else{const e=o.properties.filter(y=>y.name===d.name);e.length&&i.push(new ne({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique among all properties in the parent entity. Entity with id "${e[0].id}" has the same name.
|
|
400
400
|
Please provide a unique 'name' string.`,severity:H.Error,code:ae.NameNotUniqueInScope}))}}return i}function Db(d,u){const i=[];d.name||i.push(new ne({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:ae.EmptyName}));const a=J(d.parent);if(!a)i.push(new ne({id:`${d.id}--parent-reference--${k.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${d.id}" and type "${d.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:H.Error,code:k.InvalidReferenceObjectStructure}));else{const o=u.get(a);if(!o)i.push(new ne({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:H.Error,code:k.ReferencedEntityNotFound}));else{const e=hb(o).filter(y=>y.name===d.name);e.length&&i.push(new ne({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${e[0].id}" has the same name.
|
|
401
401
|
Please provide a unique 'name' string.`,severity:H.Error,code:ae.NameNotUniqueInScope}))}}return i}function Ob(d,u){const i=[];d.name||i.push(new ne({id:`${d.id}--${ae.EmptyName}`,message:`Entity with id "${d.id}" and type "${d.type}" has an empty name. Please provide a 'name' string.`,severity:H.Error,code:ae.EmptyName}));const a=J(d.parent);if(!a)i.push(new ne({id:`${d.id}--parent-reference--${k.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${d.id}" and type "${d.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:H.Error,code:k.InvalidReferenceObjectStructure}));else{const o=u.get(a);if(!o)i.push(new ne({id:`${d.id}--parent-reference--${k.ReferencedEntityNotFound}`,message:`The entity with id '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:H.Error,code:k.ReferencedEntityNotFound}));else{const e=ES(o).filter(y=>y.name===d.name);e.length&&i.push(new ne({id:`${d.id}--${ae.NameNotUniqueInScope}`,message:`Entity with id "${d.id}" and type "${d.type}" has a name "${d.name}" that is not unique among all outputs declared in the parent entity. Entity with id "${e[0].id}" has the same name.
|
|
402
|
-
Please provide a unique 'name' string.`,severity:H.Error,code:ae.NameNotUniqueInScope}))}}return i}function GIe(d,u){switch(d.type){case f.DefinitionEntity:return wb(d,u);case f.FunctionDeclaration:return Rb(d,u);case f.VariableDeclaration:return gb(d,u);case f.Property:return _b(d,u);case f.ArgumentDeclaration:return Db(d,u);case f.ReturnDeclaration:return Ob(d,u);default:return[]}}function Cb(d,u){switch(d.type){case f.FunctionCall:case f.InternalCall:return qi(d.declaration,u).codeName}if(!e_.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=qi(d.implements,u);return Cb(a,u)||null}return d.codeName||null}case f.InputMap:case f.OutputMap:case f.VariableInstance:{if(d.declaration){const a=qi(d.declaration,u);return Cb(a,u)||""}break}}return i.codeName||null}function jS(d,u,i){const o=`${Lm(d)}-${u}-id`;return i.instances[o]?N.UUID.uuid():o}function $b(d,u){let i="",a=null;if(d.parent){const p=u.get(d.parent);p&&(a=p)}let o="";return a&&(o=`${Lm(Y(a,u))}-`),i=`${o}${Lm(Y(d,u))}-id`,u.instances[i]?N.UUID.uuid():i}function jr(d,u,i="uuid"){return i==="semantic"?jS(Y(d,u),d.type,u):N.UUID.uuid()}const FIe=/^[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 Pb(d){return typeof d=="string"&&FIe.test(d)}function GS(d){var a;const u=FS(d);return(a=d.dataType)==null||a.validate(),[...u,...vo(d),...SS(d)]}function FS(d){const u=[];if(!d.implements)return u;const i=d.implements;if(!i.abstract){const o=Rt({id:`${d.id}--${re.PropertyImplementsNonAbstact}`,message:`Property "${Y(d,d.project)}" with id "${d.id}" implements a non-abstract property "${Y(i,d.project)}" with id "${i.id}".`,severity:H.Error,code:re.PropertyImplementsNonAbstact,entity:d});u.push(o.error)}if(d.static&&!i.static){const o=Rt({id:`${d.id}--${re.NonStaticPropertyImplementsStatic}`,message:`Static property "${Y(d,d.project)}" with id "${d.id}" implements a non-static property "${Y(i,d.project)}" with id "${i.id}".`,severity:H.Error,code:re.NonStaticPropertyImplementsStatic,entity:d});u.push(o.error)}if(!d.static&&i.static){const o=Rt({id:`${d.id}--${re.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${Y(d,d.project)}" with id "${d.id}" implements a static property "${Y(i,d.project)}" with id "${i.id}".`,severity:H.Error,code:re.StaticPropertyImplementsNonStatic,entity:d});u.push(o.error)}if(!Ws(d.dataType,i.dataType)){const o=Rt({id:`${d.id}--${re.PropertyImplementsIncompatibleType}`,message:`Property "${Y(d,d.project)}" with id "${d.id}" implements a property "${Y(i,d.project)}" with id "${i.id}" that has an incompatible data type.`,severity:H.Error,code:re.PropertyImplementsIncompatibleType,entity:d});u.push(o.error)}return Er(d.errors,u)}function SS(d){const
|
|
402
|
+
Please provide a unique 'name' string.`,severity:H.Error,code:ae.NameNotUniqueInScope}))}}return i}function GIe(d,u){switch(d.type){case f.DefinitionEntity:return wb(d,u);case f.FunctionDeclaration:return Rb(d,u);case f.VariableDeclaration:return gb(d,u);case f.Property:return _b(d,u);case f.ArgumentDeclaration:return Db(d,u);case f.ReturnDeclaration:return Ob(d,u);default:return[]}}function Cb(d,u){switch(d.type){case f.FunctionCall:case f.InternalCall:return qi(d.declaration,u).codeName}if(!e_.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=qi(d.implements,u);return Cb(a,u)||null}return d.codeName||null}case f.InputMap:case f.OutputMap:case f.VariableInstance:{if(d.declaration){const a=qi(d.declaration,u);return Cb(a,u)||""}break}}return i.codeName||null}function jS(d,u,i){const o=`${Lm(d)}-${u}-id`;return i.instances[o]?N.UUID.uuid():o}function $b(d,u){let i="",a=null;if(d.parent){const p=u.get(d.parent);p&&(a=p)}let o="";return a&&(o=`${Lm(Y(a,u))}-`),i=`${o}${Lm(Y(d,u))}-id`,u.instances[i]?N.UUID.uuid():i}function jr(d,u,i="uuid"){return i==="semantic"?jS(Y(d,u),d.type,u):N.UUID.uuid()}const FIe=/^[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 Pb(d){return typeof d=="string"&&FIe.test(d)}function GS(d){var a;const u=FS(d);return(a=d.dataType)==null||a.validate(),[...u,...vo(d),...SS(d)]}function FS(d){const u=[];if(!d.implements)return u;const i=d.implements;if(!i.abstract){const o=Rt({id:`${d.id}--${re.PropertyImplementsNonAbstact}`,message:`Property "${Y(d,d.project)}" with id "${d.id}" implements a non-abstract property "${Y(i,d.project)}" with id "${i.id}".`,severity:H.Error,code:re.PropertyImplementsNonAbstact,entity:d});u.push(o.error)}if(d.static&&!i.static){const o=Rt({id:`${d.id}--${re.NonStaticPropertyImplementsStatic}`,message:`Static property "${Y(d,d.project)}" with id "${d.id}" implements a non-static property "${Y(i,d.project)}" with id "${i.id}".`,severity:H.Error,code:re.NonStaticPropertyImplementsStatic,entity:d});u.push(o.error)}if(!d.static&&i.static){const o=Rt({id:`${d.id}--${re.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${Y(d,d.project)}" with id "${d.id}" implements a static property "${Y(i,d.project)}" with id "${i.id}".`,severity:H.Error,code:re.StaticPropertyImplementsNonStatic,entity:d});u.push(o.error)}if(!Ws(d.dataType,i.dataType)){const o=Rt({id:`${d.id}--${re.PropertyImplementsIncompatibleType}`,message:`Property "${Y(d,d.project)}" with id "${d.id}" implements a property "${Y(i,d.project)}" with id "${i.id}" that has an incompatible data type.`,severity:H.Error,code:re.PropertyImplementsIncompatibleType,entity:d});u.push(o.error)}return Er(d.errors,u)}function SS(d,u){const a=[...d.parent.allProperties].filter(o=>{var p,e;return o.id!==d.id&&o.id!==((p=d.implements)==null?void 0:p.id)&&o.id!==((e=d.extends)==null?void 0:e.id)});return Hp(d,[xr],a,u)}const SIe=Object.freeze(Object.defineProperty({__proto__:null,validate:GS,validateImplementation:FS,validatePropertyEntityName:SS},Symbol.toStringTag,{value:"Module"}));function KIe(d,u){const i=[];if(d.parent){const o=u.get(d.parent);if(!o)i.push(new ne({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}));else{const p=Ao(o);if(p){const e=o!==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}' (${Y(p,o.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 ne({id:`${d.id}--${k.InvalidBuiltInEntityReference}`,code:k.InvalidBuiltInEntityReference,severity:H.Error,message:e}))}else if(![f.DefinitionEntity].includes(o.type))i.push(new ne({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:H.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'.`}));else{const y=Vi(o).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 '${o.id}' because it extends or implements multiple '${f.BuiltInBaseEntity}' entities that are non-interactive ("${st(y.map(E=>Y(E,E.project)),'", "','" and "')}").`:`The entity of type '${d.type}' with id '${d.id}' can't be added to the 'parent' entity with id '${o.id}' because it extends or implements a '${f.BuiltInBaseEntity}' entity that is non-interactive ("${Y(y[0],y[0].project)}").`;v+=`
|
|
403
403
|
${mo}`,i.push(new ne({id:`${d.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:H.Error,message:v}))}else if(d.implements){const v=u.get(d.implements);if(d.id===d.implements)return i.push(new ne({id:`${d.id}--${d.implements}--${k.SelfReference}`,code:k.SelfReference,severity:H.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.`})),i;if(!v)i.push(new ne({id:`${d.id}--${d.implements}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}));else{const E=o.properties.find(w=>{var A;return((A=w.implements)==null?void 0:A.id)===d.implements});E?i.push(new ne({id:`${d.id}--${ae.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:ae.PropertyOverwritesOtherSiblingWithSameImplementation,severity:H.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.`})):[f.Property].includes(v.type)?v.abstract||i.push(new ne({id:`${d.id}--${d.implements}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:H.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new ne({id:`${d.id}--${d.implements}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:H.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'.`}))}}}}}const a=ti(d,{},u);return i.push(...a.errors),i}function KS(d,u){var e;const i=[],a=[],o=[],p=[];if(((e=d.implements)==null?void 0:e.id)===he["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id){let y=d.defaultValue;if(!d.defaultValue){const v=Si.new(u);v.name=oe.EntityTemplate,v.parent=d.toReference();const E=se(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=PS(d.project);v&&y.setValueAsTypeSingle(v,u)}}return{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:d}}var kS=(d=>(d.PropertyImplements="property-implements",d.PropertyExtends="property-extends",d.DataTypeEntity="data-type-entity",d))(kS||{});const Ct=class Ct extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"private");_(this,"abstract");_(this,"index");_(this,"static");_(this,"required");_(this,"constant",!1);_(this,"interactive",!1);_(this,"type",f.Property);_(this,"hidden",!1);_(this,"defaultValue",null);_(this,"dataType",null);_(this,"implements",null);_(this,"extends",null);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestion",!1);_(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 o=J(i.parent),p=a.get(o);let e=null;if(i.implements){const w=J(i.implements);e=a.get(w)}let y=null;if(i.extends){const w=J(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=se(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=KIe(o,a),y=_b(o,a);return p.push(...e,...y,...Vr(o)),{errors:p,modifiedData:o}}get isExtendedProperty(){const i=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(a=>{var o;return a.id===((o=this.extends)==null?void 0:o.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 ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.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.`})),(i.readsValue||i.writesValue)&&a.push(new ne({id:`${this.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:H.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
|
|
405
|
-
${pm}`})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return KS(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,o),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.remove({ignoreUpstream:!1},o);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,o){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,o),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.restore({},o);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,o,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(o=this.extends)==null?void 0:o.unsubscribeDependents)==null||p.call(o,[{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($r.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,o,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(o=this.extends)==null?void 0:o.subscribeDependents)==null||p.call(o,[{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($r.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=[],o=[],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),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(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 o=J(i.parent),p=this.project.get(o),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 '${o}' 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 o=J(i.implements),p=this.project.get(o);if(p)this.setImplements(p,a);else if(o)throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'implements' reference "${o}" which is missing in the project`)}if(i.extends){const o=J(i.extends),p=this.project.get(o);if(p)this.setExtends(p,a);else if(o)throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'extends' reference "${o}" 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=[],o=[],p=[];if(this.initialData.parent){const e=J(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=J(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.extends){const e=J(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Ii(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(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);a.push(...y),o.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:B}=KS(this,i);return a.push(...A),o.push(...$),p.push(...V),e.push(...B),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],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(o),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var o;return((o=this.implements)==null?void 0:o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var o;return((o=this.extends)==null?void 0:o.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 G(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=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=se(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=se(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(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):o&&(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,...o){return await Ct.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],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(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(!i){const v=this.removeFromParent(a);e.push(...v.added),o.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(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);o.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(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.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,o,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:((o=this.dataType)==null?void 0:o.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=Se){var o,p,e,y,v,E,w;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e,y,v;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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 o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.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 o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.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=GS(this),this.errors.length,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((o=this.dataType)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),o=null){const p=o||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=se(e,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var V,B;let e=Ur(a,this);const y=o||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=dr(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 $=(B=this.defaultValue)==null?void 0:B.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const o=this.dataType;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.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 G(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],o=[],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),o.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),o.push(E)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}};_(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,...o)=>null}),_(Ct,"type",f.Property),_(Ct,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),_(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),_(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","interactive"]),_(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),_(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"index"]),_(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),_(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),_(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),_(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),_(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),_(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let zn=Ct;function qS(d){const u=d.implements.flatMap(y=>kIe(d,y)),i=qIe(d,d.extends),a=HIe(d),o=ZIe(d);d.methods.flatMap(y=>y.validate());const p=[...u,...i,...a,...o,...JS(d)];return Er(d.errors,p)}function ZS(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let o=[...d.properties];return i.forEach(p=>{const e=o.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?o=o.filter(y=>y.id!==e.id):a.push(p)}),a}function HS(d,u){const i=u.abstractMethods,a=[];let o=[...d.methods];return i.forEach(p=>{const e=o.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?o=o.filter(y=>y.id!==e.id):a.push(p)}),a}function kIe(d,u){const i=[];if(!u.abstract){const w=Rt({id:d.id+"--"+re.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),o=[];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):o.push(w)}),o.length&&o.forEach(w=>{const A=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.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=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.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=Rt({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}"`,severity:H.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=Rt({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}"`,severity:H.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function qIe(d,u){const i=[];if(!u)return i;const a=[];if(!d.abstract&&u.abstract){const p=Rt({id:d.id+"--"+u.id+"--"+re.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=Rt({id:d.id+"--"+u.id+"--"+re.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.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=Rt({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}"`,severity:H.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const o=[];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&&o.push(p)}),o.length&&o.forEach(p=>{const e=Rt({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}"`,severity:H.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function ZIe(d){const u=[];if(!d.properties.length){const i=Rt({id:d.id+"--"+re.NoProperties,message:"No properties implemented",severity:H.Warning,code:re.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function HIe(d){const u=[];if(d.abstract){if(d.methods.length){const i=Rt({id:d.id+"--"+re.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:H.Error,code:re.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=Rt({id:d.id+"--"+re.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:H.Error,code:re.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const o=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.StaticEntityWithNonStaticProperties,entity:d});u.push(o.error)}})}}else{if(d.abstractMethods.length){const i=Rt({id:d.id+"--"+re.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:H.Error,code:re.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.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=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function JIe(d,u){const i=[],a=Vi(u);if(!u.abstract){const e=new ir({id:d.id+"--"+u.id+"--"+re.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(e)}const o=d.implements.filter(e=>e.id!==u.id);if(d.abstract){const e=new ir({id:d.id+"--"+u.id+"--"+re.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}"`,severity:H.Error,code:re.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(e)}if(d.static&&!u.static){const e=new ir({id:d.id+"--"+u.id+"--"+re.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}"`,severity:H.Error,code:re.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(e)}if(!d.static&&u.static){const e=new ir({id:d.id+"--"+u.id+"--"+re.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}"`,severity:H.Error,code:re.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(e)}return o.length&&o.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 ir({id:d.id+"--"+v.id+"--"+e.id+"--"+re.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`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(E)}})}else{Vi(e).forEach(w=>{const A=a.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new ir({id:d.id+"--"+$.id+"--"+w.id+"--"+re.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`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});i.push(V)}})});const v=Na(u.ownDeclaredProperties,e.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const E=Na(u.abstractMethods,[...e.abstractMethods,...e.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...E.errors)}}),R(d.extends?Vi(d.extends):[]).forEach(e=>{if(!a.find(y=>y.id===e.id)){const y=new ir({id:d.id+"--"+u.id+"--"+e.id+"--"+re.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`,severity:H.Error,code:re.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:e});i.push(y)}}),i}function WIe(d,u,i=!1){var E,w;const a=[],o=Vi(u);if(!d.abstract&&u.abstract){const A=Rt({id:d.id+"--"+u.id+"--"+re.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(A.error)}if(d.abstract&&!u.abstract){const A=Rt({id:d.id+"--"+u.id+"--"+re.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(A.error)}if(!d.static&&u.static){const A=Rt({id:d.id+"--"+u.id+"--"+re.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(A.error)}if(d.static&&!u.static){const A=Rt({id:d.id+"--"+u.id+"--"+re.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(A.error)}if(!Qp(u)){const A=Rt({id:d.id+"--"+u.id+"--"+re.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(A.error)}if(d.extends&&((E=d.extends)==null?void 0:E.id)!==u.id)if(((w=d.extends)==null?void 0:w.type)===f.BuiltInBaseEntity){const A=o.filter($=>{var V;return $.id!==((V=d.extends)==null?void 0:V.id)});A.length&&A.forEach($=>{var V,B,F,K;if($.id!==((V=d.extends)==null?void 0:V.id)){const q=Rt({id:d.id+"--"+$.id+"--"+((B=d.extends)==null?void 0:B.id)+"--"+re.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${$.name}" with id "${$.id}" but also extends entity "${(F=d.extends)==null?void 0:F.name}" with id "${(K=d.extends)==null?void 0:K.id}" which is incompatible`,severity:H.Error,code:re.ExtendsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:d.extends});a.push(q.error)}})}else{Vi(d.extends).forEach(q=>{const ie=o.filter(W=>W.id!==q.id);ie.length&&ie.forEach(W=>{if(W.id!==q.id){const de=new ir({id:d.id+"--"+W.id+"--"+q.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${W.name}" with id "${W.id}" but also extends or implements entity "${q.name}" with id "${q.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:W,secondRelationship:q});a.push(de)}})});const $=!!Vi(d.extends).find(q=>q.id===u.id);let V=[...d.extends.properties];$&&(V=V.filter(q=>!u.properties.find(ie=>{var W;return ie.id===q.id||ie.name===q.name||ie.id===((W=q.implements)==null?void 0:W.id)})));let B=[...d.extends.methods];$&&(B=B.filter(q=>!u.methods.find(ie=>{var W;return ie.id===q.id||ie.name===q.name||ie.id===((W=q.implements)==null?void 0:W.id)})));const F=Na(u.ownDeclaredProperties,V,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...F.errors);const K=Na(u.abstractMethods,B,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...K.errors)}i&&Me.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(A=>{if(A.type===f.BuiltInBaseEntity){const $=o.filter(V=>V.id!==A.id);$.length&&$.forEach(V=>{if(V.id!==A.id){const B=new ir({id:d.id+"--"+V.id+"--"+A.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${A.name}" with id "${A.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:A});a.push(B)}})}else{Vi(A).forEach(F=>{const K=o.filter(q=>q.id!==F.id);K.length&&K.forEach(q=>{if(q.id!==F.id){const ie=new ir({id:d.id+"--"+q.id+"--"+F.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${q.name}" with id "${q.id}" but also implements entity "${F.name}" with id "${F.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:q,secondRelationship:F});a.push(ie)}})});const V=Na(u.ownDeclaredProperties,A.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...V.errors);const B=Na(u.abstractMethods,[...A.abstractMethods,...A.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...B.errors)}});const e=Na(d.ownDeclaredProperties,u.ownDeclaredProperties,ae.PropertyOverwritesOtherSiblingWithSameImplementation,ae.PropertyOverwritesOtherSiblingWithSameName);a.push(...e.errors);const y=Na(u.methods,u.abstractMethods,ae.MethodOverwritesOtherSiblingWithSameImplementation,ae.MethodOverwritesOtherSiblingWithSameName);return a.push(...y.errors),R(d.extends?Vi(d.extends):[]).forEach(A=>{if(!o.find($=>$.id===A.id)){const $=new ir({id:d.id+"--"+u.id+"--"+A.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${A.name}" with id "${A.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:A});a.push($)}}),a}function YIe(d){const u=[];if(d.implements.forEach(i=>{if(!i.static){const a=new ir({id:d.id+"--"+i.id+"--"+re.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:H.Error,code:re.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends&&!d.extends.static){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-static`,severity:H.Error,code:re.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function zIe(d){const u=[];if(d.implements.length){const i=new ir({id:d.id+"--"+re.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:H.Error,code:re.AbstractEntityImplements,entity:d});u.push(i)}if(d.extends&&!d.extends.abstract){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-abstract`,severity:H.Error,code:re.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function XIe(d){const u=[];if(d.extends&&d.extends.static){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is static`,severity:H.Error,code:re.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function QIe(d){const u=[];if(d.extends&&d.extends.abstract){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is abstract`,severity:H.Error,code:re.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function JS(d){const i=[...d.project.entities].filter(a=>a.id!==d.id);return Hp(d,[xr,Il],i)}const eAe=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:HS,getBasePropertiesNotImplemented:ZS,validate:qS,validateCanBecomeAbstract:zIe,validateCanBecomeNonAbstract:QIe,validateCanBecomeNonStatic:XIe,validateCanBecomeStatic:YIe,validateCanExtendEntity:WIe,validateCanImplementEntity:JIe,validateDefinitionEntityName:JS},Symbol.toStringTag,{value:"Module"}));function tAe(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new ne({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:H.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.`}));else{const a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new ne({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:H.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'.`})):i.push(new ne({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new ne({id:`${d.id}--${a}--${k.SelfReference}`,code:k.SelfReference,severity:H.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.`}));return}const o=u.get(a);o?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(o.type)?o.abstract||i.push(new ne({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:H.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new ne({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:H.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'.`})):i.push(new ne({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}))}):i.push(new ne({id:`${d.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:H.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const o=u.get(a);o?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(o.type)?o.abstract&&i.push(new ne({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:H.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?`})):i.push(new ne({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:H.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'.`})):i.push(new ne({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}))}),i}var Bm=(d=>(d.Extends="extends",d.Implements="implements",d))(Bm||{});const qt=class qt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"static");_(this,"abstract");_(this,"type",f.DefinitionEntity);_(this,"properties",[]);_(this,"methods",[]);_(this,"abstractMethods",[]);_(this,"extends",null);_(this,"implements",[]);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestedProperties",[]);_(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:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const E=J(i.parent);o=a.get(E)}const p=[];i.implements&&i.implements.forEach(E=>{p.push(a.get(E)||a.getBuiltIn(E))});let e=null;i.extends&&(e=a.get(i.extends)||a.getBuiltIn(i.extends));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:o},v=se(y,a);return v.setParent(o,null),v}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=tAe(o,a),y=wb(o,a);p.push(...e,...y,...Vr(o));const v=o.parent?a.get(o.parent):null;if(v&&v.type===f.DataType){const E=v;E.entity&&p.push(new ne({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:H.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
|
+
${pm}`})),{errors:a,modifiedData:i}}onProjectInitialized(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,new Date().toISOString(),this,!0,"on-property-received-project-initialized"))){return KS(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(null,o),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.remove({ignoreUpstream:!1},o);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,o){const p=[],e=[],y=[],v=[];if(a==="property-implements"&&(this.setImplements(i,o),p.push(this)),a==="property-extends"){const{updated:E,added:w,removed:A,affected:$}=this.restore({},o);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,o,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.unsubscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(o=this.extends)==null?void 0:o.unsubscribeDependents)==null||p.call(o,[{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($r.PROJECT_INITIALIZED,this.onProjectInitialized),this}subscribeToDependencies(){var i,a,o,p,e,y,v;return(a=(i=this.implements)==null?void 0:i.subscribeDependents)==null||a.call(i,[{entity:this,field:"property-implements"}]),(p=(o=this.extends)==null?void 0:o.subscribeDependents)==null||p.call(o,[{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($r.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=[],o=[],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),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(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 o=J(i.parent),p=this.project.get(o),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 '${o}' 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 o=J(i.implements),p=this.project.get(o);if(p)this.setImplements(p,a);else if(o)throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'implements' reference "${o}" which is missing in the project`)}if(i.extends){const o=J(i.extends),p=this.project.get(o);if(p)this.setExtends(p,a);else if(o)throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'extends' reference "${o}" 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=[],o=[],p=[];if(this.initialData.parent){const e=J(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=J(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else if(e)throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}if(this.initialData.extends){const e=J(this.initialData.extends),y=this.project.get(e);if(y)this.setExtends(y,null),i.push(y);else if(e)throw new Error(`${Ii(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(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncWithImplementation(i);a.push(...y),o.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:B}=KS(this,i);return a.push(...A),o.push(...$),p.push(...V),e.push(...B),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],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(o),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-implements"))){var o;return((o=this.implements)==null?void 0:o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extends"))){var o;return((o=this.extends)==null?void 0:o.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 G(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=se(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(i)),this.initialData.dataType){const a=se(this.initialData.dataType,this.project);a.setParent(this,null),a.initChildren(i),this.dataType=a}if(this.initialData.implements){const a=se(this.initialData.implements,this.project);this.setImplements(a,null)}if(this.initialData.extends){const a=se(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(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):o&&(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,...o){return await Ct.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],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(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.defaultValue){const{updated:v,removed:E}=this.defaultValue.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(this.dataType){const{updated:v,removed:E}=this.dataType.remove({ignoreUpstream:!0},a);o.push(...v),p.push(...E)}if(!i){const v=this.removeFromParent(a);e.push(...v.added),o.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(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.defaultValue){const{updated:y}=this.defaultValue.restore({},i);o.push(...y)}if(this.dataType){const{updated:y}=this.dataType.restore({},i);o.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(o),removed:R(p),affected:R(e),self:this}}toFlat(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.defaultValue)==null?void 0:o.toFlat(i))||[],...((p=this.dataType)==null?void 0:p.toFlat(i))||[],...this.parent.toFlat(i)])}toFlatIds(i=new Set){var o,p;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.defaultValue)==null?void 0:o.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,o,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:((o=this.dataType)==null?void 0:o.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=Se){var o,p,e,y,v,E,w;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p,e,y,v;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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 o,p,e;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...((o=this.defaultValue)==null?void 0:o.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 o,p;return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...((o=this.defaultValue)==null?void 0:o.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=GS(this),this.errors.length,{success:!0}}getErrors(){var a,o;return[...this.errors,...((a=this.defaultValue)==null?void 0:a.getErrors())||[],...((o=this.dataType)==null?void 0:o.getErrors())||[]]}getShallowErrors(){return this.errors}implement(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-self-as-property")),o=null){const p=o||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=se(e,this.project);return y.hydrateAncestors(),y.addSelfToProject(a),y.initChildren(a),y}clone(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var V,B;let e=Ur(a,this);const y=o||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=dr(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 $=(B=this.defaultValue)==null?void 0:B.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-data-type"))){const o=this.dataType;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.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 G(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-default-value"))){const o=this.defaultValue;return(o==null?void 0:o.id)!==(i==null?void 0:i.id)&&(o==null||o.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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-with-implementation"))){var y;const a=[],o=[],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),o.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),o.push(E)}}return i==null||i.attemptAutoclose("sync-with-implementation",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}};_(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,...o)=>null}),_(Ct,"type",f.Property),_(Ct,"USER_MANAGED_PARENT_TYPES",[f.DefinitionEntity]),_(Ct,"PARENT_TYPES",[...Ct.USER_MANAGED_PARENT_TYPES,f.PrimitiveEntity,f.BuiltInBaseEntity]),_(Ct,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private","abstract","static","required","constant","interactive"]),_(Ct,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Ct,"BASE_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,...Ct.INMUTABLE_BASE_PROPERTIES]),_(Ct,"MUTABLE_META_PROPERTIES",[...Ct.MUTABLE_BASE_PROPERTIES,"index"]),_(Ct,"INMUTABLE_META_PROPERTIES",[...Ct.INMUTABLE_BASE_PROPERTIES]),_(Ct,"META_PROPERTIES",[...Ct.MUTABLE_META_PROPERTIES,...Ct.INMUTABLE_META_PROPERTIES]),_(Ct,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Ct,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),_(Ct,"UPSTREAM_PROPERTIES",[...Ct.MUTABLE_UPSTREAM_PROPERTIES,...Ct.INMUTABLE_UPSTREAM_PROPERTIES]),_(Ct,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),_(Ct,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Ct,"DOWNSTREAM_PROPERTIES",[...Ct.MUTABLE_DOWNSTREAM_PROPERTIES,...Ct.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Ct,"PROPERTIES",[...Ct.META_PROPERTIES,...Ct.UPSTREAM_PROPERTIES,...Ct.DOWNSTREAM_PROPERTIES]);let zn=Ct;function qS(d){const u=d.implements.flatMap(y=>kIe(d,y)),i=qIe(d,d.extends),a=HIe(d),o=ZIe(d);d.methods.flatMap(y=>y.validate());const p=[...u,...i,...a,...o,...JS(d)];return Er(d.errors,p)}function ZS(d,u){const i=u.properties.filter(p=>p.abstract),a=[];let o=[...d.properties];return i.forEach(p=>{const e=o.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?o=o.filter(y=>y.id!==e.id):a.push(p)}),a}function HS(d,u){const i=u.abstractMethods,a=[];let o=[...d.methods];return i.forEach(p=>{const e=o.find(y=>{var v;return((v=y.implements)==null?void 0:v.id)===p.id});e?o=o.filter(y=>y.id!==e.id):a.push(p)}),a}function kIe(d,u){const i=[];if(!u.abstract){const w=Rt({id:d.id+"--"+re.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.ImplementingNonAbstractEntity,entity:d});return i.push(w.error),i}const a=u.properties.filter(w=>w.abstract),o=[];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):o.push(w)}),o.length&&o.forEach(w=>{const A=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.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=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.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=Rt({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}"`,severity:H.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=Rt({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}"`,severity:H.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(A.error)}),i}function qIe(d,u){const i=[];if(!u)return i;const a=[];if(!d.abstract&&u.abstract){const p=Rt({id:d.id+"--"+u.id+"--"+re.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});return i.push(p.error),i}if(d.abstract&&!u.abstract){const p=Rt({id:d.id+"--"+u.id+"--"+re.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.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=Rt({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}"`,severity:H.Error,code:ae.PropertyOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)});const o=[];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&&o.push(p)}),o.length&&o.forEach(p=>{const e=Rt({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}"`,severity:H.Error,code:ae.MethodOverwritesOtherSiblingWithSameName,entity:d});i.push(e.error)}),i}function ZIe(d){const u=[];if(!d.properties.length){const i=Rt({id:d.id+"--"+re.NoProperties,message:"No properties implemented",severity:H.Warning,code:re.NoProperties,entity:d});u.push(i.error)}return d.properties.forEach(i=>{i.validate()}),u}function HIe(d){const u=[];if(d.abstract){if(d.methods.length){const i=Rt({id:d.id+"--"+re.AbstractEntityWithNonAbstractMethods,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract methods`,severity:H.Error,code:re.AbstractEntityWithNonAbstractMethods,entity:d});u.push(i.error)}if(d.properties.some(i=>!i.abstract)){const i=Rt({id:d.id+"--"+re.AbstractEntityWithNonAbstractProperties,message:`Entity "${d.name}" with id "${d.id}" is marked as abstract but has non-abstract properties`,severity:H.Error,code:re.AbstractEntityWithNonAbstractProperties,entity:d});u.push(i.error),d.properties.forEach(a=>{if(!a.abstract){const o=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.StaticEntityWithNonStaticProperties,entity:d});u.push(o.error)}})}}else{if(d.abstractMethods.length){const i=Rt({id:d.id+"--"+re.AbstractPropertyInNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not marked as abstract but has abstract methods`,severity:H.Error,code:re.AbstractPropertyInNonAbstractEntity,entity:d});u.push(i.error)}d.properties.some(i=>i.abstract)&&d.properties.forEach(i=>{if(i.abstract){const a=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.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=Rt({id:d.id+"--"+re.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`,severity:H.Error,code:re.NonStaticPropertyInStaticEntity,entity:d,firstRelationship:i});u.push(a.error)}}),u}function JIe(d,u){const i=[],a=Vi(u);if(!u.abstract){const e=new ir({id:d.id+"--"+u.id+"--"+re.ImplementingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is implementing a non-abstract built-in entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.ImplementingNonAbstractEntity,entity:d,firstRelationship:u});i.push(e)}const o=d.implements.filter(e=>e.id!==u.id);if(d.abstract){const e=new ir({id:d.id+"--"+u.id+"--"+re.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}"`,severity:H.Error,code:re.AbstractEntityImplements,entity:d,firstRelationship:u});i.push(e)}if(d.static&&!u.static){const e=new ir({id:d.id+"--"+u.id+"--"+re.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}"`,severity:H.Error,code:re.StaticImplementingNonStaticEntity,entity:d,firstRelationship:u});i.push(e)}if(!d.static&&u.static){const e=new ir({id:d.id+"--"+u.id+"--"+re.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}"`,severity:H.Error,code:re.NonStaticImplementingStaticEntity,entity:d,firstRelationship:u});i.push(e)}return o.length&&o.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 ir({id:d.id+"--"+v.id+"--"+e.id+"--"+re.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`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:v,secondRelationship:e});i.push(E)}})}else{Vi(e).forEach(w=>{const A=a.filter($=>$.id!==w.id);A.length&&A.forEach($=>{if($.id!==w.id){const V=new ir({id:d.id+"--"+$.id+"--"+w.id+"--"+re.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`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:w});i.push(V)}})});const v=Na(u.ownDeclaredProperties,e.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);i.push(...v.errors);const E=Na(u.abstractMethods,[...e.abstractMethods,...e.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);i.push(...E.errors)}}),R(d.extends?Vi(d.extends):[]).forEach(e=>{if(!a.find(y=>y.id===e.id)){const y=new ir({id:d.id+"--"+u.id+"--"+e.id+"--"+re.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`,severity:H.Error,code:re.ExtendsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:e});i.push(y)}}),i}function WIe(d,u,i=!1){var E,w;const a=[],o=Vi(u);if(!d.abstract&&u.abstract){const A=Rt({id:d.id+"--"+u.id+"--"+re.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is not-abstract but is extending an abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:u});a.push(A.error)}if(d.abstract&&!u.abstract){const A=Rt({id:d.id+"--"+u.id+"--"+re.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but is extending an non-abstract entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:u});a.push(A.error)}if(!d.static&&u.static){const A=Rt({id:d.id+"--"+u.id+"--"+re.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is not static but is extending a static entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.NonStaticExtendingStaticEntity,entity:d,firstRelationship:u});a.push(A.error)}if(d.static&&!u.static){const A=Rt({id:d.id+"--"+u.id+"--"+re.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but is extending an non-static entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.StaticExtendingNonStaticEntity,entity:d,firstRelationship:u});a.push(A.error)}if(!Qp(u)){const A=Rt({id:d.id+"--"+u.id+"--"+re.ExtendingNonInteractiveEntity,message:`Entity "${d.name}" with id "${d.id}" is extending an non-interactive entity "${u.name}" with id "${u.id}"`,severity:H.Error,code:re.ExtendingNonInteractiveEntity,entity:d,firstRelationship:u});a.push(A.error)}if(d.extends&&((E=d.extends)==null?void 0:E.id)!==u.id)if(((w=d.extends)==null?void 0:w.type)===f.BuiltInBaseEntity){const A=o.filter($=>{var V;return $.id!==((V=d.extends)==null?void 0:V.id)});A.length&&A.forEach($=>{var V,B,F,K;if($.id!==((V=d.extends)==null?void 0:V.id)){const q=Rt({id:d.id+"--"+$.id+"--"+((B=d.extends)==null?void 0:B.id)+"--"+re.ExtendsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${$.name}" with id "${$.id}" but also extends entity "${(F=d.extends)==null?void 0:F.name}" with id "${(K=d.extends)==null?void 0:K.id}" which is incompatible`,severity:H.Error,code:re.ExtendsIncompatibleEntities,entity:d,firstRelationship:$,secondRelationship:d.extends});a.push(q.error)}})}else{Vi(d.extends).forEach(q=>{const ie=o.filter(W=>W.id!==q.id);ie.length&&ie.forEach(W=>{if(W.id!==q.id){const de=new ir({id:d.id+"--"+W.id+"--"+q.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${W.name}" with id "${W.id}" but also extends or implements entity "${q.name}" with id "${q.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:W,secondRelationship:q});a.push(de)}})});const $=!!Vi(d.extends).find(q=>q.id===u.id);let V=[...d.extends.properties];$&&(V=V.filter(q=>!u.properties.find(ie=>{var W;return ie.id===q.id||ie.name===q.name||ie.id===((W=q.implements)==null?void 0:W.id)})));let B=[...d.extends.methods];$&&(B=B.filter(q=>!u.methods.find(ie=>{var W;return ie.id===q.id||ie.name===q.name||ie.id===((W=q.implements)==null?void 0:W.id)})));const F=Na(u.ownDeclaredProperties,V,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);a.push(...F.errors);const K=Na(u.abstractMethods,B,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherExtendedEntitysMethodWithSameName);a.push(...K.errors)}i&&Me.log("self.implements.length",d.implements.length),d.implements.length&&d.implements.forEach(A=>{if(A.type===f.BuiltInBaseEntity){const $=o.filter(V=>V.id!==A.id);$.length&&$.forEach(V=>{if(V.id!==A.id){const B=new ir({id:d.id+"--"+V.id+"--"+A.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${A.name}" with id "${A.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:V,secondRelationship:A});a.push(B)}})}else{Vi(A).forEach(F=>{const K=o.filter(q=>q.id!==F.id);K.length&&K.forEach(q=>{if(q.id!==F.id){const ie=new ir({id:d.id+"--"+q.id+"--"+F.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is implementing built-in entity "${q.name}" with id "${q.id}" but also implements entity "${F.name}" with id "${F.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:q,secondRelationship:F});a.push(ie)}})});const V=Na(u.ownDeclaredProperties,A.ownDeclaredProperties,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,ae.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);a.push(...V.errors);const B=Na(u.abstractMethods,[...A.abstractMethods,...A.methods],ae.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,ae.MethodOverwritesOtherImplementedEntitysMethodWithSameName);a.push(...B.errors)}});const e=Na(d.ownDeclaredProperties,u.ownDeclaredProperties,ae.PropertyOverwritesOtherSiblingWithSameImplementation,ae.PropertyOverwritesOtherSiblingWithSameName);a.push(...e.errors);const y=Na(u.methods,u.abstractMethods,ae.MethodOverwritesOtherSiblingWithSameImplementation,ae.MethodOverwritesOtherSiblingWithSameName);return a.push(...y.errors),R(d.extends?Vi(d.extends):[]).forEach(A=>{if(!o.find($=>$.id===A.id)){const $=new ir({id:d.id+"--"+u.id+"--"+A.id+"--"+re.ImplementsIncompatibleEntities,message:`Entity "${d.name}" with id "${d.id}" is extending built-in entity "${u.name}" with id "${u.id}" but also extends entity "${A.name}" with id "${A.id}" which is incompatible`,severity:H.Error,code:re.ImplementsIncompatibleEntities,entity:d,firstRelationship:u,secondRelationship:A});a.push($)}}),a}function YIe(d){const u=[];if(d.implements.forEach(i=>{if(!i.static){const a=new ir({id:d.id+"--"+i.id+"--"+re.StaticImplementingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but implements entity "${i.name}" with id "${i.id}" which is non-static`,severity:H.Error,code:re.StaticImplementingNonStaticEntity,entity:d,firstRelationship:i});u.push(a)}}),d.extends&&!d.extends.static){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.StaticExtendingNonStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-static`,severity:H.Error,code:re.StaticExtendingNonStaticEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function zIe(d){const u=[];if(d.implements.length){const i=new ir({id:d.id+"--"+re.AbstractEntityImplements,message:`Entity "${d.name}" with id "${d.id}" cannot be marked as abstract because it implements other entities`,severity:H.Error,code:re.AbstractEntityImplements,entity:d});u.push(i)}if(d.extends&&!d.extends.abstract){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.AbstractExtendingNonAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is non-abstract`,severity:H.Error,code:re.AbstractExtendingNonAbstractEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function XIe(d){const u=[];if(d.extends&&d.extends.static){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.NonStaticExtendingStaticEntity,message:`Entity "${d.name}" with id "${d.id}" is non-static but extends entity "${d.extends.name}" with id "${d.extends.id}" which is static`,severity:H.Error,code:re.NonStaticExtendingStaticEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function QIe(d){const u=[];if(d.extends&&d.extends.abstract){const i=new ir({id:d.id+"--"+d.extends.id+"--"+re.NonAbstractExtendingAbstractEntity,message:`Entity "${d.name}" with id "${d.id}" is non-abstract but extends entity "${d.extends.name}" with id "${d.extends.id}" which is abstract`,severity:H.Error,code:re.NonAbstractExtendingAbstractEntity,entity:d,firstRelationship:d.extends});u.push(i)}return u}function JS(d,u){const a=[...d.project.entities].filter(o=>o.id!==d.id);return Hp(d,[xr,Il],a,u)}const eAe=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:HS,getBasePropertiesNotImplemented:ZS,validate:qS,validateCanBecomeAbstract:zIe,validateCanBecomeNonAbstract:QIe,validateCanBecomeNonStatic:XIe,validateCanBecomeStatic:YIe,validateCanExtendEntity:WIe,validateCanImplementEntity:JIe,validateDefinitionEntityName:JS},Symbol.toStringTag,{value:"Module"}));function tAe(d,u){const i=[];if(d.parent)if(d.id===d.parent)i.push(new ne({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:H.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.`}));else{const a=u.get(d.parent);a?[f.Project,f.DataType].includes(a.type)||i.push(new ne({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:H.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'.`})):i.push(new ne({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}))}return d.implements&&Array.isArray(d.implements)?d.implements.forEach(a=>{if(d.id===a){i.push(new ne({id:`${d.id}--${a}--${k.SelfReference}`,code:k.SelfReference,severity:H.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.`}));return}const o=u.get(a);o?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(o.type)?o.abstract||i.push(new ne({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:H.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' reference that isn't pointing to an abstract entity.`})):i.push(new ne({id:`${d.id}--${a}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:H.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'.`})):i.push(new ne({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}))}):i.push(new ne({id:`${d.id}--${ae.InvalidObjectStructure}`,code:ae.InvalidObjectStructure,severity:H.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'implements' property that isn't an array.`})),d.extends&&Array.isArray(d.extends)&&d.extends.forEach(a=>{const o=u.get(a);o?[f.DefinitionEntity,f.BuiltInBaseEntity].includes(o.type)?o.abstract&&i.push(new ne({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:H.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?`})):i.push(new ne({id:`${d.id}--${a}--${k.InvalidExtendsReference}`,code:k.InvalidExtendsReference,severity:H.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'.`})):i.push(new ne({id:`${d.id}--${a}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:H.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.`}))}),i}var Bm=(d=>(d.Extends="extends",d.Implements="implements",d))(Bm||{});const qt=class qt extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"static");_(this,"abstract");_(this,"type",f.DefinitionEntity);_(this,"properties",[]);_(this,"methods",[]);_(this,"abstractMethods",[]);_(this,"extends",null);_(this,"implements",[]);_(this,"project");_(this,"errors",[]);_(this,"parent");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"suggestedProperties",[]);_(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:null,implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(i,a){let o=a;if(i.parent){const E=J(i.parent);o=a.get(E)}const p=[];i.implements&&i.implements.forEach(E=>{p.push(a.get(E)||a.getBuiltIn(E))});let e=null;i.extends&&(e=a.get(i.extends)||a.getBuiltIn(i.extends));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:o},v=se(y,a);return v.setParent(o,null),v}static validateGenerationTarget(i,a){let o=JSON.parse(JSON.stringify(i));const p=[],e=tAe(o,a),y=wb(o,a);p.push(...e,...y,...Vr(o));const v=o.parent?a.get(o.parent):null;if(v&&v.type===f.DataType){const E=v;E.entity&&p.push(new ne({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:H.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
|
${Wn({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.`}))}return{errors:p,modifiedData:o}}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?[this.extends]:[]).flatMap(i=>i.allMethods,[]),...this.implements.flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).flatMap(i=>i.allProperties,[]),...this.implements.flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R([...(this.extends?[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?[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?[this.extends]:[]).reduce((i,a)=>{const o=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...o]},[]))}get implementedPropertiesFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).reduce((i,a)=>{const o=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!o.find(y=>y.name===e.name));return[...o,...p,...i]},[]),...this.implements.reduce((i,a)=>{const o=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!o.find(y=>y.name===e.name));return[...o,...p,...i]},[])].filter(i=>!!i.abstract))}get extendedMethodsFromOriginalParents(){return R((this.extends?[this.extends]:[]).reduce((i,a)=>{if(a.type!==f.DefinitionEntity)return[];const o=[...a.ownDeclaredMethods,...a.extendedMethodsFromOriginalParents].filter(p=>p.type!==f.ActionDescriptor);return[...i,...o]},[]))}get implementedMethodsFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).reduce((i,a)=>{const o=a.type===f.DefinitionEntity?a.methods:[],p=[...a.abstractMethods].filter(e=>!o.find(y=>y.name===e.name));return[...o,...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 ne({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:H.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.`})),{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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];return a==="implements"&&this.removeImplementation(i),a==="extends"&&this.setExtension(null,o),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){const p=[],e=[],y=[],v=[];return a==="implements"&&this.addImplementation(i),a==="extends"&&this.setExtension(i,o),{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){return this.implements.forEach(i=>{Zi.includes(i.type)||i.unsubscribeDependents([{entity:this,field:"implements"}])}),this}subscribeToDependencies(){return this.implements.forEach(i=>{Zi.includes(i.type)||i.subscribeDependents([{entity:this,field:"implements"}])}),this.extends&&(Zi.includes(this.extends.type)||this.extends.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=[],o=[],p=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),o.push(...y.added),p.push(...y.removed)}return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(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 o=J(i.parent),p=this.project.get(o),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 '${o}' 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.extends){const o=J(i.extends),p=this.project.get(o);p&&this.setExtension(p,a)}return i.implements.forEach(o=>{const p=J(o),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=[],o=[],p=[];if(this.initialData.parent){const e=J(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'`);if(this.initialData.extends){const e=J(this.initialData.extends),y=this.project.get(e);y&&(this.setExtension(y,null),y.type!==f.BuiltInBaseEntity&&i.push(y))}return this.initialData.implements.forEach(e=>{const y=J(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(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"after-all-children-initialized"))){const a=[],o=[],p=[],e=[];this.initialized=!0;const{updated:y,added:v,removed:E,affected:w}=this.syncImplementationProperties(i);a.push(...y),o.push(...v),p.push(...E),e.push(...w);const{updated:A,added:$,removed:V,affected:B}=this.addExtendedProperties(i);a.push(...A),o.push(...$),p.push(...V),e.push(...B);const{updated:F,added:K,removed:q}=this.removeUnrecognizedProperties(i);a.push(...F),o.push(...K),p.push(...q);const{updated:ie,added:W,removed:de,affected:Q}=this.syncImplementationMethods(i);a.push(...ie),o.push(...W),p.push(...de),e.push(...Q);const{updated:ce,added:X,removed:z,affected:pe}=this.addExtendedMethods(i);a.push(...ce),o.push(...X),p.push(...z),e.push(...pe);const{updated:te,added:ue,removed:Ie}=this.removeUnrecognizedMethods(i);return a.push(...te),o.push(...ue),p.push(...Ie),this.addSuggestions(),this.captureVersion(),i==null||i.attemptAutoclose("after-all-children-initialized",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-self-to-project"))){const a=[this],o=[],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(o),removed:R(p),affected:R(e),self:this}}setParent(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-parent"))){var o;return((o=this.parent)==null?void 0:o.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}setExtension(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"set-extension"))){var o;return((o=this.extends)==null?void 0:o.id)!==(i==null?void 0:i.id)&&(this.extends=i,a&&(a==null||a.add(this,S.Updated))),a==null||a.attemptAutoclose("set-extension",this.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 G(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 o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.methods=this.initialData.methods.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.abstractMethods=this.initialData.abstractMethods.map(a=>{const o=se(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.initialData.extends&&(this.extends=se(this.initialData.extends,this.project)),this.implements=this.initialData.implements.map(a=>se(a,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("init-children",this.id),this)}removeUnrecognizedProperties(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-properties"))){const a=[],o=[],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(o),removed:R(p),affected:R(e),self:this}}removeUnrecognizedMethods(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-unrecognized-methods"))){const a=[],o=[],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(o),removed:R(p),affected:R(e),self:this}}syncImplementationMethods(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-methods"))){const a=[],o=[],p=[],e=[],y=this.methods,v=this.implementedMethodsFromOriginalParents,E=[...this.allBaseMethodsFromExtendedAndImplementedEntities,...y];return v.filter(A=>!E.find(V=>{var B;return((B=V.implements)==null?void 0:B.id)===A.id})).forEach(A=>{if(this.methods.find(F=>{var K;return((K=F.implements)==null?void 0:K.id)===A.id}))return;const V=this.methods.find(F=>{var de,Q;if(F.name===A.name&&!F.implements)return!0;const K=es(this,Le.CRON_JOB),q=es(this,Le.HTTP_ENDPOINT),ie=((de=F.implements)==null?void 0:de.id)===he["built-in-base-entity"].BUILT_IN_HTTP_ENDPOINT_ENTITY.methods.handler.id,W=((Q=F.implements)==null?void 0:Q.id)===he["built-in-base-entity"].BUILT_IN_CRON_JOB_ENTITY.methods.handler.id;return!!(K&&!W&&!q&&ie||q&&!ie&&!K&&W)});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}const B=A.implementAsFunctionDeclaration(i,this);o.push(B),i==null||i.add(B,S.Added),this.addMethod(B)}),i==null||i.attemptAutoclose("sync-implementation-methods",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}syncImplementationProperties(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"sync-implementation-properties"))){const a=[],o=[],p=[],e=[],y=this.properties,v=this.implementedPropertiesFromOriginalParents,E=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...y];return v.filter(A=>!E.find(V=>{var B;return((B=V.implements)==null?void 0:B.id)===A.id})).forEach(A=>{if(this.properties.find(F=>{var K;return((K=F.implements)==null?void 0:K.id)===A.id}))return;const V=this.properties.find(F=>F.name===A.name&&!!F.abstract&&!F.implements);if(V){V.setImplements(A,i),V.metaSync({abstract:!1},i),V.afterAllChildrenInitialized(i);return}const B=A.implement(this,i,N.UUID.uuid());o.push(B),i==null||i.add(B,S.Added)}),i==null||i.attemptAutoclose("sync-implementation-properties",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addExtendedMethods(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-extended-methods"))){const a=[],o=[],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),o.push($),i==null||i.add($,S.Added),this.addMethod($)}),i==null||i.attemptAutoclose("add-extended-methods",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addExtendedProperties(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-extended-properties"))){const a=[],o=[],p=[],e=[],y=this.properties,v=this.extendedPropertiesFromOriginalParents,E=v.filter(A=>v.find(V=>{var B;return((B=V.implements)==null?void 0:B.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),o.push($),i==null||i.add($,S.Added),this.addProperty($)}),i==null||i.attemptAutoclose("add-extended-properties",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSuggestions(){return this.implements.forEach(i=>{ZS(this,i).forEach(p=>{const e=p.toJSON();e.id=`_suggestion--parent--${this.id}--${p.id}`;const y=se(e,this.project);y.suggestion=!0,y.setParent(this,null),y.initChildren(null),this.addSuggestedProperty(y)}),HS(this,i).forEach(p=>{const e=`_suggestion--parent--${this.id}--${p.id}`,y=p.implementAsFunctionDeclaration(null,this,e),v=se(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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(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):o&&(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,...o){return await qt.repository.APILoadVersion(this.id,a,...o)}removeFromParent(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-from-parent"))){const a=[],o=[],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(o),affected:R(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){const o=[],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);o.push(...E),p.push(...w),e.push(...A)}),this.properties.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.methods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.abstractMethods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.suggestedProperties.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),this.suggestedMethods.forEach(v=>{const{updated:E,removed:w}=v.remove({ignoreUpstream:!0},a);o.push(...E),p.push(...w)}),!i){const v=this.removeFromParent(a);e.push(...v.added),o.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(o),removed:R(p),affected:R(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"restore-entity"))){const a=[],o=[],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);o.push(...v),p.push(...E),a.push(...w)}),this.properties.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.methods.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.abstractMethods.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.suggestedProperties.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),this.suggestedMethods.forEach(y=>{const{updated:v}=y.restore({},i);o.push(...v)}),i==null||i.attemptAutoclose("restore-entity",this.id),{added:R(a),updated:R(o),removed:R(p),affected:R(e),self:this})}toFlat(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this,...((o=this.extends)==null?void 0:o.toFlat(i))||[],...this.implements.flatMap(p=>p.toFlat(i)),...this.properties.flatMap(p=>p.toFlat(i)),...this.methods.flatMap(p=>p.toFlat(i)),...this.abstractMethods.flatMap(p=>p.toFlat(i)),...this.parent.toFlat(i)])}toFlatIds(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this.id,...((o=this.extends)==null?void 0:o.toFlatIds(i))||[],...this.implements.flatMap(p=>p.toFlatIds(i)),...this.properties.flatMap(p=>p.toFlatIds(i)),...this.methods.flatMap(p=>p.toFlatIds(i)),...this.abstractMethods.flatMap(p=>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,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(i=new Set){var a;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(o=>o.toJSON(i)),methods:this.methods.map(o=>o.toJSON(i)),abstractMethods:this.abstractMethods.map(o=>o.toJSON(i)),implements:this.implements.map(o=>o.toJSON(i)),extends:((a=this.extends)==null?void 0:a.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Se){var o,p,e,y,v,E,w,A;let a;return(o=i.seenEntityMaps)!=null&&o.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||jr(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($=>$.toJSONClone({...i,newId:null})),methods:this.methods.map($=>$.toJSONClone({...i,newId:null})),abstractMethods:this.abstractMethods.map($=>$.toJSONClone({...i,newId:null})),implements:this.implements.map($=>$.type===f.BuiltInBaseEntity?$.toJSON(i.seenEntities):$.toJSONClone({...i,newId:null})),extends:((E=this.extends)==null?void 0:E.type)===f.BuiltInBaseEntity?(w=this.extends)==null?void 0:w.toJSON(i.seenEntities):(A=this.extends)==null?void 0:A.toJSONClone({...i,newId:null}),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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=Se){var o,p;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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(e=>e.toReference(i)),methods:this.methods.map(e=>e.toReference(i)),abstractMethods:this.abstractMethods.map(e=>e.toReference(i)),implements:this.implements.map(e=>e.toReference(i)),extends:((p=this.extends)==null?void 0:p.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(p=>p.toFlatJSON(i)),...this.methods.flatMap(p=>p.toFlatJSON(i)),...this.abstractMethods.flatMap(p=>p.toFlatJSON(i)),...this.implements.flatMap(p=>p.toFlatJSON(i)),...((o=this.extends)==null?void 0:o.toFlatJSON(i))||[],...this.parent.toFlatJSON(i)])}toGenerationTarget(){var a;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:(a=this.extends)==null?void 0:a.id,implements:this.implements.map(o=>o.id),parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(o=>o.toFlatGenerationTarget(i)),...this.methods.flatMap(o=>o.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(o=>o.toFlatGenerationTarget(i)),...this.implements.filter(o=>o.type===f.DefinitionEntity).flatMap(o=>o.toFlatGenerationTarget(i)),...this.implements.filter(o=>o.type===f.DefinitionEntity).flatMap(o=>o.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=qS(this),{success:!0}}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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"clone-entity")),a=null,o=null,p=!0){var F,K,q;let e=Ur(a,this);const y=this.toJSON(),v=o||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=dr(y,e);a&&A.setParent(a,null),p&&A.subscribe(),A.initChildren(i),i==null||i.add(A,S.Added);const $=(F=this.properties)==null?void 0:F.map(ie=>ie.clone(i,A,N.UUID.uuid(),p));A.properties=$;const V=(K=this.methods)==null?void 0:K.map((ie,W)=>ie.clone(i,A,w+"-method-"+W+"-id",p));A.methods=V;const B=(q=this.abstractMethods)==null?void 0:q.map((ie,W)=>ie.clone(i,A,w+"-abstract-method-"+W+"-id",p));return A.abstractMethods=B,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 G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"implement-definition-entity")),o){const p=vm(this,i,a,o);return a==null||a.attemptAutoclose("implement-definition-entity",this.id),p}getAllInteractiveMethods(){var o;const i=this.implements.filter(p=>p.type===f.DefinitionEntity||p.type===f.BuiltInBaseEntity&&p.interactive);return R([...this.methods,...((o=this.extends)==null?void 0:o.getAllInteractiveMethods())||[],...i.flatMap(p=>p.getAllInteractiveMethods())])}inferFromInputs(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const o=[],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=>Y(V,this.project)===Y(A,this.project))||v.push(A)});const E=this.properties.filter(A=>!A.dataType);v.forEach(A=>{var ie,W,de;const $=E.find(Q=>Y(Q,this.project)===Y(A,this.project));if(!$)return;const B=Ni(A.parent).getMasterInputWithValueWritterFromAllInstances(A),F=pn(B,a),K=F==null?void 0:F.clone(a,$,N.UUID.uuid(),!0);K&&((ie=$.dataType)==null||ie.merge(K,a),K.id!==((W=$.dataType)==null?void 0:W.id)&&K.remove({ignoreUpstream:!1},a),$.dataType&&($.dataType.metaSync({inferred:!0,like:!0},a),$.setDataType($.dataType,a),a==null||a.add($,S.Affected)));let q=null;if(A.declaration&&$.id!==((de=A.declaration)==null?void 0:de.id)&&(q=A.declaration),A.setDeclaration($,a),a==null||a.add(A,S.Updated),q){const{updated:Q,removed:ce}=q.remove({ignoreUpstream:!1},a);p.push(...Q),e.push(...ce)}});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 W,de,Q,ce;const $=this.properties.find(X=>Y(X,this.project)===Y(A,this.project));if($){if(A.setDeclaration($,a),!$.getDataType(a)){const z=Ni(A.parent).getMasterInputWithValueWritterFromAllInstances(A),pe=pn(z),te=pe==null?void 0:pe.clone(a,$,N.UUID.uuid(),!0);te&&((W=$.dataType)==null||W.merge(te,a),te.id!==((de=$.dataType)==null?void 0:de.id)&&te.remove({ignoreUpstream:!1},a),$.dataType&&($.dataType.metaSync({inferred:!0,like:!0},a),$.setDataType($.dataType,a),a==null||a.add($,S.Affected)))}return}const V=zn.new(a);V.parent=this.toReference(),V.index=A.index,V.name=Y(A,this.project),V.codeName=A.codeName,V.description=A.description;const B=se(V,this.project);B.hydrateAncestors(),a==null||a.add(B,S.Added),B.setParent(this,a),B.initChildren(a);const K=Ni(A.parent).getMasterInputWithValueWritterFromAllInstances(A),q=pn(K),ie=q==null?void 0:q.clone(a,B,N.UUID.uuid(),!0);return ie&&((Q=B.dataType)==null||Q.merge(ie,a),ie.id!==((ce=B.dataType)==null?void 0:ce.id)&&ie.remove({ignoreUpstream:!1},a),B.dataType&&(B.dataType.metaSync({inferred:!0,like:!0},a),B.setDataType(B.dataType,a),a==null||a.add(B,S.Affected))),this.addProperty(B),A.setDeclaration(B,a),a==null||a.add(A,S.Updated),B}),a==null||a.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:R(o),updated:R(p),removed:R(e),affected:R(y),self:this})}getRawDefaultValue(){const i={};return this.properties.forEach(a=>{var p;if(!bb(a))return;const o=xr(a.name);i[o]=((p=a.getDefaultValue())==null?void 0:p.value)||null}),i}getActiveRawDefaultValue(){const i={};return this.properties.forEach(a=>{var e;if(!bb(a))return;const o=xr(a.name),p=(e=this.project.requestActiveDynamicValue(a))==null?void 0:e.value;i[o]=(p==null?void 0:p.value)||null}),i}};_(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,...o)=>null}),_(qt,"type",f.DefinitionEntity),_(qt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.DataType]),_(qt,"PARENT_TYPES",[...qt.USER_MANAGED_PARENT_TYPES]),_(qt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","static","abstract"]),_(qt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(qt,"BASE_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,...qt.INMUTABLE_BASE_PROPERTIES]),_(qt,"MUTABLE_META_PROPERTIES",[...qt.MUTABLE_BASE_PROPERTIES,"x","y"]),_(qt,"INMUTABLE_META_PROPERTIES",[...qt.INMUTABLE_BASE_PROPERTIES]),_(qt,"META_PROPERTIES",[...qt.MUTABLE_META_PROPERTIES,...qt.INMUTABLE_META_PROPERTIES]),_(qt,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),_(qt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),_(qt,"UPSTREAM_PROPERTIES",[...qt.MUTABLE_UPSTREAM_PROPERTIES,...qt.INMUTABLE_UPSTREAM_PROPERTIES]),_(qt,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),_(qt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(qt,"DOWNSTREAM_PROPERTIES",[...qt.MUTABLE_DOWNSTREAM_PROPERTIES,...qt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(qt,"PROPERTIES",[...qt.META_PROPERTIES,...qt.UPSTREAM_PROPERTIES,...qt.DOWNSTREAM_PROPERTIES]);let Xn=qt;function rAe(d){const u=[];return Er(d.errors,u)}const of=class of extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"version");_(this,"name");_(this,"description",null);_(this,"type",f.BuiltInBaseEntity);_(this,"abstract",!1);_(this,"static");_(this,"properties",[]);_(this,"methods",[]);_(this,"abstractMethods",[]);_(this,"extends",null);_(this,"interactive",!1);_(this,"errors",[]);_(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(o=>{const p=se(o,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(o=>{const p=se(o,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.abstractMethods=this.initialData.abstractMethods.map(o=>{const p=se(o,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.initialData.extends&&(this.extends=se(this.initialData.extends,this.project))}get allMethods(){return R([...this.ownDeclaredMethods,...this.allBaseMethodsFromOriginalParents])}get allProperties(){return R([...this.ownDeclaredProperties,...this.allBasePropertiesFromOriginalParents])}get allBaseMethodsFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R((this.extends?[this.extends]:[]).reduce((i,a)=>{const o=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...o]},[]))}get extendedPropertiesFromOriginalParents(){return R((this.extends?[this.extends]:[]).reduce((i,a)=>{const o=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...o]},[]))}get implementedPropertiesFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).reduce((i,a)=>{const o=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!o.find(y=>y.name===e.name));return[...o,...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 of.repository.APILoad(this.id,...a),this}toFlat(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this,...this.properties.flatMap(p=>p.toFlat(i)),...this.methods.flatMap(p=>p.toFlat(i)),...this.abstractMethods.flatMap(p=>p.toFlat(i)),...((o=this.extends)==null?void 0:o.toFlat(i))||[]])}toFlatIds(i=new Set){var o;return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(p=>p.toFlatIds(i)),...this.methods.flatMap(p=>p.toFlatIds(i)),...this.abstractMethods.flatMap(p=>p.toFlatIds(i)),...((o=this.extends)==null?void 0:o.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){var a;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(o=>o.toJSON(i)),methods:this.methods.map(o=>o.toJSON(i)),abstractMethods:this.abstractMethods.map(o=>o.toJSON(i)),extends:((a=this.extends)==null?void 0:a.toJSON(i))||null})}toReference(i=Se){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=Se){var a;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(o=>o.toReference()),methods:this.methods.map(o=>o.toReference()),abstractMethods:this.abstractMethods.map(o=>o.toReference()),extends:((a=this.extends)==null?void 0:a.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(o=>o.toFlatJSON(i)),...this.methods.flatMap(o=>o.toFlatJSON(i)),...this.abstractMethods.flatMap(o=>o.toFlatJSON(i))])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(o=>o.toFlatGenerationTarget(i)),...this.methods.flatMap(o=>o.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(o=>o.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=rAe(this);return this.errors=i,{success:!0}}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 G(this.project,N.sessionAuthor,L().toISOString(),null,!0,"implement-built-in-base-entity")),o){const p=vm(this,i,a,o);return a==null||a.attemptAutoclose("implement-built-in-base-entity",this.id),p}getAllInteractiveMethods(){const i=[];if(this.interactive){if(i.push(...this.methods),!this.extends||this.extends.type===f.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===f.PrimitiveEntity)return i;this.extends instanceof of&&i.push(...this.extends.getAllInteractiveMethods())}return R(i)}};_(of,"repository",{APILoad:async(i,...a)=>null});let Qn=of;function iAe(d){const u=[];return Er(d.errors,u)}const Gm=class Gm extends Cr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"description",null);_(this,"type",f.PrimitiveEntity);_(this,"static");_(this,"abstract");_(this,"properties",[]);_(this,"methods",[]);_(this,"abstractMethods",[]);_(this,"extends",null);_(this,"errors",[]);_(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(o=>{const p=se(o,this.project);return p.setParent(this,null),p.initChildren(null),p}),this.methods=this.initialData.methods.map(o=>{const p=se(o,this.project);return p.parent=this,p}),this.abstractMethods=this.initialData.abstractMethods.map(o=>{const p=se(o,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?[this.extends]:[]).flatMap(i=>i.allMethods,[])])}get allBasePropertiesFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).flatMap(i=>i.allProperties,[])])}get allBasePropertiesFromExtendedAndImplementedEntities(){return R((this.extends?[this.extends]:[]).reduce((i,a)=>{const o=[...a.ownDeclaredProperties,...a.allBasePropertiesFromExtendedAndImplementedEntities].filter(p=>!p.abstract);return[...i,...o]},[]))}get extendedPropertiesFromOriginalParents(){return R((this.extends?[this.extends]:[]).reduce((i,a)=>{const o=[...a.ownDeclaredProperties,...a.extendedPropertiesFromOriginalParents].filter(p=>!p.abstract);return[...i,...o]},[]))}get implementedPropertiesFromOriginalParents(){return R([...(this.extends?[this.extends]:[]).reduce((i,a)=>{const o=a.implementedPropertiesFromOriginalParents,p=[...a.ownDeclaredProperties].filter(e=>!!e.abstract&&!o.find(y=>y.name===e.name));return[...o,...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(o=>o.toFlat(i)),...this.methods.flatMap(o=>o.toFlat(i)),...this.abstractMethods.flatMap(o=>o.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.properties.flatMap(o=>o.toFlatIds(i)),...this.methods.flatMap(o=>o.toFlatIds(i)),...this.abstractMethods.flatMap(o=>o.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){var a;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(o=>o.toJSON(i)),methods:this.methods.map(o=>o.toJSON(i)),abstractMethods:this.abstractMethods.map(o=>o.toJSON(i)),extends:((a=this.extends)==null?void 0:a.toJSON(i))||null})}toReference(i=Se){return{id:this.id+"--"+N.UUID.uuid()+"--ref",type:f.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(i=Se){var a;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(o=>o.toReference()),methods:this.methods.map(o=>o.toReference()),abstractMethods:this.abstractMethods.map(o=>o.toReference()),extends:((a=this.extends)==null?void 0:a.toReference())||null}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(o=>o.toFlatJSON(i)),...this.methods.flatMap(o=>o.toFlatJSON(i)),...this.abstractMethods.flatMap(o=>o.toFlatJSON(i))])}toGenerationTarget(){var i;return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:(i=this.extends)==null?void 0:i.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(o=>o.toFlatGenerationTarget(i)),...this.methods.flatMap(o=>o.toFlatGenerationTarget(i)),...this.abstractMethods.flatMap(o=>o.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=iAe(this);return this.errors=i,{success:!0}}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||this.extends.type===f.BuiltInBaseEntity&&this.extends.interactive||this.extends.type===f.PrimitiveEntity?i:(this.extends instanceof Qn&&i.push(...this.extends.getAllInteractiveMethods()),R(i))}};_(Gm,"repository",{APILoad:async(i,...a)=>null});let ts=Gm;function dr(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 Si(d,u);case f.DefinitionEntity:return i||new Xn(d,u);case f.PrimitiveEntity:return i||new ts(d,u);case f.FunctionDeclaration:return i||new Xa(d,u);case f.GlobalEvent:return i||new to(d,u);case f.DataType:return i||new fs(d,u);case f.Property:return i||new zn(d,u);case f.FunctionCall:return i||new Eo(d,u);case f.Condition:return i||new ro(d,u);case f.Operation:return i||new Qa(d,u);case f.VariableDeclaration:return i||new so(d,u);case f.VariableInstance:return i||new io(d,u);case f.OutputMap:return i||new fn(d,u);case f.ReturnDeclaration:return i||new Qi(d,u);case f.ArgumentDeclaration:return i||new Kn(d,u);case f.InputMap:return i||new Zn(d,u);case f.Project:return i||new N(d);case f.InstalledProject:return i||new ao(d,u);case f.ActionDescriptor:return i||new ut(d,u);case f.ReturnStatement:return i||new eo(d,u);case f.Loop:return i||new Gi(d,u);case f.Search:return i||new no(d,u);case f.ValueDescriptor:return i||new hn(d,u);case f.BuiltInBaseEntity:return i||new Qn(d,u);case f.InternalCall:return i||new oo(d,u);case f.ContinueStatement:return i||new Pi(d,u);case f.BreakStatement:return i||new lo(d,u);case f.GenericReference:return u.get(d.entityId);default:throw new Error("Invalid entity type: "+d.type)}}function se(d,u){if(!d)throw new Error("Entity is null");const i=dr(d,u);return i.subscribe(),i}function sAe(d,u){if(!d)throw new Error("Entity is null");switch(d.type){case f.LiteralValue:return Si.fromGenerationTarget(d,u);case f.DefinitionEntity:return Xn.fromGenerationTarget(d,u);case f.FunctionDeclaration:return Xa.fromGenerationTarget(d,u);case f.GlobalEvent:return to.fromGenerationTarget(d,u);case f.DataType:return fs.fromGenerationTarget(d,u);case f.Property:return zn.fromGenerationTarget(d,u);case f.FunctionCall:return Eo.fromGenerationTarget(d,u);case f.Condition:return ro.fromGenerationTarget(d,u);case f.Operation:return Qa.fromGenerationTarget(d,u);case f.VariableDeclaration:return so.fromGenerationTarget(d,u);case f.VariableInstance:return io.fromGenerationTarget(d,u);case f.OutputMap:return fn.fromGenerationTarget(d,u);case f.ReturnDeclaration:return Qi.fromGenerationTarget(d,u);case f.ArgumentDeclaration:return Kn.fromGenerationTarget(d,u);case f.InputMap:return Zn.fromGenerationTarget(d,u);case f.InstalledProject:return ao.fromGenerationTarget(d,u);case f.ReturnStatement:return eo.fromGenerationTarget(d,u);case f.Loop:return Gi.fromGenerationTarget(d,u);case f.Search:return no.fromGenerationTarget(d,u);case f.ActionDescriptor:return ut.fromGenerationTarget(d,u);case f.ValueDescriptor:return hn.fromGenerationTarget(d,u);case f.InternalCall:return oo.fromGenerationTarget(d,u);case f.ContinueStatement:return Pi.fromGenerationTarget(d,u);case f.BreakStatement:return lo.fromGenerationTarget(d,u);default:throw new Error("Invalid entity type: "+d.type)}}const Se={seenEntityMaps:new Map,seenEntities:new Set,timestamp:L().toISOString()};class WS{constructor(){_(this,"initialData")}}const ve={cascade:!1},YS={APILoad:async(d,...u)=>null},nAe={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,...YS};class aAe{}class oAe extends WS{}class lAe{}class dAe{}class uAe{}class Nb{}class cAe extends Nb{}class pAe extends Nb{}class fAe{}class sf{static initReadsValue(u){if(u.initialData.readsValue&&u.initialData.readsValue.type!==f.GenericReference)u.readsValue=se(u.initialData.readsValue,u.project);else if(u.initialData.readsValue&&u.initialData.readsValue.type===f.GenericReference){const i=qi(u.initialData.readsValue,u.project);i&&(u.readsValue=i)}if(u.readsValue){if(Tt.includes(u.readsValue.type)){let i=u.parent;Nr.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 nf{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=se(e,u.project);return y.setValueWriter(u,null),Tt.includes(y.type)&&(y.setParent(i,null),y.initChildren(null)),[...p,y]},[]),o=[...u.writesValues];return u.writesValues=R([...o,...a]),u.writesValues}}class hAe{}var $r=(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))($r||{});const Vb={...PA,events:new xp},zS={requestActiveDynamicValue:d=>null,...Vb},ft=class ft extends Cr{constructor(i,a={...zS,events:new xp}){super(i);_(this,"initialData");_(this,"id");_(this,"type",f.Project);_(this,"name",null);_(this,"description",null);_(this,"x");_(this,"y");_(this,"entities",[]);_(this,"projects",[]);_(this,"functions",[]);_(this,"events",[]);_(this,"variableDeclarations",[]);_(this,"variableInstances",[]);_(this,"conditions",[]);_(this,"operations",[]);_(this,"functionCalls",[]);_(this,"loops",[]);_(this,"searches",[]);_(this,"primitives",[]);_(this,"builtInBaseEntities",[]);_(this,"operationDeclarations",[]);_(this,"globalEventActionDescriptors",[]);_(this,"loopDeclarations",[]);_(this,"loopDeclarationsBodies",[]);_(this,"conditionDeclarations",[]);_(this,"valueDescriptors",[]);_(this,"dataTypes",[]);_(this,"project");_(this,"instances",{});_(this,"builtInInstances",{});_(this,"deletedInstances",{});_(this,"errors",[]);_(this,"references",[]);_(this,"history",[]);_(this,"undoableStackValueIndex",-1);_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"onCloseChangeSetCallback",null);_(this,"onAddChangeSetCallback",null);_(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,!ft.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:ft.UUID.uuid(),version:ft.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||L().toISOString(),author:(i==null?void 0:i.author)||ft.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 o=JSON.parse(JSON.stringify(i));const p=[];return p.push(...Vr(o)),{errors:p,modifiedData:o}}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),o=this.history.slice(0,a),p=o[o.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,o,p=!1,e="here-this"){if(!this.history.length)return new G(this,i,a,o,p,e);const y=this.history[this.history.length-1];return y.open?y:this.addChangeSet(new G(this,i,a,o,p,e))}addChangeSet(i){var p,e;if(!this.history.length)return this.undoableStackValueIndex=RI(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 o=this.history.find(y=>y.open);if(o)throw Me.warn("Previous still open: ",o),Me.warn("New change set: ",i),new Error(`There is already an open change-set with id '${o.id}'.`);return this.undoableStackValueIndex=RI(this.undoableStackValueIndex,this.history,i),(e=this.onAddChangeSetCallback)==null||e.call(this,i,this.undoableStackValueIndex),i}discardChangeSet(i){var o;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,(o=this.onDiscardChangeSetCallback)==null||o.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 G(this.project,ft.sessionAuthor,L().toISOString(),this,!0,"sync-dependents"))){const a=[],o=[],p=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),o.push(...v.added),p.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}onDetachedDependencyRemoved(i,a,o){const p=[],e=[],y=[],v=[];return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}onDetachedDependencyRestored(i,a,o){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=ft.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 ft(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=[],o=[],p=[],e=[];return{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}async restoreVersion(i){var v;const a=[],o=[],p=[],e=[];if(this.version===i)return{updated:R(a),added:R(o),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 ft(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(o),removed:R(p),affected:R(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,ft.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=[],o=[],p=[];return{updated:R(i),added:R(a),removed:R(o),affected:R(p),self:this}}afterAllChildrenInitialized(i=null){const a=[],o=[],p=[],e=[];return this.initialized||(this.initialized=!0,this.emit("project-initialized",this,i)),this.validate(),this.captureVersion(),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}addSelfToProject(i){const a=[],o=[],p=[],e=[];return this.subscribe(),this.subscribeToDependencies(),{updated:R(a),added:R(o),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 G(this.project,ft.sessionAuthor,L().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.projects=this.initialData.projects.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.variableDeclarations=this.initialData.variableDeclarations.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.variableInstances=this.initialData.variableInstances.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.conditions=this.initialData.conditions.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.operations=this.initialData.operations.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.functions=this.initialData.functions.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.events=this.initialData.events.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.functionCalls=this.initialData.functionCalls.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.loops=this.initialData.loops.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),this.searches=this.initialData.searches.map(a=>{const o=se(a,this);return o.setParent(this,null),o.initChildren(i),o}),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 G(this.project,ft.sessionAuthor,L().toISOString(),this,!0,"meta-sync"))){const o=Lr(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):o&&(a==null||a.add(this,S.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await ft.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await ft.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await ft.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await ft.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await ft.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await ft.repository.APILoadVersion(this.id,a,...o)}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,ft.sessionAuthor,L().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,ft.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(o=>o.toFlat(i)),...this.functions.flatMap(o=>o.toFlat(i)),...this.events.flatMap(o=>o.toFlat(i)),...this.projects.flatMap(o=>o.toFlat(i)),...this.variableDeclarations.flatMap(o=>o.toFlat(i)),...this.variableInstances.flatMap(o=>o.toFlat(i)),...this.conditions.flatMap(o=>o.toFlat(i)),...this.operations.flatMap(o=>o.toFlat(i)),...this.functionCalls.flatMap(o=>o.toFlat(i)),...this.loops.flatMap(o=>o.toFlat(i)),...this.searches.flatMap(o=>o.toFlat(i))])}toFlatIds(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.id,...this.entities.flatMap(o=>o.toFlatIds(i)),...this.functions.flatMap(o=>o.toFlatIds(i)),...this.events.flatMap(o=>o.toFlatIds(i)),...this.projects.flatMap(o=>o.toFlatIds(i)),...this.variableDeclarations.flatMap(o=>o.toFlatIds(i)),...this.variableInstances.flatMap(o=>o.toFlatIds(i)),...this.conditions.flatMap(o=>o.toFlatIds(i)),...this.operations.flatMap(o=>o.toFlatIds(i)),...this.functionCalls.flatMap(o=>o.toFlatIds(i)),...this.loops.flatMap(o=>o.toFlatIds(i)),...this.searches.flatMap(o=>o.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,o=new Set,p=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(e=>{if(p.includes(e)){a.set(e,e);return}a.set(e,ft.UUID.uuid())}),o.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:o,newId:null})),projects:this.projects.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),variableDeclarations:this.variableDeclarations.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),variableInstances:this.variableInstances.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),conditions:this.conditions.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),operations:this.operations.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),functions:this.functions.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),events:this.events.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),functionCalls:this.functionCalls.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),loops:this.loops.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null})),searches:this.searches.map(e=>e.toJSONClone({...i,seenEntityMaps:a,seenEntities:o,newId:null}))}}toReference(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+ft.UUID.uuid()+"--ref",type:f.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=Se){var o;let a=this.id;return(o=i.seenEntityMaps)!=null&&o.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(o=>o.toFlatJSON(i)),...this.functions.flatMap(o=>o.toFlatJSON(i)),...this.events.flatMap(o=>o.toFlatJSON(i)),...this.projects.flatMap(o=>o.toFlatJSON(i)),...this.variableDeclarations.flatMap(o=>o.toFlatJSON(i)),...this.variableInstances.flatMap(o=>o.toFlatJSON(i)),...this.conditions.flatMap(o=>o.toFlatJSON(i)),...this.operations.flatMap(o=>o.toFlatJSON(i)),...this.functionCalls.flatMap(o=>o.toFlatJSON(i)),...this.loops.flatMap(o=>o.toFlatJSON(i)),...this.searches.flatMap(o=>o.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(o=>o.toFlatGenerationTarget(i)),...this.functions.flatMap(o=>o.toFlatGenerationTarget(i)),...this.events.flatMap(o=>o.toFlatGenerationTarget(i)),...this.projects.flatMap(o=>o.toFlatGenerationTarget(i)),...this.variableDeclarations.flatMap(o=>o.toFlatGenerationTarget(i)),...this.variableInstances.flatMap(o=>o.toFlatGenerationTarget(i)),...this.conditions.flatMap(o=>o.toFlatGenerationTarget(i)),...this.operations.flatMap(o=>o.toFlatGenerationTarget(i)),...this.functionCalls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.loops.flatMap(o=>o.toFlatGenerationTarget(i)),...this.searches.flatMap(o=>o.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(){return this.validateChildren(),JT([...this.errors]),{success:!0}}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(o=>o.id===i.id);if(a>-1){const o=this.entities[a];return this.entities.splice(a,1),o}return null}removeCondition(i){const a=this.conditions.findIndex(o=>o.id===i.id);if(a>-1){const o=this.conditions[a];return this.conditions.splice(a,1),o}return null}removeOperation(i){const a=this.operations.findIndex(o=>o.id===i.id);if(a>-1){const o=this.operations[a];return this.operations.splice(a,1),o}return null}removeLoop(i){const a=this.loops.findIndex(o=>o.id===i.id);if(a>-1){const o=this.loops[a];return this.loops.splice(a,1),o}return null}removeSearch(i){const a=this.searches.findIndex(o=>o.id===i.id);if(a>-1){const o=this.searches[a];return this.searches.splice(a,1),o}return null}removeFunctionCall(i){const a=this.functionCalls.findIndex(o=>o.id===i.id);if(a>-1){const o=this.functionCalls[a];return this.functionCalls.splice(a,1),o}return null}removeVariableInstance(i){const a=this.variableInstances.findIndex(o=>o.id===i.id);if(a>-1){const o=this.variableInstances[a];return this.variableInstances.splice(a,1),o}return null}removeVariableDeclaration(i){const a=this.variableDeclarations.findIndex(o=>o.id===i.id);if(a>-1){const o=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),o}return null}removeFunctionDeclaration(i){const a=this.functions.findIndex(o=>o.id===i.id);if(a>-1){const o=this.functions[a];return this.functions.splice(a,1),o}return null}removeInstalledProject(i){const a=this.projects.findIndex(o=>o.id===i.id);if(a>-1){const o=this.projects[a];return this.projects.splice(a,1),o}return null}removeGlobalEvent(i){const a=this.events.findIndex(o=>o.id===i.id);if(a>-1){const o=this.events[a];return this.events.splice(a,1),o}return null}removeTopLevelVariableDeclaration(i){if(i.type!==f.VariableDeclaration)return null;const a=this.variableDeclarations.findIndex(o=>o.id===i.id);if(a>-1){const o=this.variableDeclarations[a];return this.variableDeclarations.splice(a,1),o}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(a=>a.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((a,o)=>{const p=yt(o);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,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.functionCalls.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.operations.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.loops.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Condition)]},[]),...this.searches.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.functionCalls.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.conditions.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.loops.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Operation)]},[]),...this.searches.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.conditions.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.operations.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.loops.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[]),...this.searches.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((a,o)=>{const p=vr(o);return[...a,...p]},[]),...this.functionCalls.reduce((a,o)=>{const p=vr(o);return[...a,...p]},[]),...this.conditions.reduce((a,o)=>{const p=vr(o);return[...a,...p]},[]),...this.operations.reduce((a,o)=>{const p=vr(o);return[...a,...p]},[]),...this.loops.reduce((a,o)=>{const p=vr(o);return[...a,...p]},[]),...this.searches.reduce((a,o)=>{const p=vr(o);return[...a,...p]},[])]}getVariableInstances(){return[...this.variableInstances,...this.entities.reduce((a,o)=>[...a,...o.methods.flatMap(p=>{const y=yt(p).filter(v=>v.type===f.VariableInstance);return[...a,...y]})],[]),...this.getEntryPoints().reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.functionCalls.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.conditions.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.operations.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.loops.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[]),...this.searches.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableInstance);return[...a,...e]},[])]}getVariableDeclarations(){return R([...this.variableDeclarations,...this.entities.reduce((a,o)=>[...a,...o.methods.flatMap(p=>{const y=yt(p).filter(v=>v.type===f.VariableDeclaration);return[...a,...y]})],[]),...this.getEntryPoints().reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.functionCalls.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.conditions.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.operations.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.loops.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[]),...this.searches.reduce((a,o)=>{const e=vr(o).filter(y=>y.type===f.VariableDeclaration);return[...a,...e]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.functionCalls.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.conditions.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.operations.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Loop)]},[]),...this.searches.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.functionCalls.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.conditions.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.operations.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Search)]},[]),...this.loops.reduce((a,o)=>{const p=yt(o);return[...a,...p.filter(e=>e.type===f.Search)]},[])]}attachOrphanReferences(){const i=this.getVariableInstances(),a=this.getVariableDeclarations();return i.forEach(o=>{if(!o.declaration){const p=o.initialData,e=p.declaration.entityId||p.declaration.id,y=a.find(v=>v.id===e);y&&o.setDeclaration(y)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(i=>i.name===Le.PERSISTED_ENTITY)||null}requestActiveDynamicValue(i){var o,p;const a=(p=(o=this.parentContext).requestActiveDynamicValue)==null?void 0:p.call(o,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"?Gu:a||null}return i==="uuid"?Gu: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()),bI(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()),bI(i||"initial",a||"initial",this)}applyExternalChangeSet(i){const a=i.payload,o=this.addChangeSet(new G(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 Yn(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(`,
|