@elyx-code/project-logic-tree 0.0.6551 → 0.0.6552

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 CHANGED
@@ -5787,6 +5787,7 @@ export declare enum ExecutionState {
5787
5787
 
5788
5788
  export declare enum ExecutionTerminationType {
5789
5789
  Success = "success",
5790
+ ConditionNotMet = "condition-not-met",
5790
5791
  CaughtError = "caught-error",
5791
5792
  UnhandledError = "unhandled-error",
5792
5793
  Break = "break",
package/dist/index.js CHANGED
@@ -56636,7 +56636,7 @@ const _Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty(
56636
56636
  __proto__: null,
56637
56637
  validate: DB
56638
56638
  }, Symbol.toStringTag, { value: "Module" }));
56639
- var z = /* @__PURE__ */ ((d) => (d.Success = "success", d.CaughtError = "caught-error", d.UnhandledError = "unhandled-error", d.Break = "break", d.Continue = "continue", d.Return = "return", d))(z || {});
56639
+ var z = /* @__PURE__ */ ((d) => (d.Success = "success", d.ConditionNotMet = "condition-not-met", d.CaughtError = "caught-error", d.UnhandledError = "unhandled-error", d.Break = "break", d.Continue = "continue", d.Return = "return", d))(z || {});
56640
56640
  const Zt = class Zt extends er {
56641
56641
  constructor(i, a) {
56642
56642
  super(i);
@@ -50,7 +50,7 @@ Specifically for return statements the parent needs to always be the 'function-d
50
50
  ${N0(a)}`}));else if(!a.get(i.implements))f.push(new de({id:`${i.id}--${W.ReferencedEntityNotFound}`,code:W.ReferencedEntityNotFound,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that isn't found in the project. The 'implements' property must point to one of the built-in action descriptors reserved for 'global-event' entities.
51
51
  ${N0(a)}`}));else if(!a.globalEventActionDescriptors.find(T=>T.id===i.implements))f.push(new de({id:`${i.id}--${W.InvalidImplementsReference}`,code:W.InvalidImplementsReference,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that isn't pointing to an action descriptor reserved for 'global-event' entities.
52
52
  ${N0(a)}`}));else{const T=a.events.find(A=>A.implements.id===i.implements);T&&f.push(new de({id:`${i.id}--${W.InvalidImplementsReference}`,code:W.InvalidImplementsReference,severity:Y.Error,message:`Entity of type '${i.type}' with id '${i.id}' has an 'implements' property that points to an action descriptor that is already implemented by another global event with id '${T.id}' in the project. Each global event must implement a unique action descriptor.
53
- You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`}))}return{errors:f,modifiedData:l}}get returnStatements(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===iA.Parent&&a.entity.type===p.ReturnStatement&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new de({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Y.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,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Zt(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.detachedChildren=[...this.detachedChildren],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[P,L]of I.knownVersions)T.set(P,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Zt(T,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:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,null);else throw a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=X(i.implements),f=this.project.get(l);if(f)this.setImplements(f,a);else throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${rr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}else throw new Error(`${rr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(O.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose(O.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],f=[],e=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}replaceDetachedChild(i,a){const l=this.detachedChildren.indexOf(i);return l!==-1&&(this.detachedChildren[l]=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}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,O.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(O.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(O.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.SetImplements,this.id),this)}addCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.AddCall))){return this.checkCanEdit(this)?(this.calls.includes(i)||(this.calls.push(i),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose(O.AddCall,this.id),this):(J.warn(`[addCall] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.AddCall,this.id),this)}removeCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RemoveCall))){if(!this.checkCanEdit(this))return J.warn(`[removeCall] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.RemoveCall,this.id),this;const l=this.calls.indexOf(i);return l!==-1&&(this.calls.splice(l,1),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose(O.RemoveCall,this.id),this}addInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().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,V.sessionAuthor,B().toISOString(),this,!0,"remove-input-declaration"))){const l=this.inputs.findIndex(f=>f.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.calls=this.initialData.calls.map(a=>{const l=se(a,this.project);if(l.addEntryCaller(this,null),l.type===p.ReturnStatement){const f=fr(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this,null),l.initChildren(i));return l}),this.implements=se(this.initialData.implements,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,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.description=l.description!==void 0?l.description:e.description,this.x=l.x||e.x,this.y=l.y||e.y,this.collapsed=l.collapsed!==void 0?l.collapsed:e.collapsed,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await Zt.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await Zt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await Zt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await Zt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await Zt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await Zt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(O.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.type===p.Project&&(this.project.removeGlobalEvent(this),i==null||i.add(this.parent,K.Affected),e.push(this.parent)),i==null||i.attemptAutoclose(O.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RemoveEntity))){var T;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${O.RemoveEntity}-${this.id}`,action:O.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((T=a==null?void 0:a.self)==null?void 0:T.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===O.RemoveEntity}),a==null||a.attemptAutoclose(O.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(O.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(A=>{const{updated:I,removed:P,added:L}=A.entity.onDetachedDependencyRemoved(this,A.field,a);l.push(...I),f.push(...P),e.push(...L)}),this.inputs.forEach(A=>{const{updated:I,removed:P}=A.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...P)}),xn(this).forEach(A=>{const{updated:I,removed:P}=A.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...P)}),!i){const A=this.removeFromParent(a);e.push(...A.added),l.push(...A.updated),f.push(...A.removed),y.push(...A.affected)}return a==null||a.attemptAutoclose(O.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(O.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(O.RestoreEntity,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:T,removed:A,added:I}=v.entity.onDetachedDependencyRestored(this,v.field,i);l.push(...T),f.push(...A),a.push(...I)}),this.inputs.forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),xn(this).forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),i==null||i.attemptAutoclose(O.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.calls.flatMap(l=>l.toFlat(i)),...this.returnStatements.flatMap(l=>l.toFlat(i)),...this.implements?this.implements.toFlat(i):[]])}toFlatIds(i=new Set){if(i.has(this.id))return[];i.add(this.id);const a=xn(this);return[this.id,...this.inputs.flatMap(f=>f.toFlatIds(i)),...this.calls.flatMap(f=>f.toFlatIds(i)),...this.returnStatements.flatMap(f=>f.toFlatIds(i)),...this.implements?this.implements.toFlatIds(i):[],...a.flatMap(f=>f.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,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,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,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(i),inputs:this.inputs.map(a=>a.toJSON(i)),calls:this.calls.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var l,f,e,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.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:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(T=>T.toJSONClone({...i,newId:null})),calls:this.calls.map(T=>T.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(i),inputs:this.inputs.map(f=>f.toReference(i)),calls:this.calls.map(f=>f.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.calls.flatMap(l=>l.toFlatJSON(i)),...this.returnStatements.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.calls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.returnStatements.flatMap(l=>l.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=yK(this);return this.errors=i,{success:!0}}getErrors(){const i=xn(this);return[...this.errors,...this.inputs.flatMap(l=>l.getErrors()),...i.flatMap(l=>l.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.CloneEntity)),a=null,l=null,f=!0,e=!1){var j;let y=lr(a,this);const v=this.toJSON(),T=l||V.UUID.uuid();v.inputs=[];const A=T.split("-id"),I=A[A.length-1||0]||T;v.id=T,v.version=V.UUID.uuid(),v.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),v.author=(i==null?void 0:i.author)||"1",v.previousVersion=null,v.deleted=!1,v.deletable=!0,v.editable=!0;const P=Ei(v,y);a?P.setParent(a,null):P.setParent(this.parent,null),f&&P.subscribe(),P.initChildren(i),i==null||i.add(P,K.Added);const L=(j=this.inputs)==null?void 0:j.map((q,Z)=>q.clone(i,P,I+"-argument-declaration-"+Z+"-id",f));return P.inputs=L,e?(xn(this).map((q,Z)=>q.clone(i,P,I+"-body-entity-"+Z+"-id")),i==null||i.attemptAutoclose(O.CloneEntity,this.id),P):(i==null||i.attemptAutoclose(O.CloneEntity,this.id),P)}getVariableInstances(){return Di(this).filter(l=>l.type===p.VariableInstance)}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}};_(Zt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),_(Zt,"type",p.GlobalEvent),_(Zt,"USER_MANAGED_PARENT_TYPES",[p.Project]),_(Zt,"PARENT_TYPES",[...Zt.USER_MANAGED_PARENT_TYPES]),_(Zt,"MUTABLE_BASE_PROPERTIES",["description"]),_(Zt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Zt,"BASE_PROPERTIES",[...Zt.MUTABLE_BASE_PROPERTIES,...Zt.INMUTABLE_BASE_PROPERTIES]),_(Zt,"MUTABLE_META_PROPERTIES",[...Zt.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),_(Zt,"INMUTABLE_META_PROPERTIES",[...Zt.INMUTABLE_BASE_PROPERTIES]),_(Zt,"META_PROPERTIES",[...Zt.MUTABLE_META_PROPERTIES,...Zt.INMUTABLE_META_PROPERTIES]),_(Zt,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Zt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),_(Zt,"UPSTREAM_PROPERTIES",[...Zt.MUTABLE_UPSTREAM_PROPERTIES,...Zt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Zt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),_(Zt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Zt,"DOWNSTREAM_PROPERTIES",[...Zt.MUTABLE_DOWNSTREAM_PROPERTIES,...Zt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Zt,"PROPERTIES",[...Zt.META_PROPERTIES,...Zt.UPSTREAM_PROPERTIES,...Zt.DOWNSTREAM_PROPERTIES]);let io=Zt;function rA(d){var a,l,f;d.inputs.forEach(e=>e.validate()),d.outputs.forEach(e=>e.validate()),(a=d.error)==null||a.validate(),(l=d.body)==null||l.validate(),(f=d.dataType)==null||f.validate();const i=[...hl(d),...ml(d)];return $i(d.errors,i)}function Cge(d){return rA(d)}const _ge=Object.freeze(Object.defineProperty({__proto__:null,validate:rA,validateListLoop:Cge},Symbol.toStringTag,{value:"Module"}));function hK(d){var i;d.inputs.flatMap(a=>a.validate()),(i=d.dataType)==null||i.validate();const u=[];return $i(d.errors,u)}const Dge=Object.freeze(Object.defineProperty({__proto__:null,validate:hK},Symbol.toStringTag,{value:"Module"}));var z=(d=>(d.Success="success",d.CaughtError="caught-error",d.UnhandledError="unhandled-error",d.Break="break",d.Continue="continue",d.Return="return",d))(z||{});const Wt=class Wt extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"index",null);_(this,"outputName",null);_(this,"outputDescription",null);_(this,"type",p.ActionDescriptor);_(this,"inputs",[]);_(this,"dataType",null);_(this,"error",null);_(this,"implementation",null);_(this,"parent",null);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"autoexecutable",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.codeName=i.codeName,this.description=i.description,this.index=i.index,this.outputName=i.outputName,this.outputDescription=i.outputDescription}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ActionDescriptor,name:"",codeName:null,description:"",error:null,inputs:[],dataType:null,outputName:null,outputDescription:null,index:null,parent:null}}static fromGenerationTarget(i,a){let l=null;if(i.parent){const y=X(i.parent);l=a.get(y)}const f={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:p.ActionDescriptor,codeName:i.codeName,description:i.description,inputs:[],dataType:null,outputName:null,outputDescription:null,index:null,error:null,parent:l},e=se(f,a);return l&&e.setParent(l,null),e}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.DefinitionEntity,p.DataType]}},a);l=e.modifiedData;const y=l.parent?a.get(l.parent):null;if(y&&y.type===p.DefinitionEntity){const v=y,A=Qr(v).filter(I=>!I.interactive);if(A.length){let I=A.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${p.BuiltInBaseEntity}' entities that are non-interactive ("${ut(A.map(P=>Q(P,P.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${p.BuiltInBaseEntity}' entity that is non-interactive ("${Q(A[0],A[0].project)}").`;I+=`
53
+ You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`}))}return{errors:f,modifiedData:l}}get returnStatements(){const i=[];return Object.values(this.detachedDependents).forEach(a=>{a.field===iA.Parent&&a.entity.type===p.ReturnStatement&&!i.includes(a.entity)&&i.push(a.entity)}),i}validateGeneratedUpdate(i){const a=[];return i.parent&&a.push(new de({id:`${this.id}--${W.InvalidParentUpdate}`,code:W.InvalidParentUpdate,severity:Y.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,V.sessionAuthor,B().toISOString(),this,!0,"sync-dependents"))){const a=[],l=[],f=[],e=[];return Object.values(this.detachedDependents).forEach(y=>{const v=y.entity.afterAllChildrenInitialized(i);a.push(...v.updated),l.push(...v.added),f.push(...v.removed),e.push(...v.affected)}),i==null||i.attemptAutoclose("sync-dependents",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}onDetachedDependencyRemoved(i,a,l){const f=[],e=[],y=[],v=[];return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}onDetachedDependencyRestored(i,a,l){const f=[],e=[],y=[],v=[];return{updated:g(f),added:g(e),removed:g(y),affected:g(v),self:this}}unsubscribeFromDependencies(){return this}subscribeToDependencies(){return this}increaseVersion(i){if(i&&!B(i).isValid())throw new Error(`The shared timestamp '${i}' is not a valid ISO 8601 date string.`);return i&&B(i).isSame(B(this.createdAt))?this:(this.previousVersion=this.version,this.version=V.UUID.uuid(),this.createdAt=B(i).toISOString()||B().toISOString(),this)}captureVersion(){var a;const i=((a=this.knownVersions)==null?void 0:a.get(this.version))||new Zt(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.detachedChildren=[...this.detachedChildren],i.parent=this.parent,this}recursiveCaptureUpstreamVersions(i){const a=[],l=[],f=[],e=[];if(this.parent){this.parent.increaseVersion(i);const y=this.parent.recursiveCaptureUpstreamVersions(i);a.push(this.parent,...y.updated),l.push(...y.added),f.push(...y.removed)}return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}async restoreVersion(i){var v;const a=[],l=[],f=[],e=[];if(this.version===i)return{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this};if(!this.knownVersions){const T=new Map;for(const[A,I]of this.knownVersions||new Map){if(T.set(A,I),I.activeVersion=!1,I.knownVersions)for(const[P,L]of I.knownVersions)T.set(P,L);I.knownVersions=null}}let y=(v=this.knownVersions)==null?void 0:v.get(i);if(!y){const T=await this.APILoadVersion({},i);if(!T)throw new Error(`Version with id '${i}' for entity with id '${this.id}' not found.`);y=new Zt(T,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:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}updateWithShallowTransfer(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.UpdateWithShallowTransfer))){if(!this.checkCanEdit(this))return J.warn(`[updateWithShallowTransfer] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),this;if(this.metaSync(i,a),this.version=i.version,this.createdAt=i.createdAt,this.author=i.author,this.deleted=i.deleted,this.previousVersion=i.previousVersion,this.unsubscribeFromDependencies(),i.parent){const l=X(i.parent),f=this.project.get(l),e=this.parent;if(e&&e.id!==(f==null?void 0:f.id)&&this.removeFromParent(a),f)this.setParent(f,null);else throw a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(i.implements){const l=X(i.implements),f=this.project.get(l);if(f)this.setImplements(f,a);else throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${rr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return this.captureVersion(),this.subscribeToDependencies(),a==null||a.attemptAutoclose(O.UpdateWithShallowTransfer,this.id),this}hydrateAncestors(){const i=[],a=[],l=[],f=[];if(this.initialData.parent){const e=X(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=X(this.initialData.implements),y=this.project.get(e);if(y)this.setImplements(y,null),i.push(y);else throw new Error(`${rr(this.type)} with id '${this.id}' has a 'implements' reference "${e}" which is missing in the project`)}else throw new Error(`${rr(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:g(i),added:g(a),removed:g(l),affected:g(f),self:this}}afterAllChildrenInitialized(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.AfterAllChildrenInitialized))){if(!this.checkCanEdit(this))return J.warn(`[afterAllChildrenInitialized] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(O.AfterAllChildrenInitialized,this.id),{updated:[],added:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.initialized=!0,this.captureVersion(),i==null||i.attemptAutoclose(O.AfterAllChildrenInitialized,this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}addSelfToProject(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"add-self-to-project"))){const a=[this],l=[],f=[],e=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),i==null||i.attemptAutoclose("add-self-to-project",this.id),{updated:g(a),added:g(l),removed:g(f),affected:g(e),self:this}}replaceDetachedChild(i,a){const l=this.detachedChildren.indexOf(i);return l!==-1&&(this.detachedChildren[l]=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}setParent(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.SetParent))){var l;return this.checkCanEditWithCounterpartAndSideEffects(this,i,O.SetParent,a)?(((l=this.parent)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.parent=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(O.SetParent,this.id),this):this}setImplements(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.SetImplements))){var l;return this.checkCanEdit(this)?(((l=this.implements)==null?void 0:l.id)!==(i==null?void 0:i.id)&&(this.implements=i,a&&(a==null||a.add(this,K.Updated))),a==null||a.attemptAutoclose(O.SetImplements,this.id),this):(J.warn(`[setImplements] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.SetImplements,this.id),this)}addCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.AddCall))){return this.checkCanEdit(this)?(this.calls.includes(i)||(this.calls.push(i),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose(O.AddCall,this.id),this):(J.warn(`[addCall] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.AddCall,this.id),this)}removeCall(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RemoveCall))){if(!this.checkCanEdit(this))return J.warn(`[removeCall] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),a==null||a.attemptAutoclose(O.RemoveCall,this.id),this;const l=this.calls.indexOf(i);return l!==-1&&(this.calls.splice(l,1),a==null||a.add(i,K.Affected)),a==null||a.attemptAutoclose(O.RemoveCall,this.id),this}addInputDeclaration(i,a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().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,V.sessionAuthor,B().toISOString(),this,!0,"remove-input-declaration"))){const l=this.inputs.findIndex(f=>f.id===i.id);return l>-1&&(this.inputs.splice(l,1),a&&(a==null||a.add(this,K.Affected))),a==null||a.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(a=>{const l=se(a,this.project);return l.setParent(this,null),l.initChildren(i),l}),this.calls=this.initialData.calls.map(a=>{const l=se(a,this.project);if(l.addEntryCaller(this,null),l.type===p.ReturnStatement){const f=fr(this,this.project);l.setParent(f,null),l.initChildren(i)}else l.type!==p.InternalCall&&(l.setParent(this,null),l.initChildren(i));return l}),this.implements=se(this.initialData.implements,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,V.sessionAuthor,B().toISOString(),this,!0,"meta-sync"))){const l=Xi(this,i),f=Yi(this,l),e=this.toMeta();return this.name=l.name!==void 0?l.name:e.name,this.description=l.description!==void 0?l.description:e.description,this.x=l.x||e.x,this.y=l.y||e.y,this.collapsed=l.collapsed!==void 0?l.collapsed:e.collapsed,super.baseMetaSync(l,this),l.deleted===!0&&!e.deleted?a==null||a.add(this,K.Removed):l.deleted===!1&&e.deleted?a==null||a.add(this,K.Added):f&&(a==null||a.add(this,K.Updated)),a==null||a.attemptAutoclose("meta-sync",this.id),this}async APILoad(i=Ie,...a){return await Zt.repository.APILoad(this.id,...a),this}async APICreate(i=Ie,...a){return await Zt.repository.APICreate(this.toShallowJSON(),...a),this}async APIUpdate(i=Ie,...a){return await Zt.repository.APIUpdate(this.toShallowJSON(),...a),this}async APIDelete(i=Ie,...a){return await Zt.repository.APIDelete(this.toShallowJSON(),...a),this}async APIClone(i=Ie,...a){return await Zt.repository.APIClone(this.id,...a),this}async APILoadVersion(i=Ie,a,...l){return await Zt.repository.APILoadVersion(this.id,a,...l)}removeFromParent(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RemoveFromParent))){if(!this.checkCanEdit(this))return J.warn(`[removeFromParent] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(O.RemoveFromParent,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return this.parent.type===p.Project&&(this.project.removeGlobalEvent(this),i==null||i.add(this.parent,K.Affected),e.push(this.parent)),i==null||i.attemptAutoclose(O.RemoveFromParent,this.id),{added:g(f),updated:g(a),removed:g(l),affected:g(e),self:this}}remove({ignoreUpstream:i}={ignoreUpstream:!1},a=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RemoveEntity))){var T;if(!this.checkCanDelete(this)||!this.checkCanEdit(this))return J.warn(`[remove] User is not allowed to delete or edit this ${this.type} entity with id: ${this.id}`),a==null||a.event({id:`${O.RemoveEntity}-${this.id}`,action:O.RemoveEntity,owner:this,errorReason:Si.ActionOwnerEntityNonDeletable,rootAction:((T=a==null?void 0:a.self)==null?void 0:T.id)===this.id&&(a==null?void 0:a.autoCloseActionName)===O.RemoveEntity}),a==null||a.attemptAutoclose(O.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const l=[],f=[],e=[],y=[];if(a!=null&&a.hasRemoved(this.id))return a==null||a.attemptAutoclose(O.RemoveEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(f.push(this),this.unsubscribe(),this.unsubscribeFromDependencies(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},a),Object.values(this.detachedDependents).forEach(A=>{const{updated:I,removed:P,added:L}=A.entity.onDetachedDependencyRemoved(this,A.field,a);l.push(...I),f.push(...P),e.push(...L)}),this.inputs.forEach(A=>{const{updated:I,removed:P}=A.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...P)}),xn(this).forEach(A=>{const{updated:I,removed:P}=A.remove({ignoreUpstream:!0},a);l.push(...I),f.push(...P)}),!i){const A=this.removeFromParent(a);e.push(...A.added),l.push(...A.updated),f.push(...A.removed),y.push(...A.affected)}return a==null||a.attemptAutoclose(O.RemoveEntity,this.id),{added:g(e),updated:g(l),removed:g(f),affected:g(y),self:this}}restore({}={},i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.RestoreEntity))){if(!this.checkCanEdit(this))return J.warn(`[restore] User is not allowed to edit this ${this.type} entity with id: ${this.id}`),i==null||i.attemptAutoclose(O.RestoreEntity,this.id),{added:[],updated:[],removed:[],affected:[],self:this};const a=[],l=[],f=[],e=[];return i!=null&&i.hasAdded(this.id)?(i==null||i.attemptAutoclose(O.RestoreEntity,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:T,removed:A,added:I}=v.entity.onDetachedDependencyRestored(this,v.field,i);l.push(...T),f.push(...A),a.push(...I)}),this.inputs.forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),xn(this).forEach(v=>{const{updated:T}=v.restore({},i);l.push(...T)}),i==null||i.attemptAutoclose(O.RestoreEntity,this.id),{added:g(a),updated:g(l),removed:g(f),affected:g(e),self:this})}toFlat(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this,...this.inputs.flatMap(l=>l.toFlat(i)),...this.calls.flatMap(l=>l.toFlat(i)),...this.returnStatements.flatMap(l=>l.toFlat(i)),...this.implements?this.implements.toFlat(i):[]])}toFlatIds(i=new Set){if(i.has(this.id))return[];i.add(this.id);const a=xn(this);return[this.id,...this.inputs.flatMap(f=>f.toFlatIds(i)),...this.calls.flatMap(f=>f.toFlatIds(i)),...this.returnStatements.flatMap(f=>f.toFlatIds(i)),...this.implements?this.implements.toFlatIds(i):[],...a.flatMap(f=>f.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,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,editable:this.editable,deletable:this.deletable,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,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(i),inputs:this.inputs.map(a=>a.toJSON(i)),calls:this.calls.map(a=>a.toJSON(i)),parent:this.parent.toReference()})}toJSONClone(i=ke){var l,f,e,y,v;let a;return(l=i.seenEntityMaps)!=null&&l.has(this.id)?a=i.seenEntityMaps.get(this.id):(a=i.newId||or(this,this.project,i.uuidStrategy),i.seenEntityMaps&&i.seenEntityMaps.set(this.id,a)),(f=i.seenEntities)!=null&&f.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:V.UUID.uuid(),createdAt:i.timestamp||B().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(T=>T.toJSONClone({...i,newId:null})),calls:this.calls.map(T=>T.toJSONClone({...i,newId:null})),parent:this.parent.toReference({seenEntityMaps:i.seenEntityMaps})})}toReference(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a+"--"+V.UUID.uuid()+"--ref",type:p.GenericReference,entityId:a,version:this.version,entityType:this.type}}toShallowJSON(i=ke){var l;let a=this.id;return(l=i.seenEntityMaps)!=null&&l.has(this.id)&&(a=i.seenEntityMaps.get(this.id)),{id:a,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,editable:this.editable,deletable:this.deletable,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(i),inputs:this.inputs.map(f=>f.toReference(i)),calls:this.calls.map(f=>f.toReference(i)),parent:this.parent.toReference(i)}}toFlatJSON(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(l=>l.toFlatJSON(i)),...this.calls.flatMap(l=>l.toFlatJSON(i)),...this.returnStatements.flatMap(l=>l.toFlatJSON(i))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(i=new Set){return i.has(this.id)?[]:(i.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(i)),...this.calls.flatMap(l=>l.toFlatGenerationTarget(i)),...this.returnStatements.flatMap(l=>l.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=yK(this);return this.errors=i,{success:!0}}getErrors(){const i=xn(this);return[...this.errors,...this.inputs.flatMap(l=>l.getErrors()),...i.flatMap(l=>l.getErrors())]}getShallowErrors(){return this.errors}clone(i=this.project.addChangeSet(new G(this.project,V.sessionAuthor,B().toISOString(),this,!0,O.CloneEntity)),a=null,l=null,f=!0,e=!1){var j;let y=lr(a,this);const v=this.toJSON(),T=l||V.UUID.uuid();v.inputs=[];const A=T.split("-id"),I=A[A.length-1||0]||T;v.id=T,v.version=V.UUID.uuid(),v.createdAt=(i==null?void 0:i.timestamp)||B().toISOString(),v.author=(i==null?void 0:i.author)||"1",v.previousVersion=null,v.deleted=!1,v.deletable=!0,v.editable=!0;const P=Ei(v,y);a?P.setParent(a,null):P.setParent(this.parent,null),f&&P.subscribe(),P.initChildren(i),i==null||i.add(P,K.Added);const L=(j=this.inputs)==null?void 0:j.map((q,Z)=>q.clone(i,P,I+"-argument-declaration-"+Z+"-id",f));return P.inputs=L,e?(xn(this).map((q,Z)=>q.clone(i,P,I+"-body-entity-"+Z+"-id")),i==null||i.attemptAutoclose(O.CloneEntity,this.id),P):(i==null||i.attemptAutoclose(O.CloneEntity,this.id),P)}getVariableInstances(){return Di(this).filter(l=>l.type===p.VariableInstance)}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}};_(Zt,"repository",{APICreate:async(i,...a)=>i,APIUpdate:async(i,...a)=>i,APIDelete:async(i,...a)=>i,APIClone:async(i,...a)=>{},APILoad:async(i,...a)=>null,APILoadVersion:async(i,a,...l)=>null}),_(Zt,"type",p.GlobalEvent),_(Zt,"USER_MANAGED_PARENT_TYPES",[p.Project]),_(Zt,"PARENT_TYPES",[...Zt.USER_MANAGED_PARENT_TYPES]),_(Zt,"MUTABLE_BASE_PROPERTIES",["description"]),_(Zt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),_(Zt,"BASE_PROPERTIES",[...Zt.MUTABLE_BASE_PROPERTIES,...Zt.INMUTABLE_BASE_PROPERTIES]),_(Zt,"MUTABLE_META_PROPERTIES",[...Zt.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),_(Zt,"INMUTABLE_META_PROPERTIES",[...Zt.INMUTABLE_BASE_PROPERTIES]),_(Zt,"META_PROPERTIES",[...Zt.MUTABLE_META_PROPERTIES,...Zt.INMUTABLE_META_PROPERTIES]),_(Zt,"MUTABLE_UPSTREAM_PROPERTIES",[]),_(Zt,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),_(Zt,"UPSTREAM_PROPERTIES",[...Zt.MUTABLE_UPSTREAM_PROPERTIES,...Zt.INMUTABLE_UPSTREAM_PROPERTIES]),_(Zt,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),_(Zt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),_(Zt,"DOWNSTREAM_PROPERTIES",[...Zt.MUTABLE_DOWNSTREAM_PROPERTIES,...Zt.INMUTABLE_DOWNSTREAM_PROPERTIES]),_(Zt,"PROPERTIES",[...Zt.META_PROPERTIES,...Zt.UPSTREAM_PROPERTIES,...Zt.DOWNSTREAM_PROPERTIES]);let io=Zt;function rA(d){var a,l,f;d.inputs.forEach(e=>e.validate()),d.outputs.forEach(e=>e.validate()),(a=d.error)==null||a.validate(),(l=d.body)==null||l.validate(),(f=d.dataType)==null||f.validate();const i=[...hl(d),...ml(d)];return $i(d.errors,i)}function Cge(d){return rA(d)}const _ge=Object.freeze(Object.defineProperty({__proto__:null,validate:rA,validateListLoop:Cge},Symbol.toStringTag,{value:"Module"}));function hK(d){var i;d.inputs.flatMap(a=>a.validate()),(i=d.dataType)==null||i.validate();const u=[];return $i(d.errors,u)}const Dge=Object.freeze(Object.defineProperty({__proto__:null,validate:hK},Symbol.toStringTag,{value:"Module"}));var z=(d=>(d.Success="success",d.ConditionNotMet="condition-not-met",d.CaughtError="caught-error",d.UnhandledError="unhandled-error",d.Break="break",d.Continue="continue",d.Return="return",d))(z||{});const Wt=class Wt extends nr{constructor(i,a){super(i);_(this,"initialData");_(this,"id");_(this,"name");_(this,"codeName",null);_(this,"description",null);_(this,"index",null);_(this,"outputName",null);_(this,"outputDescription",null);_(this,"type",p.ActionDescriptor);_(this,"inputs",[]);_(this,"dataType",null);_(this,"error",null);_(this,"implementation",null);_(this,"parent",null);_(this,"errors",[]);_(this,"project");_(this,"detachedDependents",{});_(this,"knownVersions",null);_(this,"activeVersion",!1);_(this,"initialized",!1);_(this,"startedInitialization",!1);_(this,"autoexecutable",!1);this.initialData=i,this.project=a,this.id=i.id,this.name=i.name,this.codeName=i.codeName,this.description=i.description,this.index=i.index,this.outputName=i.outputName,this.outputDescription=i.outputDescription}static new(i=null){return{id:V.UUID.uuid(),version:V.UUID.uuid(),createdAt:(i==null?void 0:i.timestamp)||B().toISOString(),author:(i==null?void 0:i.author)||V.sessionAuthor,previousVersion:null,deleted:!1,deletable:!0,editable:!0,type:p.ActionDescriptor,name:"",codeName:null,description:"",error:null,inputs:[],dataType:null,outputName:null,outputDescription:null,index:null,parent:null}}static fromGenerationTarget(i,a){let l=null;if(i.parent){const y=X(i.parent);l=a.get(y)}const f={id:i.id,version:V.UUID.uuid(),createdAt:B().toISOString(),author:V.sessionAuthor,previousVersion:null,deleted:!1,name:i.name,deletable:!0,editable:!0,type:p.ActionDescriptor,codeName:i.codeName,description:i.description,inputs:[],dataType:null,outputName:null,outputDescription:null,index:null,error:null,parent:l},e=se(f,a);return l&&e.setParent(l,null),e}static validateGenerationTarget(i,a){let l=JSON.parse(JSON.stringify(i));const f=[],e=Pr(l,{parent:{list:!1,types:[p.DefinitionEntity,p.DataType]}},a);l=e.modifiedData;const y=l.parent?a.get(l.parent):null;if(y&&y.type===p.DefinitionEntity){const v=y,A=Qr(v).filter(I=>!I.interactive);if(A.length){let I=A.length>1?`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements multiple '${p.BuiltInBaseEntity}' entities that are non-interactive ("${ut(A.map(P=>Q(P,P.project)),'", "','" and "')}").`:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it extends or implements a '${p.BuiltInBaseEntity}' entity that is non-interactive ("${Q(A[0],A[0].project)}").`;I+=`
54
54
  ${To}`,f.push(new de({id:`${i.id}--${W.NonInteractiveEntityReferenced}`,code:W.NonInteractiveEntityReferenced,severity:Y.Error,message:I}))}}else if(y&&y.type===p.DataType){const v=y;v.entity&&f.push(new de({id:`${i.id}--${W.NewEntityWouldOverriteExisting}`,code:W.NewEntityWouldOverriteExisting,severity:Y.Error,message:`The entity of type '${i.type}' with id '${i.id}' can't be added to the 'parent' entity with id '${v.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
55
55
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
56
56
  ${ga({describe_entity:v.entity.id})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyx-code/project-logic-tree",
3
- "version": "0.0.6551",
3
+ "version": "0.0.6552",
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",