@elyx-code/project-logic-tree 0.0.6453 → 0.0.6454

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.
@@ -31,7 +31,7 @@ If you want to implement a new method, you can create a new 'function-declaratio
31
31
  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.`}))}}else if(v&&v.type===f.Loop){const $=v.body;$&&((A=$.implements)==null?void 0:A.id)===o.implements&&p.push(new re({id:`${o.id}--${ee.LoopBodyFunctionOverwrite}`,code:ee.LoopBodyFunctionOverwrite,severity:q.Error,message:`The '${f.FunctionDeclaration}' with id "${o.id}" is being added as the 'body' of the ${f.Loop} with id "${v.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`}))}const E=o.parent&&a.get(o.parent)||a.getBuiltIn(o.parent),b=E?yo(E):null;return b&&p.push(new re({id:`${i.id}--${k.BuiltInEntityParent}`,code:k.BuiltInEntityParent,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', belongs to a built-in system entity "${W(b,a)}" with id '${b.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`})),p.push(...e.errors,...y,...Vr(o)),{errors:p,modifiedData:o}}get isExtendedMethod(){if(this.parent.type!==f.DefinitionEntity)return!1;const i=this.parent.allBaseMethodsFromExtendedAndImplementedEntities.find(a=>{var o;return a.id===((o=this.extends)==null?void 0:o.id)});return!!i&&i.id!==this.id&&i.type!==f.ActionDescriptor}get returnStatements(){return bt(this).filter(o=>o.type===f.ReturnStatement&&o.parent.id===this.id)}validateGeneratedUpdate(i){const a=[];return i.parent&&(this.parent.type===f.Project?a.push(new re({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
32
32
  This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`})):a.push(new re({id:`${this.id}--${k.InvalidParentUpdate}`,code:k.InvalidParentUpdate,severity:q.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
33
33
  This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.
34
- Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`}))),{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==="function-declaration-implements"&&this.setImplements(null,o),a==="function-declaration-extends"){const{updated:E,added:b,removed:A,affected:$}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),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==="function-declaration-implements"&&(this.setImplements(i,o),p.push(i)),a==="function-declaration-extends"){const{updated:E,added:b,removed:A,affected:$}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a;return(i=this.implements)==null||i.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var i,a;return(i=this.implements)==null||i.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.subscribeDependents([{entity:this,field:"function-declaration-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 Nt(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.calls=[...this.calls],i.implements=this.implements,i.extends=this.extends,i.detachedChildren=[...this.detachedChildren],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[b,A]of this.knownVersions||new Map){if(E.set(b,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 Nt(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.calls=y.calls,this.implements=y.implements,this.detachedChildren=y.detachedChildren,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=H(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=H(i.implements),p=this.project.get(o);if(p)this.setImplements(p,a);else if(o)throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),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=H(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=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'parent' reference "${e}" which is missing in the project`)}else throw new Error(`${Ii(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const e=H(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=H(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}=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.addFunctionDeclaration(this):this.parent.type===f.DefinitionEntity?(this.parent.addMethod(this),e.push(this.parent)):this.parent.type===f.Loop&&(this.parent.setBody(this),e.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}}replaceDetachedChild(i,a){const o=this.detachedChildren.indexOf(i);return o!==-1&&(this.detachedChildren[o]=a),this}subscribeDetachedChild(i){return this.detachedChildren.includes(i)||this.detachedChildren.push(i),this}unsubscribeDetachedChild(i){const a=this.detachedChildren.indexOf(i);return a!==-1&&this.detachedChildren.splice(a,1),this}addInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(i),a==null||a.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input-declaration"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",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,K.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,K.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,K.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}addCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-call"))){return this.calls.includes(i)||(this.calls.push(i),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("add-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call"))){const o=this.calls.indexOf(i);return o!==-1&&(this.calls.splice(o,1),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("remove-call",this.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.inputs=this.initialData.inputs.map(a=>{const o=ie(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.calls=this.initialData.calls.map(a=>{const o=ie(a,this.project);return o.addEntryCaller(this,null),[f.BreakStatement,f.ContinueStatement].includes(o.type)?(o.setParent(this.parent,null),o.initChildren(i)):o.type!==f.InternalCall&&(o.setParent(this,null),o.initChildren(i)),o}),this.initialData.implements&&(this.implements=ie(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=ie(this.initialData.extends,this.project)),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.private=i.private!==void 0?i.private:this.private,this.index=i.index||(i.index!==0?p.index:0),this.collapsed=i.collapsed!==void 0?i.collapsed:p.collapsed,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,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):o&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Nt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Nt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Nt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Nt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Nt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Nt.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.removeMethod(this),i==null||i.add(this.parent,K.Affected),e.push(this.parent)):this.parent.type===f.Loop?(this.parent.detachBody(),i==null||i.add(this.parent,K.Affected),e.push(this.parent)):this.parent.type===f.Project&&(this.project.removeFunctionDeclaration(this),i==null||i.add(this.parent,K.Affected),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(E=>{const{updated:b,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...b),p.push(...A),e.push(...$)}),this.inputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),ms(this).forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),!i){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.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(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRestored(this,v.field,i);o.push(...E),p.push(...b),a.push(...A)}),this.inputs.forEach(v=>{const{updated:E}=v.restore({},i);o.push(...E)}),ms(this).forEach(v=>{const{updated:E}=v.restore({},i);o.push(...E)}),this.parent.type===f.DefinitionEntity&&(this.parent.addMethod(this),i==null||i.add(this.parent,K.Affected),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){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(o=>o.toFlat(i)),...this.calls.flatMap(o=>o.toFlat(i)),...this.returnStatements.flatMap(o=>o.toFlat(i)),...this.implements?this.implements.toFlat(i):[]])}toFlatIds(i=new Set){if(i.has(this.id))return[];i.add(this.id);const a=ms(this);return[this.id,...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.calls.flatMap(p=>p.toFlatIds(i)),...this.returnStatements.flatMap(p=>p.toFlatIds(i)),...this.implements?this.implements.toFlatIds(i):[],...a.flatMap(p=>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,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),implements:((a=this.implements)==null?void 0:a.toJSON(i))||null,extends:((o=this.extends)==null?void 0:o.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Fe){var o,p,e,y,v;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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(E=>E.toJSONClone({...i,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...i,newId:null})),implements:(()=>{var E;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(E=this.implements)==null?void 0:E.toJSONClone({...i,newId:null})})(),extends:(()=>{var E;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(E=this.extends)==null?void 0:E.toJSONClone({...i,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Fe){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=Fe){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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(y=>y.toReference(i)),calls:this.calls.map(y=>y.toReference(i)),implements:((p=this.implements)==null?void 0:p.toReference(i))||null,extends:((e=this.extends)==null?void 0:e.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.calls.flatMap(o=>o.toFlatJSON(i)),...this.returnStatements.flatMap(o=>o.toFlatJSON(i)),...this.implements?this.implements.toFlatJSON(i):[]])}toGenerationTarget(){var a,o;const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((a=this.implements)==null?void 0:a.id)||void 0,extends:((o=this.extends)==null?void 0:o.id)||void 0,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.calls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.returnStatements.flatMap(o=>o.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.calls.forEach(i=>i.clearErrors()),this.returnStatements.forEach(i=>i.clearErrors()),this}validate(){const i=NU(this);return this.errors=[...i],{success:!0}}getErrors(){const i=ms(this);return[...this.errors,...this.inputs.flatMap(o=>o.getErrors()),...i.flatMap(o=>o.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,e=!1){var V;let y=xr(a,this);const v=this.toJSON(),E=o||N.UUID.uuid();v.inputs=[],v.calls=[],v.id=E,v.version=N.UUID.uuid(),v.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),v.author=(i==null?void 0:i.author)||"1",v.previousVersion=null,v.deleted=!1;const b=lr(v,y);a?b.setParent(a,null):b.setParent(this.parent,null),p&&b.subscribe(),b.initChildren(i),i==null||i.add(b,K.Added);const A=(V=this.inputs)==null?void 0:V.map(B=>B.clone(i,b,N.UUID.uuid(),p));return b.inputs=A,e?(ms(this).map(B=>B.clone(i,b,N.UUID.uuid(),p)),i==null||i.attemptAutoclose("clone-entity",this.id),b):(i==null||i.attemptAutoclose("clone-entity",this.id),b)}getVariableInstances(){return vr(this).filter(o=>o.type===f.VariableInstance)}getArgument(i){return this.inputs.find(a=>a.id===i)||null}createCall(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"create-call")),a=this.project,o={}){const p={id:o.id||N.UUID.uuid(),version:o.version||N.UUID.uuid(),createdAt:o.createdAt||(i==null?void 0:i.timestamp)||L().toISOString(),author:o.author||N.sessionAuthor||"1",previousVersion:o.previousVersion||null,deleted:o.deleted||!1,type:f.FunctionCall,parent:a.toReference(),successCalls:o.successCalls||[],errorCalls:o.errorCalls||[],inputs:o.inputs||[],outputs:o.outputs||[],error:o.error||null,process:o.process||null,calledBySuccess:o.calledBySuccess||[],calledByError:o.calledByError||[],calledByEntry:o.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},e=ie(p,this.project);return e.hydrateAncestors(),i==null||i.add(e,K.Added),e.addSelfToProject(i),e.setParent(a,i),e.initChildren(i),e.afterAllChildrenInitialized(i),i==null||i.add(e,K.Added),i==null||i.attemptAutoclose("create-call",this.id),e}createInternalCall(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"create-internal")),a,o={}){const p={id:o.id||N.UUID.uuid(),version:o.version||N.UUID.uuid(),createdAt:o.createdAt||(i==null?void 0:i.timestamp)||L().toISOString(),author:o.author||N.sessionAuthor||"1",previousVersion:o.previousVersion||null,deleted:o.deleted||!1,type:f.InternalCall,parent:a.toReference(),successCalls:o.successCalls||[],errorCalls:o.errorCalls||[],inputs:o.inputs||[],outputs:o.outputs||[],error:o.error||null,process:o.process||null,calledBySuccess:o.calledBySuccess||[],calledByError:o.calledByError||[],calledByEntry:o.calledByEntry||[],declaration:this.toShallowJSON(),index:a.internalCalls.length},e=ie(p,this.project);return e.hydrateAncestors(),i==null||i.add(e,K.Added),e.addSelfToProject(i),e.setParent(a,i),e.initChildren(i),e.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("create-internal",this.id),e}addReturnStatement(i){return this.returnStatements.includes(i)||this.returnStatements.push(i),this}removeReturnStatement(i){const a=this.returnStatements.indexOf(i);return a!==-1&&this.returnStatements.splice(a,1),this}getUniqueReturnDeclarations(){const i=[],a=[...this.returnStatements];this.parent.type===f.Loop&&a.push(...this.parent.breakStatements,...this.parent.continueStatements);const o=a.flatMap(p=>p.outputs);if(this.implements&&this.parent.type!==f.Loop){const p=this.implements.outputs;return o.forEach(e=>{const y=p.find(E=>E===e.implements),v=i.find(E=>E.implements===e.implements);y&&!v&&i.push(e)}),R(i)}else return o.forEach(p=>{i.find(y=>y===p||W(y,this.project)===W(p,this.project)&&Ws(y.dataType,p.dataType))||i.push(p)}),R(i)}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.implements?(this.inputs.forEach(v=>{var b;if(!(((b=this.implements)==null?void 0:b.inputs)||[]).find(A=>{var $;return A.id===(($=v.implements)==null?void 0:$.id)})){const A=v.remove({ignoreUpstream:!1},i);p.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.implements===v.implements&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!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}):(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"))){var A;const a=[],o=[],p=[],e=[],y=(((A=this.implements)==null?void 0:A.inputs)||[]).filter($=>$.parentRelationType===le.FixedArguments&&!this.inputs.find(V=>{var B;return((B=V.implements)==null?void 0:B.id)===$.id}));this.inputs.sort(($,V)=>$.index-V.index),y.forEach($=>{this.inputs.forEach(F=>{F.index>=$.index&&F.metaSync({index:F.index+1},i)});const V=Kn.new(i);V.implements=$.toJSON(),V.index=$.index,V.parent=this.toReference(),V.name=$.name;const B=ie(V,this.project);B.hydrateAncestors(),i==null||i.add(B,K.Added),B.setParent(this,i),B.initChildren(i),B.addSelfToProject(i)}),this.inputs.sort(($,V)=>$.index-V.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}};g(Nt,"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}),g(Nt,"type",f.FunctionDeclaration),g(Nt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop]),g(Nt,"PARENT_TYPES",[...Nt.USER_MANAGED_PARENT_TYPES,f.BuiltInBaseEntity,f.PrimitiveEntity]),g(Nt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private"]),g(Nt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Nt,"BASE_PROPERTIES",[...Nt.MUTABLE_BASE_PROPERTIES,...Nt.INMUTABLE_BASE_PROPERTIES]),g(Nt,"MUTABLE_META_PROPERTIES",[...Nt.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),g(Nt,"INMUTABLE_META_PROPERTIES",[...Nt.INMUTABLE_BASE_PROPERTIES]),g(Nt,"META_PROPERTIES",[...Nt.MUTABLE_META_PROPERTIES,...Nt.INMUTABLE_META_PROPERTIES]),g(Nt,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(Nt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(Nt,"UPSTREAM_PROPERTIES",[...Nt.MUTABLE_UPSTREAM_PROPERTIES,...Nt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Nt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),g(Nt,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),g(Nt,"DOWNSTREAM_PROPERTIES",[...Nt.MUTABLE_DOWNSTREAM_PROPERTIES,...Nt.INMUATABLE_DOWNSTREAM_PROPERTIES]),g(Nt,"PROPERTIES",[...Nt.META_PROPERTIES,...Nt.UPSTREAM_PROPERTIES,...Nt.DOWNSTREAM_PROPERTIES]);let Ha=Nt;function MU(d){const u=[];if(d.entity&&d.andChildrenGroup||d.entity&&d.orChildrenGroup||d.andChildrenGroup&&d.orChildrenGroup){const i=lt({id:d.id+"--"+Q.InvalidPropertiesCombination,message:`Data type with id "${d.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,severity:q.Error,code:Q.InvalidPropertiesCombination,entity:d});u.push(i.error)}return Er(d.errors,u)}const Uhe=Object.freeze(Object.defineProperty({__proto__:null,validate:MU},Symbol.toStringTag,{value:"Module"}));function xhe(d,u){const i=[],a=[f.DefinitionEntity,f.ActionDescriptor,f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.ValueDescriptor,f.DataType],o=`'${st(a,"', '","' or '")}'`;if(d.parent)if(d.id===d.parent)i.push(new re({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));else{const p=u.get(d.parent);p?a.includes(p.type)||i.push(new re({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type ${o}.`})):i.push(new re({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}else i.push(new re({id:`${d.id}--${ee.InvalidObjectStructure}`,code:ee.InvalidObjectStructure,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${o}.`}));if(d.entity){if(d.id===d.entity)return i.push(new re({id:`${d.id}--${d.entity}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`})),i;const p=u.get(d.entity);p?[f.DefinitionEntity,f.PrimitiveEntity,f.ActionDescriptor,f.BuiltInBaseEntity].includes(p.type)||i.push(new re({id:`${d.id}--${d.entity}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`})):i.push(new re({id:`${d.id}--${d.entity}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return i}var yI=(d=>(d.Entity="entity",d))(yI||{});const Vt=class Vt extends Cr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"isList",null);g(this,"asType",null);g(this,"type",f.DataType);g(this,"options",null);g(this,"parentRelationType",null);g(this,"like");g(this,"implementationChooseOne",!1);g(this,"inferred",!1);g(this,"staticEntities",null);g(this,"interactiveEntities",null);g(this,"actionEntities",null);g(this,"index",null);g(this,"entity",null);g(this,"andChildrenGroup",null);g(this,"orChildrenGroup",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);this.initialData=i,this.project=a,this.id=i.id,this.isList=i.isList,this.asType=i.asType,this.options=i.options,this.index=i.index??null,this.parentRelationType=i.parentRelationType,this.inferred=i.inferred||!1,this.like=i.like||!1,this.implementationChooseOne=i.implementationChooseOne||!1,this.staticEntities=i.staticEntities,this.interactiveEntities=i.interactiveEntities,this.actionEntities=i.actionEntities}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.DataType,entity:null,isList:!1,like:!1,index:null,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(i,a){const o=H(i.parent),p=a.get(o);let e=null;i.entity&&(e=a.get(i.entity));let y=null;p&&p.type===f.DataType&&(i.parentRelationType===mi.OrDataTypeGroup?y=(p.orChildrenGroup||[]).length:i.parentRelationType===mi.AndDataTypeGroup&&(y=(p.andChildrenGroup||[]).length));const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:i.parentRelationType||null,options:i.options||null,isList:i.isList,like:i.like||!1,index:y,inferred:!1,implementationChooseOne:i.implementationChooseOne||!1,staticEntities:i.staticEntities??null,interactiveEntities:i.interactiveEntities??null,actionEntities:i.actionEntities??null,entity:e,asType:i.asType,parent:p},E=ie(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){var E;let o=JSON.parse(JSON.stringify(i));const p=[],e=xhe(o,a);if(p.push(...e,...Vr(o)),o.entity){const b=a.get(o.entity);if(b.type===f.DefinitionEntity){const $=Vi(b).filter(V=>!V.interactive);if($.length){const V=$.length>1?`entities with ids '${st($.map(B=>B.id),"', '","' and '")}'`:`entity with id '${$[0].id}'`;p.push(new re({id:`${i.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot reference 'definition-entity' with id '${o.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${V}.
34
+ Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`}))),{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==="function-declaration-implements"&&this.setImplements(null,o),a==="function-declaration-extends"){const{updated:E,added:b,removed:A,affected:$}=this.remove({ignoreUpstream:!1},o);p.push(...E),e.push(...b),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==="function-declaration-implements"&&(this.setImplements(i,o),p.push(i)),a==="function-declaration-extends"){const{updated:E,added:b,removed:A,affected:$}=this.restore({},o);p.push(...E),e.push(...b),y.push(...A),v.push(...$)}return{updated:R(p),added:R(e),removed:R(y),affected:R(v),self:this}}unsubscribeFromDependencies(){var i,a;return(i=this.implements)==null||i.unsubscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.unsubscribeDependents([{entity:this,field:"function-declaration-extends"}]),this}subscribeToDependencies(){var i,a;return(i=this.implements)==null||i.subscribeDependents([{entity:this,field:"function-declaration-implements"}]),(a=this.extends)==null||a.subscribeDependents([{entity:this,field:"function-declaration-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 Nt(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.calls=[...this.calls],i.implements=this.implements,i.extends=this.extends,i.detachedChildren=[...this.detachedChildren],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[b,A]of this.knownVersions||new Map){if(E.set(b,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 Nt(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.calls=y.calls,this.implements=y.implements,this.detachedChildren=y.detachedChildren,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=H(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=H(i.implements),p=this.project.get(o);if(p)this.setImplements(p,a);else if(o)throw a==null||a.attemptAutoclose("update-with-shallow-transfer",this.id),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=H(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=H(this.initialData.parent),y=this.project.get(e);if(y)this.setParent(y,null),i.push(y);else throw new Error(`${Ii(this.type)} with id '${this.id}' has a 'parent' reference "${e}" which is missing in the project`)}else throw new Error(`${Ii(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const e=H(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=H(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}=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.addFunctionDeclaration(this):this.parent.type===f.DefinitionEntity?(this.parent.addMethod(this),e.push(this.parent)):this.parent.type===f.Loop&&(this.parent.setBody(this),e.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}}replaceDetachedChild(i,a){const o=this.detachedChildren.indexOf(i);return o!==-1&&(this.detachedChildren[o]=a),this}subscribeDetachedChild(i){return this.detachedChildren.includes(i)||this.detachedChildren.push(i),this}unsubscribeDetachedChild(i){const a=this.detachedChildren.indexOf(i);return a!==-1&&this.detachedChildren.splice(a,1),this}addInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(i)?(a==null||a.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(i),a==null||a.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-input-declaration"))){const o=this.inputs.findIndex(p=>p.id===i.id);return o>-1&&(this.inputs.splice(o,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",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,K.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,K.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,K.Updated))),a==null||a.attemptAutoclose("set-extends",this.id),this}addCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"add-call"))){return this.calls.includes(i)||(this.calls.push(i),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("add-call",this.id),this}removeCall(i,a=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"remove-call"))){const o=this.calls.indexOf(i);return o!==-1&&(this.calls.splice(o,1),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose("remove-call",this.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.inputs=this.initialData.inputs.map(a=>{const o=ie(a,this.project);return o.setParent(this,null),o.initChildren(i),o}),this.calls=this.initialData.calls.map(a=>{const o=ie(a,this.project);return o.addEntryCaller(this,null),[f.BreakStatement,f.ContinueStatement].includes(o.type)?(o.setParent(this.parent,null),o.initChildren(i)):o.type!==f.InternalCall&&(o.setParent(this,null),o.initChildren(i)),o}),this.initialData.implements&&(this.implements=ie(this.initialData.implements,this.project)),this.initialData.extends&&(this.extends=ie(this.initialData.extends,this.project)),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.private=i.private!==void 0?i.private:this.private,this.index=i.index||(i.index!==0?p.index:0),this.collapsed=i.collapsed!==void 0?i.collapsed:p.collapsed,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,K.Removed):i.deleted===!1&&p.deleted?a==null||a.add(this,K.Added):o&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=ve,...a){return await Nt.repository.APILoad(this.id,...a),this}async APICreate(i=ve,...a){return await Nt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=ve,...a){return await Nt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=ve,...a){return await Nt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=ve,...a){return await Nt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=ve,a,...o){return await Nt.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.removeMethod(this),i==null||i.add(this.parent,K.Affected),e.push(this.parent)):this.parent.type===f.Loop?(this.parent.detachBody(),i==null||i.add(this.parent,K.Affected),e.push(this.parent)):this.parent.type===f.Project&&(this.project.removeFunctionDeclaration(this),i==null||i.add(this.parent,K.Affected),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(E=>{const{updated:b,removed:A,added:$}=E.entity.onDetachedDependencyRemoved(this,E.field,a);o.push(...b),p.push(...A),e.push(...$)}),this.inputs.forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),ms(this).forEach(E=>{const{updated:b,removed:A}=E.remove({ignoreUpstream:!0},a);o.push(...b),p.push(...A)}),!i){const E=this.removeFromParent(a);e.push(...E.added),o.push(...E.updated),p.push(...E.removed),y.push(...E.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(v=>{const{updated:E,removed:b,added:A}=v.entity.onDetachedDependencyRestored(this,v.field,i);o.push(...E),p.push(...b),a.push(...A)}),this.inputs.forEach(v=>{const{updated:E}=v.restore({},i);o.push(...E)}),ms(this).forEach(v=>{const{updated:E}=v.restore({},i);o.push(...E)}),this.parent.type===f.DefinitionEntity&&(this.parent.addMethod(this),i==null||i.add(this.parent,K.Affected),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){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(o=>o.toFlat(i)),...this.calls.flatMap(o=>o.toFlat(i)),...this.returnStatements.flatMap(o=>o.toFlat(i)),...this.implements?this.implements.toFlat(i):[]])}toFlatIds(i=new Set){if(i.has(this.id))return[];i.add(this.id);const a=ms(this);return[this.id,...this.inputs.flatMap(p=>p.toFlatIds(i)),...this.calls.flatMap(p=>p.toFlatIds(i)),...this.returnStatements.flatMap(p=>p.toFlatIds(i)),...this.implements?this.implements.toFlatIds(i):[],...a.flatMap(p=>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,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(p=>p.toJSON(i)),inputs:this.inputs.map(p=>p.toJSON(i)),implements:((a=this.implements)==null?void 0:a.toJSON(i))||null,extends:((o=this.extends)==null?void 0:o.toJSON(i))||null,parent:this.parent.toReference()})}toJSONClone(i=Fe){var o,p,e,y,v;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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(E=>E.toJSONClone({...i,newId:null})),inputs:this.inputs.map(E=>E.toJSONClone({...i,newId:null})),implements:(()=>{var E;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(E=this.implements)==null?void 0:E.toJSONClone({...i,newId:null})})(),extends:(()=>{var E;return this.extends&&this.project.getBuiltIn(this.extends.id)?this.extends.toJSON():(E=this.extends)==null?void 0:E.toJSONClone({...i,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=Fe){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=Fe){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,name:this.name,codeName:this.codeName,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(y=>y.toReference(i)),calls:this.calls.map(y=>y.toReference(i)),implements:((p=this.implements)==null?void 0:p.toReference(i))||null,extends:((e=this.extends)==null?void 0:e.toReference(i))||null,parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(o=>o.toFlatJSON(i)),...this.calls.flatMap(o=>o.toFlatJSON(i)),...this.returnStatements.flatMap(o=>o.toFlatJSON(i)),...this.implements?this.implements.toFlatJSON(i):[]])}toGenerationTarget(){var a,o;const i=this.parent.type===f.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,private:this.private,implements:((a=this.implements)==null?void 0:a.id)||void 0,extends:((o=this.extends)==null?void 0:o.id)||void 0,parent:i}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(i)),...this.calls.flatMap(o=>o.toFlatGenerationTarget(i)),...this.returnStatements.flatMap(o=>o.toFlatGenerationTarget(i))])}clearErrors(){return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.calls.forEach(i=>i.clearErrors()),this.returnStatements.forEach(i=>i.clearErrors()),this}validate(){const i=NU(this);return this.errors=[...i],{success:!0}}getErrors(){const i=ms(this);return[...this.errors,...this.inputs.flatMap(o=>o.getErrors()),...i.flatMap(o=>o.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,e=!1){var V;let y=xr(a,this);const v=this.toJSON(),E=o||N.UUID.uuid();v.inputs=[],v.calls=[],v.id=E,v.version=N.UUID.uuid(),v.createdAt=(i==null?void 0:i.timestamp)||L().toISOString(),v.author=(i==null?void 0:i.author)||"1",v.previousVersion=null,v.deleted=!1;const b=lr(v,y);a?b.setParent(a,null):b.setParent(this.parent,null),p&&b.subscribe(),b.initChildren(i),i==null||i.add(b,K.Added);const A=(V=this.inputs)==null?void 0:V.map(B=>B.clone(i,b,N.UUID.uuid(),p));return b.inputs=A,e?(ms(this).map(B=>B.clone(i,b,N.UUID.uuid(),p)),i==null||i.attemptAutoclose("clone-entity",this.id),b):(i==null||i.attemptAutoclose("clone-entity",this.id),b)}getVariableInstances(){return vr(this).filter(o=>o.type===f.VariableInstance)}getArgument(i){return this.inputs.find(a=>a.id===i)||null}createCall(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"create-call")),a=this.project,o={}){const p={id:o.id||N.UUID.uuid(),version:o.version||N.UUID.uuid(),createdAt:o.createdAt||(i==null?void 0:i.timestamp)||L().toISOString(),author:o.author||N.sessionAuthor||"1",previousVersion:o.previousVersion||null,deleted:o.deleted||!1,type:f.FunctionCall,parent:a.toReference(),successCalls:o.successCalls||[],errorCalls:o.errorCalls||[],inputs:o.inputs||[],outputs:o.outputs||[],error:o.error||null,process:o.process||null,calledBySuccess:o.calledBySuccess||[],calledByError:o.calledByError||[],calledByEntry:o.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},e=ie(p,this.project);return e.hydrateAncestors(),i==null||i.add(e,K.Added),e.addSelfToProject(i),e.setParent(a,i),e.initChildren(i),e.afterAllChildrenInitialized(i),i==null||i.add(e,K.Added),i==null||i.attemptAutoclose("create-call",this.id),e}createInternalCall(i=this.project.addChangeSet(new G(this.project,N.sessionAuthor,L().toISOString(),this,!0,"create-internal")),a,o={}){const p={id:o.id||N.UUID.uuid(),version:o.version||N.UUID.uuid(),createdAt:o.createdAt||(i==null?void 0:i.timestamp)||L().toISOString(),author:o.author||N.sessionAuthor||"1",previousVersion:o.previousVersion||null,deleted:o.deleted||!1,type:f.InternalCall,parent:a.toReference(),successCalls:o.successCalls||[],errorCalls:o.errorCalls||[],inputs:o.inputs||[],outputs:o.outputs||[],error:o.error||null,process:o.process||null,calledBySuccess:o.calledBySuccess||[],calledByError:o.calledByError||[],calledByEntry:o.calledByEntry||[],declaration:this.toShallowJSON(),index:a.internalCalls.length},e=ie(p,this.project);return e.hydrateAncestors(),i==null||i.add(e,K.Added),e.addSelfToProject(i),e.setParent(a,i),e.initChildren(i),e.afterAllChildrenInitialized(i),i==null||i.attemptAutoclose("create-internal",this.id),e}addReturnStatement(i){return this.returnStatements.includes(i)||this.returnStatements.push(i),this}removeReturnStatement(i){const a=this.returnStatements.indexOf(i);return a!==-1&&this.returnStatements.splice(a,1),this}getUniqueReturnDeclarations(){const i=[],a=[...this.returnStatements];this.parent.type===f.Loop&&a.push(...this.parent.breakStatements,...this.parent.continueStatements);const o=a.flatMap(p=>p.outputs);if(this.implements&&this.parent.type!==f.Loop){const p=this.implements.outputs;return o.forEach(e=>{const y=p.find(E=>E===e.implements),v=i.find(E=>E.implements===e.implements);y&&!v&&i.push(e)}),R(i)}else return o.forEach(p=>{i.find(y=>y===p||W(y,this.project)===W(p,this.project)&&Ws(y.dataType,p.dataType))||i.push(p)}),R(i)}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.implements?(this.inputs.forEach(v=>{var b;if(!(((b=this.implements)==null?void 0:b.inputs)||[]).find(A=>{var $;return A.id===(($=v.implements)==null?void 0:$.id)})){const A=v.remove({ignoreUpstream:!1},i);p.push(...A.removed),a.push(...A.updated)}}),this.inputs.filter((v,E)=>{const b=this.inputs.findIndex($=>$.implements===v.implements&&$!==v);if(b===-1)return!1;const A=this.inputs[b];return L(A==null?void 0:A.createdAt).isSame(L(v.createdAt))?E>b:!!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}):(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"))){var A;const a=[],o=[],p=[],e=[],y=(((A=this.implements)==null?void 0:A.inputs)||[]).filter($=>$.parentRelationType===le.FixedArguments&&!this.inputs.find(V=>{var B;return((B=V.implements)==null?void 0:B.id)===$.id}));this.inputs.sort(($,V)=>$.index-V.index),y.forEach($=>{this.inputs.forEach(F=>{F.index>=$.index&&F.metaSync({index:F.index+1},i)});const V=Kn.new(i);V.implements=$.toJSON(),V.index=$.index,V.parent=this.toReference(),V.name=$.name;const B=ie(V,this.project);B.hydrateAncestors(),i==null||i.add(B,K.Added),B.setParent(this,i),B.initChildren(i),B.addSelfToProject(i)}),this.inputs.forEach($=>{const{updated:V,added:B,removed:F,affected:S}=$.afterAllChildrenInitialized(i);a.push(...V),o.push(...B),p.push(...F),e.push(...S)}),this.inputs.sort(($,V)=>$.index-V.index);const{updated:v,added:E,removed:b}=this.removeUnrecognizedInputs(i);return a.push(...v),o.push(...E),p.push(...b),i==null||i.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:R(a),added:R(o),removed:R(p),affected:R(e),self:this}}};g(Nt,"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}),g(Nt,"type",f.FunctionDeclaration),g(Nt,"USER_MANAGED_PARENT_TYPES",[f.Project,f.InstalledProject,f.DefinitionEntity,f.Loop]),g(Nt,"PARENT_TYPES",[...Nt.USER_MANAGED_PARENT_TYPES,f.BuiltInBaseEntity,f.PrimitiveEntity]),g(Nt,"MUTABLE_BASE_PROPERTIES",["name","codeName","description","private"]),g(Nt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),g(Nt,"BASE_PROPERTIES",[...Nt.MUTABLE_BASE_PROPERTIES,...Nt.INMUTABLE_BASE_PROPERTIES]),g(Nt,"MUTABLE_META_PROPERTIES",[...Nt.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),g(Nt,"INMUTABLE_META_PROPERTIES",[...Nt.INMUTABLE_BASE_PROPERTIES]),g(Nt,"META_PROPERTIES",[...Nt.MUTABLE_META_PROPERTIES,...Nt.INMUTABLE_META_PROPERTIES]),g(Nt,"MUTABLE_UPSTREAM_PROPERTIES",[]),g(Nt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements","extends"]),g(Nt,"UPSTREAM_PROPERTIES",[...Nt.MUTABLE_UPSTREAM_PROPERTIES,...Nt.INMUTABLE_UPSTREAM_PROPERTIES]),g(Nt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls"]),g(Nt,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),g(Nt,"DOWNSTREAM_PROPERTIES",[...Nt.MUTABLE_DOWNSTREAM_PROPERTIES,...Nt.INMUATABLE_DOWNSTREAM_PROPERTIES]),g(Nt,"PROPERTIES",[...Nt.META_PROPERTIES,...Nt.UPSTREAM_PROPERTIES,...Nt.DOWNSTREAM_PROPERTIES]);let Ha=Nt;function MU(d){const u=[];if(d.entity&&d.andChildrenGroup||d.entity&&d.orChildrenGroup||d.andChildrenGroup&&d.orChildrenGroup){const i=lt({id:d.id+"--"+Q.InvalidPropertiesCombination,message:`Data type with id "${d.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,severity:q.Error,code:Q.InvalidPropertiesCombination,entity:d});u.push(i.error)}return Er(d.errors,u)}const Uhe=Object.freeze(Object.defineProperty({__proto__:null,validate:MU},Symbol.toStringTag,{value:"Module"}));function xhe(d,u){const i=[],a=[f.DefinitionEntity,f.ActionDescriptor,f.Property,f.ArgumentDeclaration,f.ReturnDeclaration,f.VariableDeclaration,f.ValueDescriptor,f.DataType],o=`'${st(a,"', '","' or '")}'`;if(d.parent)if(d.id===d.parent)i.push(new re({id:`${d.id}--${d.parent}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`}));else{const p=u.get(d.parent);p?a.includes(p.type)||i.push(new re({id:`${d.id}--${d.parent}--${k.InvalidParentReference}`,code:k.InvalidParentReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a parent reference that isn't pointing to an entity of type ${o}.`})):i.push(new re({id:`${d.id}--${d.parent}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}else i.push(new re({id:`${d.id}--${ee.InvalidObjectStructure}`,code:ee.InvalidObjectStructure,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${o}.`}));if(d.entity){if(d.id===d.entity)return i.push(new re({id:`${d.id}--${d.entity}--${k.SelfReference}`,code:k.SelfReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`})),i;const p=u.get(d.entity);p?[f.DefinitionEntity,f.PrimitiveEntity,f.ActionDescriptor,f.BuiltInBaseEntity].includes(p.type)||i.push(new re({id:`${d.id}--${d.entity}--${k.InvalidImplementsReference}`,code:k.InvalidImplementsReference,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`})):i.push(new re({id:`${d.id}--${d.entity}--${k.ReferencedEntityNotFound}`,code:k.ReferencedEntityNotFound,severity:q.Error,message:`Entity of type "${d.type}" with id "${d.id}", is referencing an entity with id "${d.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`}))}return i}var yI=(d=>(d.Entity="entity",d))(yI||{});const Vt=class Vt extends Cr{constructor(i,a){super(i);g(this,"initialData");g(this,"id");g(this,"isList",null);g(this,"asType",null);g(this,"type",f.DataType);g(this,"options",null);g(this,"parentRelationType",null);g(this,"like");g(this,"implementationChooseOne",!1);g(this,"inferred",!1);g(this,"staticEntities",null);g(this,"interactiveEntities",null);g(this,"actionEntities",null);g(this,"index",null);g(this,"entity",null);g(this,"andChildrenGroup",null);g(this,"orChildrenGroup",null);g(this,"project");g(this,"errors",[]);g(this,"parent");g(this,"detachedDependents",{});g(this,"knownVersions",null);g(this,"activeVersion",!1);g(this,"initialized",!1);g(this,"startedInitialization",!1);this.initialData=i,this.project=a,this.id=i.id,this.isList=i.isList,this.asType=i.asType,this.options=i.options,this.index=i.index??null,this.parentRelationType=i.parentRelationType,this.inferred=i.inferred||!1,this.like=i.like||!1,this.implementationChooseOne=i.implementationChooseOne||!1,this.staticEntities=i.staticEntities,this.interactiveEntities=i.interactiveEntities,this.actionEntities=i.actionEntities}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.DataType,entity:null,isList:!1,like:!1,index:null,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,staticEntities:null,interactiveEntities:null,actionEntities:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(i,a){const o=H(i.parent),p=a.get(o);let e=null;i.entity&&(e=a.get(i.entity));let y=null;p&&p.type===f.DataType&&(i.parentRelationType===mi.OrDataTypeGroup?y=(p.orChildrenGroup||[]).length:i.parentRelationType===mi.AndDataTypeGroup&&(y=(p.andChildrenGroup||[]).length));const v={id:i.id,version:N.UUID.uuid(),createdAt:L().toISOString(),author:N.sessionAuthor,previousVersion:null,deleted:!1,type:f.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:i.parentRelationType||null,options:i.options||null,isList:i.isList,like:i.like||!1,index:y,inferred:!1,implementationChooseOne:i.implementationChooseOne||!1,staticEntities:i.staticEntities??null,interactiveEntities:i.interactiveEntities??null,actionEntities:i.actionEntities??null,entity:e,asType:i.asType,parent:p},E=ie(v,a);return E.setParent(p,null),E}static validateGenerationTarget(i,a){var E;let o=JSON.parse(JSON.stringify(i));const p=[],e=xhe(o,a);if(p.push(...e,...Vr(o)),o.entity){const b=a.get(o.entity);if(b.type===f.DefinitionEntity){const $=Vi(b).filter(V=>!V.interactive);if($.length){const V=$.length>1?`entities with ids '${st($.map(B=>B.id),"', '","' and '")}'`:`entity with id '${$[0].id}'`;p.push(new re({id:`${i.id}--${k.NonInteractiveEntityReferenced}`,code:k.NonInteractiveEntityReferenced,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot reference 'definition-entity' with id '${o.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${V}.
35
35
  ${co}`}))}}}const y=o.parent&&a.get(o.parent)||a.getBuiltIn(o.parent),v=y?yo(y):null;if(v)p.push(new re({id:`${i.id}--${k.BuiltInEntityParent}`,code:k.BuiltInEntityParent,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', belongs to a built-in system entity "${W(v,a)}" with id '${v.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`}));else if(y){const b=y.type,A=[f.Property,f.VariableDeclaration,f.ArgumentDeclaration,f.ReturnDeclaration,f.ValueDescriptor];if(A.includes(b)&&(o.parentRelationType&&p.push(new re({id:`${i.id}--${k.InvalidParentRelationType}`,code:k.InvalidParentRelationType,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot have a 'parentRelationType' property set of type '${b}'.
36
36
  The entitities of type '${st(A,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`})),y.dataType)){const $=(E=y.dataType)==null?void 0:E.id;p.push(new re({id:`${i.id}--${k.NewEntityWouldOverriteExisting}`,code:k.NewEntityWouldOverriteExisting,severity:q.Error,message:`The entity with id '${i.id}' and type '${i.type}', cannot be added as a child to the entity with id '${o.parent}' and type '${b}', because it already has a 'data-type' child with id '${$}'.
37
37
  The entitities of type '${st(A,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6453",
3
+ "version": "0.0.6454",
4
4
  "author": "Sergio Herrero",
5
5
  "license": "UNLICENSED",
6
6
  "description": "An installable module which contains the type definitions and ephemeral state management for a projects' logic tree data structure",