@ronaldroe/micro-flow 2.0.0 → 3.0.0

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.
Files changed (34) hide show
  1. package/dist/src/classes/base.js +2 -2
  2. package/dist/src/classes/base.js.map +2 -2
  3. package/dist/src/classes/index.js +1 -1
  4. package/dist/src/classes/index.js.map +2 -2
  5. package/dist/src/classes/instance_state.js +2 -0
  6. package/dist/src/classes/instance_state.js.map +7 -0
  7. package/dist/src/classes/state.js +1 -1
  8. package/dist/src/classes/state.js.map +3 -3
  9. package/dist/src/classes/steps/conditional_step.js +1 -1
  10. package/dist/src/classes/steps/conditional_step.js.map +3 -3
  11. package/dist/src/classes/steps/delay_step.js +1 -1
  12. package/dist/src/classes/steps/delay_step.js.map +3 -3
  13. package/dist/src/classes/steps/flow_control_step.js +1 -1
  14. package/dist/src/classes/steps/flow_control_step.js.map +3 -3
  15. package/dist/src/classes/steps/logic_step.js +1 -1
  16. package/dist/src/classes/steps/logic_step.js.map +3 -3
  17. package/dist/src/classes/steps/step.js +1 -1
  18. package/dist/src/classes/steps/step.js.map +2 -2
  19. package/dist/src/classes/steps/switch_step.js +1 -1
  20. package/dist/src/classes/steps/switch_step.js.map +3 -3
  21. package/dist/src/classes/workflow.js +1 -1
  22. package/dist/src/classes/workflow.js.map +3 -3
  23. package/package.json +1 -1
  24. package/src/classes/base.js +2 -1
  25. package/src/classes/index.js +2 -1
  26. package/src/classes/instance_state.js +277 -0
  27. package/src/classes/state.js +14 -313
  28. package/src/classes/steps/conditional_step.js +3 -2
  29. package/src/classes/steps/delay_step.js +5 -8
  30. package/src/classes/steps/flow_control_step.js +3 -2
  31. package/src/classes/steps/logic_step.js +38 -38
  32. package/src/classes/steps/step.js +12 -6
  33. package/src/classes/steps/switch_step.js +2 -1
  34. package/src/classes/workflow.js +52 -31
@@ -1,4 +1,4 @@
1
- var r=Object.defineProperty;var o=(n,t)=>r(n,"name",{value:t,configurable:!0});import h from"crypto";import{base_types as m}from"../enums/index.js";import e,{InstanceState as l}from"./state.js";class p{static{o(this,"Base")}constructor({name:t,base_type:s=m.STEP,use_state_singleton:i=!1,state:a=null}){this.id=h.randomUUID(),this.name=t??`${s}-${this.id}`,this.base_type=s,this.use_state_singleton=i,this.state=i?null:a??new l,this.timing={cancel_time:null,complete_time:null,execution_time_ms:null,start_time:null}}async execute(){throw new Error("Execute method not implemented")}log(t,s=null){if(!t||!e.get(`events.${this.base_type}`))throw new Error("Invalid event name or event emitter not found");if(e.get(`events.${this.base_type}`).emit(t,this),e.get("log_suppress"))return;const i=s?`
1
+ var r=Object.defineProperty;var o=(n,t)=>r(n,"name",{value:t,configurable:!0});import h from"crypto";import{base_types as m}from"../enums/index.js";import e from"./state.js";import{InstanceState as p}from"./instance_state.js";class l{static{o(this,"Base")}constructor({name:t,base_type:s=m.STEP,use_state_singleton:i=!1,state:a=null}){this.id=h.randomUUID(),this.name=t??`${s}-${this.id}`,this.base_type=s,this.use_state_singleton=i,this.state=i?null:a??new p,this.timing={cancel_time:null,complete_time:null,execution_time_ms:null,start_time:null}}async execute(){throw new Error("Execute method not implemented")}log(t,s=null){if(!t||!e.get(`events.${this.base_type}`))throw new Error("Invalid event name or event emitter not found");if(e.get(`events.${this.base_type}`).emit(t,this),e.get("log_suppress"))return;const i=s?`
2
2
  [${this.base_type.toUpperCase()} - ${this.name}] ${s}`:`
3
- [${this.base_type.toUpperCase()} - ${this.name}] Event: ${t}`,a=t.endsWith("_failed")?"error":"log";console[a](i)}markAsComplete(){this.timing.complete_time=new Date,this.status=e.get("statuses")[this.base_type].COMPLETE,this.timing.execution_time_ms=this.timing.complete_time-this.timing.start_time,this.steps_by_id&&delete this.steps_by_id,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_COMPLETE`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" complete.`)}markAsFailed(){this.timing.complete_time=new Date,this.status=e.get("statuses")[this.base_type].FAILED,this.timing.execution_time_ms=this.timing.complete_time-this.timing.start_time,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_FAILED`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" failed.`)}markAsWaiting(){}markAsPending(){}markAsRunning(){this.timing.start_time=this.timing.start_time??new Date,this.status=e.get("statuses")[this.base_type].RUNNING,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_RUNNING`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" started.`)}getState(t){return this.use_state_singleton?(console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),e.get(t)):this.state.get(t)}setState(t,s){if(this.use_state_singleton){console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),e.set(t,s);return}this.state.set(t,s)}deleteState(t){if(this.use_state_singleton){console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),e.delete(t);return}this.state.delete(t)}}export{p as default};
3
+ [${this.base_type.toUpperCase()} - ${this.name}] Event: ${t}`,a=t.endsWith("_failed")?"error":"log";console[a](i)}markAsComplete(){this.timing.complete_time=new Date,this.status=e.get("statuses")[this.base_type].COMPLETE,this.timing.execution_time_ms=this.timing.complete_time-this.timing.start_time,this.steps_by_id&&delete this.steps_by_id,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_COMPLETE`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" complete.`)}markAsFailed(){this.timing.complete_time=new Date,this.status=e.get("statuses")[this.base_type].FAILED,this.timing.execution_time_ms=this.timing.complete_time-this.timing.start_time,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_FAILED`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" failed.`)}markAsWaiting(){}markAsPending(){}markAsRunning(){this.timing.start_time=this.timing.start_time??new Date,this.status=e.get("statuses")[this.base_type].RUNNING,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_RUNNING`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" started.`)}getState(t){return this.use_state_singleton?(console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),e.get(t)):this.state.get(t)}setState(t,s){if(this.use_state_singleton){console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),e.set(t,s);return}this.state.set(t,s)}deleteState(t){if(this.use_state_singleton){console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),e.delete(t);return}this.state.delete(t)}}export{l as default};
4
4
  //# sourceMappingURL=base.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/classes/base.js"],
4
- "sourcesContent": ["import crypto from 'crypto';\nimport { base_types } from '../enums/index.js';\nimport State, { InstanceState } from './state.js';\n\n/**\n * Base class for workflows and steps.\n * Provides common functionality for timing, status management, logging, and state access.\n * @class Base\n */\nexport default class Base {\n /**\n * Creates a new Base instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the instance.\n * @param {string} [options.base_type=base_types.STEP] - Type of the base instance.\n * @param {boolean} [options.use_state_singleton=false] - Deprecated. When true, `getState`/`setState`/`deleteState`\n * fall back to the process-wide `State` singleton instead of this instance's own state. `Workflow` passes this\n * value down to every `Step` it owns, so it only needs to be set once, on the workflow.\n * @param {InstanceState|null} [options.state=null] - The `InstanceState` this instance's `getState`/`setState`/\n * `deleteState` calls should read and write. `Workflow` creates its own on construction and shares it with its\n * `Step`s; a `Step` created standalone (not yet added to a workflow) gets its own until it's added to one.\n */\n constructor({ name, base_type = base_types.STEP, use_state_singleton = false, state = null }) {\n this.id = crypto.randomUUID();\n this.name = name ?? `${base_type}-${this.id}`;\n\n this.base_type = base_type;\n this.use_state_singleton = use_state_singleton;\n this.state = use_state_singleton ? null : (state ?? new InstanceState());\n this.timing = {\n cancel_time: null,\n complete_time: null,\n execution_time_ms: null,\n start_time: null,\n }\n }\n\n /**\n * Executes the instance. Must be overridden by subclasses.\n * @async\n * @throws {Error} Throws if not implemented in subclass.\n */\n async execute() {\n throw new Error('Execute method not implemented');\n }\n\n /**\n * Logs an event and emits it to the appropriate event emitter.\n * @param {string} event_name - Name of the event to log.\n * @param {string} [message=null] - Optional message to log.\n * @throws {Error} Throws if event name is invalid or event emitter not found.\n */\n log(event_name, message = null) {\n if (!event_name || !State.get(`events.${this.base_type}`)) {\n throw new Error('Invalid event name or event emitter not found');\n }\n\n State.get(`events.${this.base_type}`).emit(event_name, this);\n if (State.get('log_suppress')) {\n return;\n }\n\n const log_message = message ? `\\n[${this.base_type.toUpperCase()} - ${this.name}] ${message}` : `\\n[${this.base_type.toUpperCase()} - ${this.name}] Event: ${event_name}`;\n const log_type = event_name.endsWith('_failed') ? 'error' : 'log';\n\n console[log_type](log_message);\n }\n\n /**\n * Marks the instance as complete and calculates execution time.\n */\n markAsComplete() {\n this.timing.complete_time = new Date();\n this.status = State.get('statuses')[this.base_type].COMPLETE;\n this.timing.execution_time_ms = this.timing.complete_time - this.timing.start_time;\n\n if (this.steps_by_id) {\n delete this.steps_by_id;\n }\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_COMPLETE`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" complete.`\n );\n }\n\n /**\n * Marks the instance as failed and calculates execution time.\n */\n markAsFailed() {\n this.timing.complete_time = new Date();\n this.status = State.get('statuses')[this.base_type].FAILED;\n this.timing.execution_time_ms = this.timing.complete_time - this.timing.start_time;\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_FAILED`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" failed.`\n );\n }\n\n /**\n * Marks the instance as waiting. To be implemented by subclasses.\n */\n markAsWaiting() { }\n\n /**\n * Marks the instance as pending. To be implemented by subclasses.\n */\n markAsPending() { }\n\n /**\n * Marks the instance as running and sets the start time.\n */\n markAsRunning() {\n this.timing.start_time = this.timing.start_time ?? new Date();\n this.status = State.get('statuses')[this.base_type].RUNNING;\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_RUNNING`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" started.`\n );\n }\n\n // State management methods\n /**\n * Gets a value from this instance's own state (the `Workflow`'s state, shared with its `Step`s).\n * Set `use_state_singleton: true` (on the owning `Workflow`) to instead read from the\n * deprecated, process-wide `State` singleton.\n * @param {string} path - Path to the state property.\n * @returns {*} The state value at the specified path.\n */\n getState(path) {\n if (this.use_state_singleton) {\n console.warn('The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead.');\n return State.get(path);\n }\n\n return this.state.get(path);\n }\n\n /**\n * Sets a value in this instance's own state (the `Workflow`'s state, shared with its `Step`s).\n * Set `use_state_singleton: true` (on the owning `Workflow`) to instead write to the\n * deprecated, process-wide `State` singleton.\n * @param {string} path - Path to the state property.\n * @param {*} value - Value to set.\n */\n setState(path, value) {\n if (this.use_state_singleton) {\n console.warn('The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead.');\n State.set(path, value);\n return;\n }\n\n this.state.set(path, value);\n }\n\n /**\n * Deletes a property from this instance's own state (the `Workflow`'s state, shared with its `Step`s).\n * Set `use_state_singleton: true` (on the owning `Workflow`) to instead delete from the\n * deprecated, process-wide `State` singleton.\n * @param {string} path - Path to the state property to delete.\n */\n deleteState(path) {\n if (this.use_state_singleton) {\n console.warn('The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead.');\n State.delete(path);\n return;\n }\n\n this.state.delete(path);\n }\n}\n"],
5
- "mappings": "+EAAA,OAAOA,MAAY,SACnB,OAAS,cAAAC,MAAkB,oBAC3B,OAAOC,GAAS,iBAAAC,MAAqB,aAOrC,MA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AAsH,EACnIZ,EAAM,OAAOY,CAAI,EACjB,MACF,CAEA,KAAK,MAAM,OAAOA,CAAI,CACxB,CACF",
4
+ "sourcesContent": ["import crypto from 'crypto';\nimport { base_types } from '../enums/index.js';\nimport State from './state.js';\nimport { InstanceState } from './instance_state.js';\n\n/**\n * Base class for workflows and steps.\n * Provides common functionality for timing, status management, logging, and state access.\n * @class Base\n */\nexport default class Base {\n /**\n * Creates a new Base instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the instance.\n * @param {string} [options.base_type=base_types.STEP] - Type of the base instance.\n * @param {boolean} [options.use_state_singleton=false] - Deprecated. When true, `getState`/`setState`/`deleteState`\n * fall back to the process-wide `State` singleton instead of this instance's own state. `Workflow` passes this\n * value down to every `Step` it owns, so it only needs to be set once, on the workflow.\n * @param {InstanceState|null} [options.state=null] - The `InstanceState` this instance's `getState`/`setState`/\n * `deleteState` calls should read and write. `Workflow` creates its own on construction and shares it with its\n * `Step`s; a `Step` created standalone (not yet added to a workflow) gets its own until it's added to one.\n */\n constructor({ name, base_type = base_types.STEP, use_state_singleton = false, state = null }) {\n this.id = crypto.randomUUID();\n this.name = name ?? `${base_type}-${this.id}`;\n\n this.base_type = base_type;\n this.use_state_singleton = use_state_singleton;\n this.state = use_state_singleton ? null : (state ?? new InstanceState());\n this.timing = {\n cancel_time: null,\n complete_time: null,\n execution_time_ms: null,\n start_time: null,\n }\n }\n\n /**\n * Executes the instance. Must be overridden by subclasses.\n * @async\n * @throws {Error} Throws if not implemented in subclass.\n */\n async execute() {\n throw new Error('Execute method not implemented');\n }\n\n /**\n * Logs an event and emits it to the appropriate event emitter.\n * @param {string} event_name - Name of the event to log.\n * @param {string} [message=null] - Optional message to log.\n * @throws {Error} Throws if event name is invalid or event emitter not found.\n */\n log(event_name, message = null) {\n if (!event_name || !State.get(`events.${this.base_type}`)) {\n throw new Error('Invalid event name or event emitter not found');\n }\n\n State.get(`events.${this.base_type}`).emit(event_name, this);\n if (State.get('log_suppress')) {\n return;\n }\n\n const log_message = message ? `\\n[${this.base_type.toUpperCase()} - ${this.name}] ${message}` : `\\n[${this.base_type.toUpperCase()} - ${this.name}] Event: ${event_name}`;\n const log_type = event_name.endsWith('_failed') ? 'error' : 'log';\n\n console[log_type](log_message);\n }\n\n /**\n * Marks the instance as complete and calculates execution time.\n */\n markAsComplete() {\n this.timing.complete_time = new Date();\n this.status = State.get('statuses')[this.base_type].COMPLETE;\n this.timing.execution_time_ms = this.timing.complete_time - this.timing.start_time;\n\n if (this.steps_by_id) {\n delete this.steps_by_id;\n }\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_COMPLETE`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" complete.`\n );\n }\n\n /**\n * Marks the instance as failed and calculates execution time.\n */\n markAsFailed() {\n this.timing.complete_time = new Date();\n this.status = State.get('statuses')[this.base_type].FAILED;\n this.timing.execution_time_ms = this.timing.complete_time - this.timing.start_time;\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_FAILED`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" failed.`\n );\n }\n\n /**\n * Marks the instance as waiting. To be implemented by subclasses.\n */\n markAsWaiting() { }\n\n /**\n * Marks the instance as pending. To be implemented by subclasses.\n */\n markAsPending() { }\n\n /**\n * Marks the instance as running and sets the start time.\n */\n markAsRunning() {\n this.timing.start_time = this.timing.start_time ?? new Date();\n this.status = State.get('statuses')[this.base_type].RUNNING;\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_RUNNING`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" started.`\n );\n }\n\n // State management methods\n /**\n * Gets a value from this instance's own state (the `Workflow`'s state, shared with its `Step`s).\n * Set `use_state_singleton: true` (on the owning `Workflow`) to instead read from the\n * deprecated, process-wide `State` singleton.\n * @param {string} path - Path to the state property.\n * @returns {*} The state value at the specified path.\n */\n getState(path) {\n if (this.use_state_singleton) {\n console.warn('The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead.');\n return State.get(path);\n }\n\n return this.state.get(path);\n }\n\n /**\n * Sets a value in this instance's own state (the `Workflow`'s state, shared with its `Step`s).\n * Set `use_state_singleton: true` (on the owning `Workflow`) to instead write to the\n * deprecated, process-wide `State` singleton.\n * @param {string} path - Path to the state property.\n * @param {*} value - Value to set.\n */\n setState(path, value) {\n if (this.use_state_singleton) {\n console.warn('The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead.');\n State.set(path, value);\n return;\n }\n\n this.state.set(path, value);\n }\n\n /**\n * Deletes a property from this instance's own state (the `Workflow`'s state, shared with its `Step`s).\n * Set `use_state_singleton: true` (on the owning `Workflow`) to instead delete from the\n * deprecated, process-wide `State` singleton.\n * @param {string} path - Path to the state property to delete.\n */\n deleteState(path) {\n if (this.use_state_singleton) {\n console.warn('The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead.');\n State.delete(path);\n return;\n }\n\n this.state.delete(path);\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAY,SACnB,OAAS,cAAAC,MAAkB,oBAC3B,OAAOC,MAAW,aAClB,OAAS,iBAAAC,MAAqB,sBAO9B,MAAOC,CAAmB,CAV1B,MAU0B,CAAAC,EAAA,aAaxB,YAAY,CAAE,KAAAC,EAAM,UAAAC,EAAYN,EAAW,KAAM,oBAAAO,EAAsB,GAAO,MAAAC,EAAQ,IAAK,EAAG,CAC5F,KAAK,GAAKT,EAAO,WAAW,EAC5B,KAAK,KAAOM,GAAQ,GAAGC,CAAS,IAAI,KAAK,EAAE,GAE3C,KAAK,UAAYA,EACjB,KAAK,oBAAsBC,EAC3B,KAAK,MAAQA,EAAsB,KAAQC,GAAS,IAAIN,EACxD,KAAK,OAAS,CACZ,YAAa,KACb,cAAe,KACf,kBAAmB,KACnB,WAAY,IACd,CACF,CAO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,CAAC,EAAE,YAAY,EAAI,KAAK,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,IAAI,WACnF,CACF,CAKA,eAAgB,CAAE,CAKlB,eAAgB,CAAE,CAKlB,eAAgB,CACd,KAAK,OAAO,WAAa,KAAK,OAAO,YAAc,IAAI,KACvD,KAAK,OAASA,EAAM,IAAI,UAAU,EAAE,KAAK,SAAS,EAAE,QAEpD,KAAK,IACHA,EAAM,IAAI,eAAe,KAAK,SAAS,EAAE,EAAE,GAAG,KAAK,UAAU,YAAY,CAAC,UAAU,EACpF,GAAG,KAAK,UAAU,OAAO,CAAC,EAAE,YAAY,EAAI,KAAK,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,IAAI,YACnF,CACF,CAUA,SAASY,EAAM,CACb,OAAI,KAAK,qBACP,QAAQ,KAAK,sHAAsH,EAC5HZ,EAAM,IAAIY,CAAI,GAGhB,KAAK,MAAM,IAAIA,CAAI,CAC5B,CASA,SAASA,EAAMC,EAAO,CACpB,GAAI,KAAK,oBAAqB,CAC5B,QAAQ,KAAK,sHAAsH,EACnIb,EAAM,IAAIY,EAAMC,CAAK,EACrB,MACF,CAEA,KAAK,MAAM,IAAID,EAAMC,CAAK,CAC5B,CAQA,YAAYD,EAAM,CAChB,GAAI,KAAK,oBAAqB,CAC5B,QAAQ,KAAK,sHAAsH,EACnIZ,EAAM,OAAOY,CAAI,EACjB,MACF,CAEA,KAAK,MAAM,OAAOA,CAAI,CACxB,CACF",
6
6
  "names": ["crypto", "base_types", "State", "InstanceState", "Base", "__name", "name", "base_type", "use_state_singleton", "state", "event_name", "message", "log_message", "log_type", "path", "value"]
7
7
  }
@@ -1,2 +1,2 @@
1
- export*from"./events/index.js";import{default as o}from"./base.js";import{default as f}from"./callable_registry.js";import{default as s,InstanceState as m}from"./state.js";import{default as x}from"./workflow.js";export*from"./steps/index.js";export{o as Base,f as CallableRegistry,m as InstanceState,s as State,x as Workflow};
1
+ export*from"./events/index.js";import{default as r}from"./base.js";import{default as f}from"./callable_registry.js";import{default as m}from"./state.js";import{InstanceState as s}from"./instance_state.js";import{default as d}from"./workflow.js";export*from"./steps/index.js";export{r as Base,f as CallableRegistry,s as InstanceState,m as State,d as Workflow};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/classes/index.js"],
4
- "sourcesContent": ["export * from './events/index.js';\nexport { default as Base } from './base.js';\nexport { default as CallableRegistry } from './callable_registry.js';\nexport { default as State, InstanceState } from './state.js';\nexport { default as Workflow } from './workflow.js';\nexport * from './steps/index.js';\n"],
5
- "mappings": "AAAA,WAAc,oBACd,OAAoB,WAAXA,MAAuB,YAChC,OAAoB,WAAXA,MAAmC,yBAC5C,OAAoB,WAAXA,EAAkB,iBAAAC,MAAqB,aAChD,OAAoB,WAAXD,MAA2B,gBACpC,WAAc",
4
+ "sourcesContent": ["export * from './events/index.js';\nexport { default as Base } from './base.js';\nexport { default as CallableRegistry } from './callable_registry.js';\nexport { default as State } from './state.js';\nexport { InstanceState } from './instance_state.js';\nexport { default as Workflow } from './workflow.js';\nexport * from './steps/index.js';\n"],
5
+ "mappings": "AAAA,WAAc,oBACd,OAAoB,WAAXA,MAAuB,YAChC,OAAoB,WAAXA,MAAmC,yBAC5C,OAAoB,WAAXA,MAAwB,aACjC,OAAS,iBAAAC,MAAqB,sBAC9B,OAAoB,WAAXD,MAA2B,gBACpC,WAAc",
6
6
  "names": ["default", "InstanceState"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ var w=Object.defineProperty;var a=(n,t)=>w(n,"name",{value:t,configurable:!0});import{errors as i,warnings as _}from"../enums/errors.js";import{StepEvent as y,WorkflowEvent as m,StateEvent as d}from"./events/index.js";import{base_types as g,conditional_step_comparators as b,state_event_names as P,step_event_names as A,step_statuses as E,step_types as j,sub_step_types as x,workflow_event_names as O,workflow_statuses as S}from"../enums/index.js";function p(n){const t=n.match(/[^.[\]]+|(?<=\[)([^\]]+)(?=\])/g);return t?t.map(r=>r.replace(/^['"]|['"]$/g,"")):[]}a(p,"parsePath");function f(n,t){const r=p(t);let e=n;for(const o of r)if(e&&Object.prototype.hasOwnProperty.call(e,o))e=e[o];else return;return e}a(f,"getAtPath");function l(n,t,r){const e=p(t);let o=n;for(let s=0;s<e.length-1;s++){const c=e[s],h=e[s+1];if(!Object.prototype.hasOwnProperty.call(o,c)||typeof o[c]!="object"){const u=/^\d+$/.test(h);o[c]=u?[]:{}}o=o[c]}o[e[e.length-1]]=r}a(l,"setAtPath");function T(n,t){const r=p(t);let e=n;for(let o=0;o<r.length-1;o++){const s=r[o];if(!Object.prototype.hasOwnProperty.call(e,s)||typeof e[s]!="object")return;e=e[s]}delete e[r[r.length-1]]}a(T,"deleteAtPath");function k(n,t){if(!t)return n;try{switch(t){case"string":return String(n);case"number":return Number(n);case"boolean":return!!n;default:return n}}catch(r){return console.error("Error converting state value: ",r),n}}a(k,"convertType");const B={errors:i,warnings:_},D={workflow:S,step:E},H={workflow:O,step:A,state:P},$={workflow:new m,step:new y,state:new d},F={base_types:g,step_types:j,sub_step_types:x};class R{static{a(this,"InstanceState")}constructor(t={}){this.data=t}get(t,r=null,e=null){if(!t||["*",""].includes(t))return this.data??r;const o=f(this.data,t)??r;return k(o,e)??r}set(t,r){if(!t)throw new Error(i.INVALID_STATE_PATH);l(this.data,t,r)}getStateFromPropertyPath(t){return f(this.data,t)}parseStatePath(t){return p(t)}setStateToPropertyPath(t,r){l(this.data,t,r)}delete(t){if(!t)throw new Error(i.INVALID_STATE_PATH);T(this.data,t)}merge(t){return this.data={...this.data,...t},this.data}async each(t,r){const e=this.get(t);if(Array.isArray(e))for(const[o,s]of e.entries())await r(s,o);else if(typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]")for(const o of Object.keys(e))await r(e[o],o);else throw new Error(i.VALUE_NOT_ITERABLE)}}export{R as InstanceState,b as conditional_step_comparators,H as event_names,$ as events,B as messages,D as statuses,F as types};
2
+ //# sourceMappingURL=instance_state.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/classes/instance_state.js"],
4
+ "sourcesContent": ["import { errors, warnings } from '../enums/errors.js';\nimport { StepEvent, WorkflowEvent, StateEvent } from './events/index.js';\nimport {\n base_types,\n conditional_step_comparators,\n state_event_names,\n step_event_names,\n step_statuses,\n step_types,\n sub_step_types,\n workflow_event_names,\n workflow_statuses,\n} from '../enums/index.js';\n\n/**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation.\n *\n * @param {string} path - The path to parse (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @returns {string[]} Array of property keys.\n */\nfunction parsePath(path) {\n const matches = path.match(/[^.[\\]]+|(?<=\\[)([^\\]]+)(?=\\])/g);\n\n if (!matches) {\n return [];\n }\n\n return matches.map(part => part.replace(/^['\"]|['\"]$/g, ''));\n}\n\n/**\n * Resolves a nested property path within an arbitrary object.\n * @param {Object} target - The object to read from.\n * @param {string} path - The path to the property.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\nfunction getAtPath(target, path) {\n const parts = parsePath(path);\n let current = target;\n\n for (const part of parts) {\n if (current && Object.prototype.hasOwnProperty.call(current, part)) {\n current = current[part];\n } else {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Sets a nested property value within an arbitrary object based on a path.\n * Creates intermediate objects/arrays as needed.\n * @param {Object} target - The object to write to.\n * @param {string} path - The path to the property.\n * @param {*} value - The value to set at the specified path.\n */\nfunction setAtPath(target, path, value) {\n const parts = parsePath(path);\n let current = target;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const next_part = parts[i + 1];\n\n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n const is_next_part_numeric = /^\\d+$/.test(next_part);\n current[part] = is_next_part_numeric ? [] : {};\n }\n current = current[part];\n }\n\n current[parts[parts.length - 1]] = value;\n}\n\n/**\n * Deletes a property from an arbitrary object using a path.\n * @param {Object} target - The object to delete from.\n * @param {string} path - The path of the property to delete.\n */\nfunction deleteAtPath(target, path) {\n const parts = parsePath(path);\n let current = target;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n\n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n return;\n }\n\n current = current[part];\n }\n\n delete current[parts[parts.length - 1]];\n}\n\n/**\n * Converts a resolved state value to the requested output type.\n * @param {*} value - The value to convert.\n * @param {string|null} type - One of \"string\", \"number\", \"boolean\".\n * @returns {*} The converted value, or the original value if conversion fails or type is unrecognized.\n */\nfunction convertType(value, type) {\n if (!type) {\n return value;\n }\n\n try {\n switch (type) {\n case 'string':\n return String(value);\n case 'number':\n return Number(value);\n case 'boolean':\n return Boolean(value);\n default:\n return value;\n }\n } catch (error) {\n console.error('Error converting state value: ', error);\n return value;\n }\n}\n\n/**\n * Framework constants, built once here as the single canonical source. `Workflow` (see\n * `workflow.js`) assigns these as its own static members - the public surface library\n * consumers should reach them through - while step classes that need one directly may import\n * the named export straight from this module instead of going through `Workflow` (avoiding an\n * import cycle). The deprecated `State` singleton (`state.js`) also builds its `default_state`\n * from these same values, so the `events.*` instances stay identical (by reference) regardless\n * of whether a given `Workflow`/`Step` has opted into `use_state_singleton` - listeners\n * registered via `State.get('events.workflow')` keep receiving events either way.\n */\nexport const messages = { errors, warnings };\nexport const statuses = { workflow: workflow_statuses, step: step_statuses };\nexport const event_names = { workflow: workflow_event_names, step: step_event_names, state: state_event_names };\nexport const events = { workflow: new WorkflowEvent(), step: new StepEvent(), state: new StateEvent() };\nexport const types = { base_types, step_types, sub_step_types };\nexport { conditional_step_comparators };\n\n/**\n * Per-instance replacement for the deprecated `State` singleton. Each `Workflow` owns one of\n * these (created in its constructor), and shares it with every `Step` added to it, so that\n * `getState()`/`setState()`/`deleteState()` calls made anywhere in that workflow's tree read and\n * write the same, workflow-scoped data instead of a single process-wide object. A `Workflow`\n * registers itself under the `workflow` key of its own `InstanceState` (see\n * `initializeWorkflowState()` in `workflow.js`), so `getState('workflow')` resolves to the live\n * owning `Workflow` instance; any other path is arbitrary user data set via `setState()`.\n *\n * Supports the same dot-notation/bracket-notation path access as `State`.\n *\n * @class InstanceState\n */\nexport class InstanceState {\n /**\n * Creates a new InstanceState.\n * @param {Object} [initial={}] - Initial data.\n */\n constructor(initial = {}) {\n this.data = initial;\n }\n\n /**\n * Gets the value of a state property using dot-notation or bracket-notation path access.\n * @param {string} path - The path of the state property to get. Falsy values, or \"*\", return the entire state.\n * @param {*} [defaultValue=null] - Default value to return if the path doesn't exist.\n * @param {string|null} [type=null] - The output type to convert the value to (\"string\", \"number\", \"boolean\").\n * @returns {*} The value of the state property, or defaultValue if not found.\n */\n get(path, defaultValue = null, type = null) {\n if (!path || ['*', ''].includes(path)) {\n return this.data ?? defaultValue;\n }\n\n const gotten = getAtPath(this.data, path) ?? defaultValue;\n\n return convertType(gotten, type) ?? defaultValue;\n }\n\n /**\n * Sets the value of a state property using dot-notation or bracket-notation path access.\n * Creates intermediate objects if they don't exist.\n * @param {string} path - The path of the state property to set.\n * @param {*} value - The value to set for the state property.\n * @throws {Error} Throws if path is empty or invalid.\n */\n set(path, value) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n setAtPath(this.data, path, value);\n }\n\n /**\n * Resolves a nested property path within this instance's data. Low-level counterpart to\n * `get()` - unlike `get()`, a falsy/`'*'` path is not special-cased to mean \"entire state\".\n * @param {string} path - The path to the property.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\n getStateFromPropertyPath(path) {\n return getAtPath(this.data, path);\n }\n\n /**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation.\n * @param {string} path - The path to parse.\n * @returns {string[]} Array of property keys.\n */\n parseStatePath(path) {\n return parsePath(path);\n }\n\n /**\n * Sets a nested property value within this instance's data based on a path. Low-level\n * counterpart to `set()` - unlike `set()`, does not throw on an empty path.\n * @param {string} path - The path to the property.\n * @param {*} value - The value to set at the specified path.\n */\n setStateToPropertyPath(path, value) {\n setAtPath(this.data, path, value);\n }\n\n /**\n * Deletes a state property using dot-notation or bracket-notation path access.\n * @param {string} path - The path of the state property to delete.\n * @throws {Error} Throws if path is empty or invalid.\n */\n delete(path) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n deleteAtPath(this.data, path);\n }\n\n /**\n * Merges an object into the current instance state.\n * @param {Object} newState - The object to merge in.\n * @returns {Object} The updated state data.\n */\n merge(newState) {\n this.data = { ...this.data, ...newState };\n return this.data;\n }\n\n /**\n * Iterates over a collection (array or object) located at the specified path,\n * executing a callback function for each item.\n * @param {string} path - The path of the property to iterate over.\n * @param {Function} callback - The function to execute for each item in the collection.\n * @throws {Error} Throws if the value at the path is not an array or object.\n */\n async each(path, callback) {\n const collection = this.get(path);\n\n if (Array.isArray(collection)) {\n for (const [index, item] of collection.entries()) {\n await callback(item, index);\n }\n } else if (\n typeof collection === 'object' &&\n Object.prototype.toString.call(collection) === '[object Object]'\n ) {\n for (const key of Object.keys(collection)) {\n await callback(collection[key], key);\n }\n } else {\n throw new Error(errors.VALUE_NOT_ITERABLE);\n }\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAS,UAAAA,EAAQ,YAAAC,MAAgB,qBACjC,OAAS,aAAAC,EAAW,iBAAAC,EAAe,cAAAC,MAAkB,oBACrD,OACE,cAAAC,EACA,gCAAAC,EACA,qBAAAC,EACA,oBAAAC,EACA,iBAAAC,EACA,cAAAC,EACA,kBAAAC,EACA,wBAAAC,EACA,qBAAAC,MACK,oBASP,SAASC,EAAUC,EAAM,CACvB,MAAMC,EAAUD,EAAK,MAAM,iCAAiC,EAE5D,OAAKC,EAIEA,EAAQ,IAAIC,GAAQA,EAAK,QAAQ,eAAgB,EAAE,CAAC,EAHlD,CAAC,CAIZ,CARSC,EAAAJ,EAAA,aAgBT,SAASK,EAAUC,EAAQL,EAAM,CAC/B,MAAMM,EAAQP,EAAUC,CAAI,EAC5B,IAAIO,EAAUF,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Aa,KAAK,KAAMb,CAAI,CAC9B,CAOA,MAAM0B,EAAU,CACd,YAAK,KAAO,CAAE,GAAG,KAAK,KAAM,GAAGA,CAAS,EACjC,KAAK,IACd,CASA,MAAM,KAAK1B,EAAM2B,EAAU,CACzB,MAAMC,EAAa,KAAK,IAAI5B,CAAI,EAEhC,GAAI,MAAM,QAAQ4B,CAAU,EAC1B,SAAW,CAACC,EAAOC,CAAI,IAAKF,EAAW,QAAQ,EAC7C,MAAMD,EAASG,EAAMD,CAAK,UAG5B,OAAOD,GAAe,UACtB,OAAO,UAAU,SAAS,KAAKA,CAAU,IAAM,kBAE/C,UAAWG,KAAO,OAAO,KAAKH,CAAU,EACtC,MAAMD,EAASC,EAAWG,CAAG,EAAGA,CAAG,MAGrC,OAAM,IAAI,MAAM9C,EAAO,kBAAkB,CAE7C,CACF",
6
+ "names": ["errors", "warnings", "StepEvent", "WorkflowEvent", "StateEvent", "base_types", "conditional_step_comparators", "state_event_names", "step_event_names", "step_statuses", "step_types", "sub_step_types", "workflow_event_names", "workflow_statuses", "parsePath", "path", "matches", "part", "__name", "getAtPath", "target", "parts", "current", "setAtPath", "value", "i", "next_part", "is_next_part_numeric", "deleteAtPath", "convertType", "type", "error", "messages", "statuses", "event_names", "events", "types", "InstanceState", "initial", "defaultValue", "gotten", "newState", "callback", "collection", "index", "item", "key"]
7
+ }
@@ -1,2 +1,2 @@
1
- var P=Object.defineProperty;var l=(a,t)=>P(a,"name",{value:t,configurable:!0});import{errors as m,warnings as T}from"../enums/errors.js";import{StepEvent as b,WorkflowEvent as d,StateEvent as A}from"./events/index.js";import{base_types as O,conditional_step_comparators as j,state_event_names as v,step_event_names as k,step_statuses as S,step_types as I,sub_step_types as R,workflow_event_names as x,workflow_statuses as L}from"../enums/index.js";const f={messages:{errors:m,warnings:T},statuses:{workflow:L,step:S},event_names:{workflow:x,step:k,state:v},events:{workflow:new d,step:new b,state:new A},types:{base_types:O,step_types:I,sub_step_types:R},workflows:{},conditional_step_comparators:j};let n={...f};const c=n.events,i=n.event_names;function _(a){const t=a.match(/[^.[\]]+|(?<=\[)([^\]]+)(?=\])/g);return t?t.map(s=>s.replace(/^['"]|['"]$/g,"")):[]}l(_,"parsePath");function y(a,t){const s=_(t);let r=a;for(const e of s)if(r&&Object.prototype.hasOwnProperty.call(r,e))r=r[e];else return;return r}l(y,"getAtPath");function E(a,t,s){const r=_(t);let e=a;for(let o=0;o<r.length-1;o++){const p=r[o],h=r[o+1];if(!Object.prototype.hasOwnProperty.call(e,p)||typeof e[p]!="object"){const w=/^\d+$/.test(h);e[p]=w?[]:{}}e=e[p]}e[r[r.length-1]]=s}l(E,"setAtPath");function N(a,t){const s=_(t);let r=a;for(let e=0;e<s.length-1;e++){const o=s[e];if(!Object.prototype.hasOwnProperty.call(r,o)||typeof r[o]!="object")return;r=r[o]}delete r[s[s.length-1]]}l(N,"deleteAtPath");function H(a,t){if(!t)return a;try{switch(t){case"string":return String(a);case"number":return Number(a);case"boolean":return!!a;default:return a}}catch(s){return console.error("Error converting state value: ",s),a}}l(H,"convertType");function D(){return{messages:f.messages,statuses:f.statuses,event_names:f.event_names,events:f.events,types:f.types,conditional_step_comparators:f.conditional_step_comparators,workflows:{}}}l(D,"createInstanceStateData");class z{static{l(this,"InstanceState")}constructor(t=D()){this.data=t}get(t,s=null,r=null){if(!t||["*",""].includes(t))return this.data??s;const e=y(this.data,t)??s;return H(e,r)??s}set(t,s){if(!t)throw new Error(m.INVALID_STATE_PATH);E(this.data,t,s)}getStateFromPropertyPath(t){return y(this.data,t)}parseStatePath(t){return _(t)}setStateToPropertyPath(t,s){E(this.data,t,s)}delete(t){if(!t)throw new Error(m.INVALID_STATE_PATH);N(this.data,t)}merge(t){return this.data={...this.data,...t},this.data}async each(t,s){const r=this.get(t);if(Array.isArray(r))for(const[e,o]of r.entries())await s(o,e);else if(typeof r=="object"&&Object.prototype.toString.call(r)==="[object Object]")for(const e of Object.keys(r))await s(r[e],e);else throw new Error(m.VALUE_NOT_ITERABLE)}}class u{static{l(this,"State")}static delete(t){if(!t)throw new Error(m.INVALID_STATE_PATH);const s=u.parsePath(t);let r=n;for(let e=0;e<s.length-1;e++){const o=s[e];if(!Object.prototype.hasOwnProperty.call(r,o)||typeof r[o]!="object")return;r=r[o]}delete r[s[s.length-1]],c.state.emit(i.state.DELETED,{state:n})}static async each(t,s){const r=u.get(t);if(Array.isArray(r))for(const[e,o]of r.entries())c.state.emit(i.state.EACH,{state:n}),await s(o,e);else if(typeof r=="object"&&Object.prototype.toString.call(r)==="[object Object]")for(const e of Object.keys(r))c.state.emit(i.state.EACH,{state:n}),await s(r[e],e);else throw new Error(m.VALUE_NOT_ITERABLE)}static freeze(){const t=Object.freeze(n);return c.state.emit(i.state.FROZEN,{state:n}),t}static get(t,s=null,r=null){let e=n;if(!t||["*",""].includes(t))return c.state.emit(i.state.GET,{state:e??s}),e;if(e=u.getFromPropertyPath(t,!1)??s,r)try{switch(r){case"string":e=String(e);break;case"number":e=Number(e);break;case"boolean":e=!!e;break;default:break}}catch(o){console.error("Error converting state value: ",o)}return c.state.emit(i.state.GET,{state:e}),e??s}static getFromPropertyPath(t,s=!0){const r=u.parsePath(t);let e=n;for(const o of r)if(e&&Object.prototype.hasOwnProperty.call(e,o))e=e[o];else return;return s&&c.state.emit(i.state.GET_FROM_PROPERTY_PATH,{state:n}),e}static getState(){return c.state.emit(i.state.GET_STATE,{state:n}),n}static merge(t){return n={...n,...t},c.state.emit(i.state.MERGE,{state:n}),n}static parsePath(t){const s=t.match(/[^.[\]]+|(?<=\[)([^\]]+)(?=\])/g);return s?s.map(r=>r.replace(/^['"]|['"]$/g,"")):[]}static reset(){return n={...f,workflows:{}},c.state.emit(i.state.RESET,{state:n}),n}static set(t,s){if(!t)throw new Error(m.INVALID_STATE_PATH);c.state.emit(i.state.SET,{state:n}),u.setToPropertyPath(t,s,!1)}static setToPropertyPath(t,s,r=!0){const e=u.parsePath(t);let o=n;for(let p=0;p<e.length-1;p++){const h=e[p],w=e[p+1];if(!Object.prototype.hasOwnProperty.call(o,h)||typeof o[h]!="object"){const g=/^\d+$/.test(w);o[h]=g?[]:{}}o=o[h]}r&&c.state.emit(i.state.SET_TO_PROPERTY_PATH,{state:n}),o[e[e.length-1]]=s}}var C=u;export{z as InstanceState,D as createInstanceStateData,C as default};
1
+ var y=Object.defineProperty;var m=(T,e)=>y(T,"name",{value:e,configurable:!0});import{errors as p}from"../enums/errors.js";import{messages as h,statuses as g,event_names as n,events as c,types as b,conditional_step_comparators as w}from"./instance_state.js";const E={messages:h,statuses:g,event_names:n,events:c,types:b,workflows:{},conditional_step_comparators:w};let s={...E};class i{static{m(this,"State")}static delete(e){if(!e)throw new Error(p.INVALID_STATE_PATH);const a=i.parsePath(e);let r=s;for(let t=0;t<a.length-1;t++){const o=a[t];if(!Object.prototype.hasOwnProperty.call(r,o)||typeof r[o]!="object")return;r=r[o]}delete r[a[a.length-1]],c.state.emit(n.state.DELETED,{state:s})}static async each(e,a){const r=i.get(e);if(Array.isArray(r))for(const[t,o]of r.entries())c.state.emit(n.state.EACH,{state:s}),await a(o,t);else if(typeof r=="object"&&Object.prototype.toString.call(r)==="[object Object]")for(const t of Object.keys(r))c.state.emit(n.state.EACH,{state:s}),await a(r[t],t);else throw new Error(p.VALUE_NOT_ITERABLE)}static freeze(){const e=Object.freeze(s);return c.state.emit(n.state.FROZEN,{state:s}),e}static get(e,a=null,r=null){let t=s;if(!e||["*",""].includes(e))return c.state.emit(n.state.GET,{state:t??a}),t;if(t=i.getFromPropertyPath(e,!1)??a,r)try{switch(r){case"string":t=String(t);break;case"number":t=Number(t);break;case"boolean":t=!!t;break;default:break}}catch(o){console.error("Error converting state value: ",o)}return c.state.emit(n.state.GET,{state:t}),t??a}static getFromPropertyPath(e,a=!0){const r=i.parsePath(e);let t=s;for(const o of r)if(t&&Object.prototype.hasOwnProperty.call(t,o))t=t[o];else return;return a&&c.state.emit(n.state.GET_FROM_PROPERTY_PATH,{state:s}),t}static getState(){return c.state.emit(n.state.GET_STATE,{state:s}),s}static merge(e){return s={...s,...e},c.state.emit(n.state.MERGE,{state:s}),s}static parsePath(e){const a=e.match(/[^.[\]]+|(?<=\[)([^\]]+)(?=\])/g);return a?a.map(r=>r.replace(/^['"]|['"]$/g,"")):[]}static reset(){return s={...E,workflows:{}},c.state.emit(n.state.RESET,{state:s}),s}static set(e,a){if(!e)throw new Error(p.INVALID_STATE_PATH);c.state.emit(n.state.SET,{state:s}),i.setToPropertyPath(e,a,!1)}static setToPropertyPath(e,a,r=!0){const t=i.parsePath(e);let o=s;for(let l=0;l<t.length-1;l++){const f=t[l],u=t[l+1];if(!Object.prototype.hasOwnProperty.call(o,f)||typeof o[f]!="object"){const P=/^\d+$/.test(u);o[f]=P?[]:{}}o=o[f]}r&&c.state.emit(n.state.SET_TO_PROPERTY_PATH,{state:s}),o[t[t.length-1]]=a}}var j=i;export{j as default,E as default_state};
2
2
  //# sourceMappingURL=state.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/classes/state.js"],
4
- "sourcesContent": ["import { errors, warnings } from '../enums/errors.js';\nimport { StepEvent, WorkflowEvent, StateEvent } from './events/index.js';\nimport {\n base_types,\n conditional_step_comparators,\n state_event_names,\n step_event_names,\n step_statuses,\n step_types,\n sub_step_types,\n workflow_event_names,\n workflow_statuses,\n} from '../enums/index.js';\n\nconst default_state = {\n messages: {\n errors,\n warnings,\n },\n statuses: {\n workflow: workflow_statuses,\n step: step_statuses\n },\n event_names: {\n workflow: workflow_event_names,\n step: step_event_names,\n state: state_event_names,\n },\n events: {\n workflow: new WorkflowEvent(),\n step: new StepEvent(),\n state: new StateEvent(),\n },\n types: {\n base_types,\n step_types,\n sub_step_types,\n },\n workflows: {},\n conditional_step_comparators\n};\n\nlet state = { ...default_state };\n\n// Module-level shortcuts for events and event_names\nconst events = state.events;\nconst event_names = state.event_names;\n\n/**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation. Shared by both the deprecated singleton `State` and per-instance\n * `InstanceState`.\n *\n * @param {string} path - The path to parse (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @returns {string[]} Array of property keys.\n */\nfunction parsePath(path) {\n const matches = path.match(/[^.[\\]]+|(?<=\\[)([^\\]]+)(?=\\])/g);\n\n if (!matches) {\n return [];\n }\n\n return matches.map(part => part.replace(/^['\"]|['\"]$/g, ''));\n}\n\n/**\n * Resolves a nested property path within an arbitrary object.\n * @param {Object} target - The object to read from.\n * @param {string} path - The path to the property.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\nfunction getAtPath(target, path) {\n const parts = parsePath(path);\n let current = target;\n\n for (const part of parts) {\n if (current && Object.prototype.hasOwnProperty.call(current, part)) {\n current = current[part];\n } else {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Sets a nested property value within an arbitrary object based on a path.\n * Creates intermediate objects/arrays as needed.\n * @param {Object} target - The object to write to.\n * @param {string} path - The path to the property.\n * @param {*} value - The value to set at the specified path.\n */\nfunction setAtPath(target, path, value) {\n const parts = parsePath(path);\n let current = target;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const next_part = parts[i + 1];\n\n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n const is_next_part_numeric = /^\\d+$/.test(next_part);\n current[part] = is_next_part_numeric ? [] : {};\n }\n current = current[part];\n }\n\n current[parts[parts.length - 1]] = value;\n}\n\n/**\n * Deletes a property from an arbitrary object using a path.\n * @param {Object} target - The object to delete from.\n * @param {string} path - The path of the property to delete.\n */\nfunction deleteAtPath(target, path) {\n const parts = parsePath(path);\n let current = target;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n\n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n return;\n }\n\n current = current[part];\n }\n\n delete current[parts[parts.length - 1]];\n}\n\n/**\n * Converts a resolved state value to the requested output type.\n * @param {*} value - The value to convert.\n * @param {string|null} type - One of \"string\", \"number\", \"boolean\".\n * @returns {*} The converted value, or the original value if conversion fails or type is unrecognized.\n */\nfunction convertType(value, type) {\n if (!type) {\n return value;\n }\n\n try {\n switch (type) {\n case 'string':\n return String(value);\n case 'number':\n return Number(value);\n case 'boolean':\n return Boolean(value);\n default:\n return value;\n }\n } catch (error) {\n console.error('Error converting state value: ', error);\n return value;\n }\n}\n\n/**\n * Builds a fresh data object for a `Workflow`/`Step` instance's own state, seeded with the\n * same framework constants (statuses, event enums, event emitters, comparators) the deprecated\n * `State` singleton used to provide - but with its own independent, empty `workflows` registry\n * rather than sharing the process-wide one.\n *\n * The event emitters (and other constant objects) are shared by reference with the singleton's\n * defaults so that `on()`/`off()` listeners registered via `State.get('events.workflow')` keep\n * receiving events regardless of whether a given `Workflow`/`Step` has opted back into\n * `use_state_singleton`.\n *\n * @returns {Object} A fresh instance-state data object.\n */\nexport function createInstanceStateData() {\n return {\n messages: default_state.messages,\n statuses: default_state.statuses,\n event_names: default_state.event_names,\n events: default_state.events,\n types: default_state.types,\n conditional_step_comparators: default_state.conditional_step_comparators,\n workflows: {},\n };\n}\n\n/**\n * Per-instance replacement for the deprecated `State` singleton. Each `Workflow` owns one of\n * these (created in its constructor), and shares it with every `Step` added to it, so that\n * `getState()`/`setState()`/`deleteState()` calls made anywhere in that workflow's tree read and\n * write the same, workflow-scoped data instead of a single process-wide object.\n *\n * Supports the same dot-notation/bracket-notation path access as `State`.\n *\n * @class InstanceState\n */\nexport class InstanceState {\n /**\n * Creates a new InstanceState.\n * @param {Object} [initial] - Initial data, defaults to a fresh `createInstanceStateData()` result.\n */\n constructor(initial = createInstanceStateData()) {\n this.data = initial;\n }\n\n /**\n * Gets the value of a state property using dot-notation or bracket-notation path access.\n * @param {string} path - The path of the state property to get. Falsy values, or \"*\", return the entire state.\n * @param {*} [defaultValue=null] - Default value to return if the path doesn't exist.\n * @param {string|null} [type=null] - The output type to convert the value to (\"string\", \"number\", \"boolean\").\n * @returns {*} The value of the state property, or defaultValue if not found.\n */\n get(path, defaultValue = null, type = null) {\n if (!path || ['*', ''].includes(path)) {\n return this.data ?? defaultValue;\n }\n\n const gotten = getAtPath(this.data, path) ?? defaultValue;\n\n return convertType(gotten, type) ?? defaultValue;\n }\n\n /**\n * Sets the value of a state property using dot-notation or bracket-notation path access.\n * Creates intermediate objects if they don't exist.\n * @param {string} path - The path of the state property to set.\n * @param {*} value - The value to set for the state property.\n * @throws {Error} Throws if path is empty or invalid.\n */\n set(path, value) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n setAtPath(this.data, path, value);\n }\n\n /**\n * Resolves a nested property path within this instance's data. Low-level counterpart to\n * `get()` - unlike `get()`, a falsy/`'*'` path is not special-cased to mean \"entire state\".\n * @param {string} path - The path to the property.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\n getStateFromPropertyPath(path) {\n return getAtPath(this.data, path);\n }\n\n /**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation.\n * @param {string} path - The path to parse.\n * @returns {string[]} Array of property keys.\n */\n parseStatePath(path) {\n return parsePath(path);\n }\n\n /**\n * Sets a nested property value within this instance's data based on a path. Low-level\n * counterpart to `set()` - unlike `set()`, does not throw on an empty path.\n * @param {string} path - The path to the property.\n * @param {*} value - The value to set at the specified path.\n */\n setStateToPropertyPath(path, value) {\n setAtPath(this.data, path, value);\n }\n\n /**\n * Deletes a state property using dot-notation or bracket-notation path access.\n * @param {string} path - The path of the state property to delete.\n * @throws {Error} Throws if path is empty or invalid.\n */\n delete(path) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n deleteAtPath(this.data, path);\n }\n\n /**\n * Merges an object into the current instance state.\n * @param {Object} newState - The object to merge in.\n * @returns {Object} The updated state data.\n */\n merge(newState) {\n this.data = { ...this.data, ...newState };\n return this.data;\n }\n\n /**\n * Iterates over a collection (array or object) located at the specified path,\n * executing a callback function for each item.\n * @param {string} path - The path of the property to iterate over.\n * @param {Function} callback - The function to execute for each item in the collection.\n * @throws {Error} Throws if the value at the path is not an array or object.\n */\n async each(path, callback) {\n const collection = this.get(path);\n\n if (Array.isArray(collection)) {\n for (const [index, item] of collection.entries()) {\n await callback(item, index);\n }\n } else if (\n typeof collection === 'object' &&\n Object.prototype.toString.call(collection) === '[object Object]'\n ) {\n for (const key of Object.keys(collection)) {\n await callback(collection[key], key);\n }\n } else {\n throw new Error(errors.VALUE_NOT_ITERABLE);\n }\n }\n}\n\n/**\n * Singleton class representing the global state for workflows, steps, and processes.\n * Provides methods for managing state with getter/setter functionality, nested path access,\n * and immutability options. The state is shared across all workflow and step instances.\n * \n * @class State\n */\nclass State {\n /**\n * Deletes a state property using dot-notation or bracket-notation path access.\n * \n * @param {string} path - The path of the state property to delete (e.g., \"user.profile.email\" or \"users[0].email\").\n * @returns {void}\n * @throws {Error} Throws if path is empty or invalid.\n */\n static delete(path) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n \n const parts = State.parsePath(path);\n let current = state;\n \n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n \n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n return;\n }\n \n current = current[part];\n }\n \n delete current[parts[parts.length - 1]];\n\n events.state.emit(event_names.state.DELETED, { state });\n }\n\n /**\n * Iterates over a collection (array or object) located at the specified state path,\n * executing a callback function for each item.\n * \n * @param {string} path - The path of the state property to iterate over.\n * @param {Function} callback - The function to execute for each item in the collection.\n * @throws {Error} Throws if the state property at the path is not an array or object.\n */\n static async each(path, callback) {\n const collection = State.get(path);\n \n if (Array.isArray(collection)) {\n for (const [index, item] of collection.entries()) {\n events.state.emit(event_names.state.EACH, { state });\n await callback(item, index);\n }\n } else if (\n typeof collection === 'object' &&\n Object.prototype.toString.call(collection) === '[object Object]'\n ) {\n for (const key of Object.keys(collection)) {\n events.state.emit(event_names.state.EACH, { state });\n await callback(collection[key], key);\n }\n } else {\n throw new Error(errors.VALUE_NOT_ITERABLE);\n }\n }\n\n /**\n * Freezes the entire state object, making it immutable.\n * @returns {void}\n */\n static freeze() {\n const frozen_state = Object.freeze(state);\n events.state.emit(event_names.state.FROZEN, { state });\n return frozen_state;\n }\n\n /**\n * Gets the value of a state property using dot-notation or bracket-notation path access.\n * \n * @param {string} path - The path of the state property to get. Supports both dot notation\n * (e.g., \"user.profile.name\") and bracket notation (e.g., \"users[0].name\" or \"data['key-name']\").\n * Special values:\n * - Falsy values (null, undefined, false, \"\"): Returns entire state object\n * - \"*\": Returns entire state object\n * @param {*} [defaultValue=null] - Default value to return if the path doesn't exist.\n * @param {string} [type='string'] - The output type to convert the value to.\n * Supported types: \"string\", \"number\", \"boolean\".\n * @returns {*} The value of the state property, or defaultValue if not found. null if not found\n * and no defaultValue provided.\n * @throws {Error} Throws if the value cannot be converted to the specified type.\n */\n static get(path, defaultValue = null, type = null) {\n let gotten = state;\n if (!path || ['*', ''].includes(path)) {\n events.state.emit(event_names.state.GET, { state: gotten ?? defaultValue });\n return gotten;\n }\n\n gotten = State.getFromPropertyPath(path, false) ?? defaultValue;\n\n if (type) {\n try {\n switch (type) {\n case 'string':\n gotten = String(gotten);\n break;\n case 'number':\n gotten = Number(gotten);\n break;\n case 'boolean':\n gotten = Boolean(gotten);\n break;\n default:\n break;\n }\n } catch (error) {\n console.error(\"Error converting state value: \", error);\n }\n }\n\n events.state.emit(event_names.state.GET, { state: gotten });\n\n return gotten ?? defaultValue;\n }\n\n /**\n * Resolves a nested property path within the state object.\n * Supports both dot notation and bracket notation.\n * \n * @param {string} path - The path to the property (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @param {boolean} [emit=true] - Whether to emit the GET_FROM_PROPERTY_PATH event.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\n static getFromPropertyPath(path, emit = true) {\n const parts = State.parsePath(path);\n let current = state;\n\n for (const part of parts) {\n if (current && Object.prototype.hasOwnProperty.call(current, part)) {\n current = current[part];\n } else {\n return undefined;\n }\n }\n\n if (emit) {\n events.state.emit(event_names.state.GET_FROM_PROPERTY_PATH, { state });\n }\n\n return current;\n }\n\n /**\n * Gets the entire state object.\n * @returns {Object} The entire state object.\n */\n static getState() {\n events.state.emit(event_names.state.GET_STATE, { state });\n return state;\n }\n\n /**\n * Merges an object into the current State.\n * @param {Object} newState - The object to merge into the current State.\n * @returns {object} The updated state object.\n */\n static merge(newState) {\n state = { ...state, ...newState };\n events.state.emit(event_names.state.MERGE, { state });\n return state;\n }\n\n /**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation.\n * \n * @param {string} path - The path to parse (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @returns {string[]} Array of property keys.\n */\n static parsePath(path) {\n const matches = path.match(/[^.[\\]]+|(?<=\\[)([^\\]]+)(?=\\])/g);\n \n if (!matches) {\n return [];\n }\n\n return matches.map(part => part.replace(/^['\"]|['\"]$/g, ''));\n }\n\n /**\n * Resets the state to its default values.\n * @returns {object} The reset state object.\n */\n static reset() {\n state = { \n ...default_state,\n workflows: {}, // Always create fresh to avoid shared reference mutation\n };\n events.state.emit(event_names.state.RESET, { state });\n return state;\n }\n\n /**\n * Sets the value of a state property using dot-notation or bracket-notation path access.\n * Creates intermediate objects if they don't exist.\n * \n * @param {string} path - The path of the state property to set. Supports both dot notation\n * (e.g., \"user.profile.name\") and bracket notation (e.g., \"users[0].name\" or \"data['key-name']\").\n * @param {*} value - The value to set for the state property.\n * @returns {void}\n * @throws {Error} Throws if path is empty or invalid.\n */\n static set(path, value) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n events.state.emit(event_names.state.SET, { state });\n\n State.setToPropertyPath(path, value, false);\n }\n\n /**\n * Sets a nested property value within the state object based on a path.\n * Supports both dot notation and bracket notation. Creates intermediate objects/arrays as needed.\n * \n * @param {string} path - The path to the property (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @param {*} value - The value to set at the specified path.\n * @param {boolean} [emit=true] - Whether to emit the SET_TO_PROPERTY_PATH event.\n */\n static setToPropertyPath(path, value, emit = true) {\n const parts = State.parsePath(path);\n let current = state;\n \n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const next_part = parts[i + 1];\n \n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n // Determine if next part is an array index (numeric)\n const is_next_part_numeric = /^\\d+$/.test(next_part);\n current[part] = is_next_part_numeric ? [] : {};\n }\n current = current[part];\n }\n \n if (emit) {\n events.state.emit(event_names.state.SET_TO_PROPERTY_PATH, { state });\n }\n\n current[parts[parts.length - 1]] = value;\n }\n}\n\nexport default State;\n"],
5
- "mappings": "+EAAA,OAAS,UAAAA,EAAQ,YAAAC,MAAgB,qBACjC,OAAS,aAAAC,EAAW,iBAAAC,EAAe,cAAAC,MAAkB,oBACrD,OACE,cAAAC,EACA,gCAAAC,EACA,qBAAAC,EACA,oBAAAC,EACA,iBAAAC,EACA,cAAAC,EACA,kBAAAC,EACA,wBAAAC,EACA,qBAAAC,MACK,oBAEP,MAAMC,EAAgB,CACpB,SAAU,CACR,OAAAd,EACA,SAAAC,CACF,EACA,SAAU,CACR,SAAUY,EACV,KAAMJ,CACR,EACA,YAAa,CACX,SAAUG,EACV,KAAMJ,EACN,MAAOD,CACT,EACA,OAAQ,CACN,SAAU,IAAIJ,EACd,KAAM,IAAID,EACV,MAAO,IAAIE,CACb,EACA,MAAO,CACL,WAAAC,EACA,WAAAK,EACA,eAAAC,CACF,EACA,UAAW,CAAC,EACZ,6BAAAL,CACF,EAEA,IAAIS,EAAQ,CAAE,GAAGD,CAAc,EAG/B,MAAME,EAASD,EAAM,OACfE,EAAcF,EAAM,YAU1B,SAASG,EAAUC,EAAM,CACvB,MAAMC,EAAUD,EAAK,MAAM,iCAAiC,EAE5D,OAAKC,EAIEA,EAAQ,IAAIC,GAAQA,EAAK,QAAQ,eAAgB,EAAE,CAAC,EAHlD,CAAC,CAIZ,CARSC,EAAAJ,EAAA,aAgBT,SAASK,EAAUC,E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,CAAC,OAAO,UAAU,eAAe,KAAKH,EAASL,CAAI,GAAK,OAAOK,EAAQL,CAAI,GAAM,SAAU,CAE7F,MAAMU,EAAuB,QAAQ,KAAKD,CAAS,EACnDJ,EAAQL,CAAI,EAAIU,EAAuB,CAAC,EAAI,CAAC,CAC/C,CACAL,EAAUA,EAAQL,CAAI,CACxB,CAEI4B,GACFjC,EAAO,MAAM,KAAKC,EAAY,MAAM,qBAAsB,CAAE,MAAAF,CAAM,CAAC,EAGrEW,EAAQD,EAAMA,EAAM,OAAS,CAAC,CAAC,EAAIG,CACrC,CACF,CAEA,IAAOsB,EAAQH",
6
- "names": ["errors", "warnings", "StepEvent", "WorkflowEvent", "StateEvent", "base_types", "conditional_step_comparators", "state_event_names", "step_event_names", "step_statuses", "step_types", "sub_step_types", "workflow_event_names", "workflow_statuses", "default_state", "state", "events", "event_names", "parsePath", "path", "matches", "part", "__name", "getAtPath", "target", "parts", "current", "setAtPath", "value", "i", "next_part", "is_next_part_numeric", "deleteAtPath", "convertType", "type", "error", "createInstanceStateData", "InstanceState", "initial", "defaultValue", "gotten", "newState", "callback", "collection", "index", "item", "key", "State", "frozen_state", "emit", "state_default"]
4
+ "sourcesContent": ["import { errors } from '../enums/errors.js';\nimport { messages, statuses, event_names, events, types, conditional_step_comparators } from './instance_state.js';\n\n// Built from the same constants `Workflow` exposes as static members (see instance_state.js),\n// so `events.*` stays the same instance regardless of whether a given Workflow/Step has opted\n// into `use_state_singleton`. Only `workflows` is singleton-only - it was never meant to be\n// copied into per-instance state.\nexport const default_state = {\n messages,\n statuses,\n event_names,\n events,\n types,\n workflows: {},\n conditional_step_comparators,\n};\n\nlet state = { ...default_state };\n\n/**\n * Singleton class representing the global state for workflows, steps, and processes.\n * Provides methods for managing state with getter/setter functionality, nested path access,\n * and immutability options. The state is shared across all workflow and step instances.\n * \n * @class State\n */\nclass State {\n /**\n * Deletes a state property using dot-notation or bracket-notation path access.\n * \n * @param {string} path - The path of the state property to delete (e.g., \"user.profile.email\" or \"users[0].email\").\n * @returns {void}\n * @throws {Error} Throws if path is empty or invalid.\n */\n static delete(path) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n \n const parts = State.parsePath(path);\n let current = state;\n \n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n \n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n return;\n }\n \n current = current[part];\n }\n \n delete current[parts[parts.length - 1]];\n\n events.state.emit(event_names.state.DELETED, { state });\n }\n\n /**\n * Iterates over a collection (array or object) located at the specified state path,\n * executing a callback function for each item.\n * \n * @param {string} path - The path of the state property to iterate over.\n * @param {Function} callback - The function to execute for each item in the collection.\n * @throws {Error} Throws if the state property at the path is not an array or object.\n */\n static async each(path, callback) {\n const collection = State.get(path);\n \n if (Array.isArray(collection)) {\n for (const [index, item] of collection.entries()) {\n events.state.emit(event_names.state.EACH, { state });\n await callback(item, index);\n }\n } else if (\n typeof collection === 'object' &&\n Object.prototype.toString.call(collection) === '[object Object]'\n ) {\n for (const key of Object.keys(collection)) {\n events.state.emit(event_names.state.EACH, { state });\n await callback(collection[key], key);\n }\n } else {\n throw new Error(errors.VALUE_NOT_ITERABLE);\n }\n }\n\n /**\n * Freezes the entire state object, making it immutable.\n * @returns {void}\n */\n static freeze() {\n const frozen_state = Object.freeze(state);\n events.state.emit(event_names.state.FROZEN, { state });\n return frozen_state;\n }\n\n /**\n * Gets the value of a state property using dot-notation or bracket-notation path access.\n * \n * @param {string} path - The path of the state property to get. Supports both dot notation\n * (e.g., \"user.profile.name\") and bracket notation (e.g., \"users[0].name\" or \"data['key-name']\").\n * Special values:\n * - Falsy values (null, undefined, false, \"\"): Returns entire state object\n * - \"*\": Returns entire state object\n * @param {*} [defaultValue=null] - Default value to return if the path doesn't exist.\n * @param {string} [type='string'] - The output type to convert the value to.\n * Supported types: \"string\", \"number\", \"boolean\".\n * @returns {*} The value of the state property, or defaultValue if not found. null if not found\n * and no defaultValue provided.\n * @throws {Error} Throws if the value cannot be converted to the specified type.\n */\n static get(path, defaultValue = null, type = null) {\n let gotten = state;\n if (!path || ['*', ''].includes(path)) {\n events.state.emit(event_names.state.GET, { state: gotten ?? defaultValue });\n return gotten;\n }\n\n gotten = State.getFromPropertyPath(path, false) ?? defaultValue;\n\n if (type) {\n try {\n switch (type) {\n case 'string':\n gotten = String(gotten);\n break;\n case 'number':\n gotten = Number(gotten);\n break;\n case 'boolean':\n gotten = Boolean(gotten);\n break;\n default:\n break;\n }\n } catch (error) {\n console.error(\"Error converting state value: \", error);\n }\n }\n\n events.state.emit(event_names.state.GET, { state: gotten });\n\n return gotten ?? defaultValue;\n }\n\n /**\n * Resolves a nested property path within the state object.\n * Supports both dot notation and bracket notation.\n * \n * @param {string} path - The path to the property (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @param {boolean} [emit=true] - Whether to emit the GET_FROM_PROPERTY_PATH event.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\n static getFromPropertyPath(path, emit = true) {\n const parts = State.parsePath(path);\n let current = state;\n\n for (const part of parts) {\n if (current && Object.prototype.hasOwnProperty.call(current, part)) {\n current = current[part];\n } else {\n return undefined;\n }\n }\n\n if (emit) {\n events.state.emit(event_names.state.GET_FROM_PROPERTY_PATH, { state });\n }\n\n return current;\n }\n\n /**\n * Gets the entire state object.\n * @returns {Object} The entire state object.\n */\n static getState() {\n events.state.emit(event_names.state.GET_STATE, { state });\n return state;\n }\n\n /**\n * Merges an object into the current State.\n * @param {Object} newState - The object to merge into the current State.\n * @returns {object} The updated state object.\n */\n static merge(newState) {\n state = { ...state, ...newState };\n events.state.emit(event_names.state.MERGE, { state });\n return state;\n }\n\n /**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation.\n * \n * @param {string} path - The path to parse (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @returns {string[]} Array of property keys.\n */\n static parsePath(path) {\n const matches = path.match(/[^.[\\]]+|(?<=\\[)([^\\]]+)(?=\\])/g);\n \n if (!matches) {\n return [];\n }\n\n return matches.map(part => part.replace(/^['\"]|['\"]$/g, ''));\n }\n\n /**\n * Resets the state to its default values.\n * @returns {object} The reset state object.\n */\n static reset() {\n state = { \n ...default_state,\n workflows: {}, // Always create fresh to avoid shared reference mutation\n };\n events.state.emit(event_names.state.RESET, { state });\n return state;\n }\n\n /**\n * Sets the value of a state property using dot-notation or bracket-notation path access.\n * Creates intermediate objects if they don't exist.\n * \n * @param {string} path - The path of the state property to set. Supports both dot notation\n * (e.g., \"user.profile.name\") and bracket notation (e.g., \"users[0].name\" or \"data['key-name']\").\n * @param {*} value - The value to set for the state property.\n * @returns {void}\n * @throws {Error} Throws if path is empty or invalid.\n */\n static set(path, value) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n events.state.emit(event_names.state.SET, { state });\n\n State.setToPropertyPath(path, value, false);\n }\n\n /**\n * Sets a nested property value within the state object based on a path.\n * Supports both dot notation and bracket notation. Creates intermediate objects/arrays as needed.\n * \n * @param {string} path - The path to the property (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @param {*} value - The value to set at the specified path.\n * @param {boolean} [emit=true] - Whether to emit the SET_TO_PROPERTY_PATH event.\n */\n static setToPropertyPath(path, value, emit = true) {\n const parts = State.parsePath(path);\n let current = state;\n \n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const next_part = parts[i + 1];\n \n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n // Determine if next part is an array index (numeric)\n const is_next_part_numeric = /^\\d+$/.test(next_part);\n current[part] = is_next_part_numeric ? [] : {};\n }\n current = current[part];\n }\n \n if (emit) {\n events.state.emit(event_names.state.SET_TO_PROPERTY_PATH, { state });\n }\n\n current[parts[parts.length - 1]] = value;\n }\n}\n\nexport default State;\n"],
5
+ "mappings": "+EAAA,OAAS,UAAAA,MAAc,qBACvB,OAAS,YAAAC,EAAU,YAAAC,EAAU,eAAA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AK,CAAM,CAAC,EAGrEK,EAAQD,EAAMA,EAAM,OAAS,CAAC,CAAC,EAAIiB,CACrC,CACF,CAEA,IAAOG,EAAQvB",
6
+ "names": ["errors", "messages", "statuses", "event_names", "events", "types", "conditional_step_comparators", "default_state", "state", "State", "__name", "path", "parts", "current", "i", "part", "callback", "collection", "index", "item", "key", "frozen_state", "defaultValue", "type", "gotten", "error", "emit", "newState", "matches", "value", "next_part", "is_next_part_numeric", "state_default"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var c=Object.defineProperty;var i=(n,e)=>c(n,"name",{value:e,configurable:!0});import s from"./step.js";import u from"./logic_step.js";import"../../enums/index.js";class r extends u{static{i(this,"ConditionalStep")}static step_name="conditional";constructor({name:e,conditional:l={subject:null,operator:null,value:null},true_callable:t=i(async()=>{},"true_callable"),false_callable:a=i(async()=>{},"false_callable"),true_callable_registry_key:_=null,false_callable_registry_key:o=null}){super({name:e,conditional:l}),this.true_callable_registry_key=_,this.false_callable_registry_key=o,this._true_callable_raw=t,this._false_callable_raw=a,typeof t=="function"?this.true_callable=t.bind(this):this.true_callable=t,typeof a=="function"?this.false_callable=a.bind(this):this.false_callable=a,this.callable=this.conditional.bind(this)}async conditional(){const e=this.true_callable,l=this.false_callable;let t=null;return this.checkCondition()?(this.log(this.getState("events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED"),`Condition met for step: ${this.name}, executing true branch`),typeof e=="function"?t=await e():(e.parent_workflow_id=this.parent_workflow_id,e.use_state_singleton=this.use_state_singleton,e.state=this.state,t=await e.execute())):(this.log(this.getState("events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED"),`Condition not met for step: ${this.name}, executing false branch`),typeof l=="function"?t=await l():(l.parent_workflow_id=this.parent_workflow_id,l.use_state_singleton=this.use_state_singleton,l.state=this.state,t=await l.execute())),{message:`Conditional step ${this.name} completed`,result:t}}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,true_callable:this.true_callable_registry_key?{type:s.callable_types.FUNCTION,value:this.true_callable_registry_key}:s.serializeCallableField(this._true_callable_raw),false_callable:this.false_callable_registry_key?{type:s.callable_types.FUNCTION,value:this.false_callable_registry_key}:s.serializeCallableField(this._false_callable_raw)}}static hydrate(e,l=null){const t=e.true_callable,a=e.false_callable;return super.hydrate({...e,true_callable:s.hydrateCallableField(t,l),false_callable:s.hydrateCallableField(a,l),true_callable_registry_key:t?.type===s.callable_types.FUNCTION?t.value:null,false_callable_registry_key:a?.type===s.callable_types.FUNCTION?a.value:null},l)}}r.registerStepClass(r);export{r as default};
1
+ var u=Object.defineProperty;var i=(n,e)=>u(n,"name",{value:e,configurable:!0});import s from"./step.js";import h from"./logic_step.js";import"../../enums/index.js";import{event_names as _}from"../instance_state.js";class r extends h{static{i(this,"ConditionalStep")}static step_name="conditional";constructor({name:e,conditional:t={subject:null,operator:null,value:null},true_callable:l=i(async()=>{},"true_callable"),false_callable:a=i(async()=>{},"false_callable"),true_callable_registry_key:o=null,false_callable_registry_key:c=null}){super({name:e,conditional:t}),this.true_callable_registry_key=o,this.false_callable_registry_key=c,this._true_callable_raw=l,this._false_callable_raw=a,typeof l=="function"?this.true_callable=l.bind(this):this.true_callable=l,typeof a=="function"?this.false_callable=a.bind(this):this.false_callable=a,this.callable=this.conditional.bind(this)}async conditional(){const e=this.true_callable,t=this.false_callable;let l=null;return this.checkCondition()?(this.log(_.step.CONDITIONAL_TRUE_BRANCH_EXECUTED,`Condition met for step: ${this.name}, executing true branch`),typeof e=="function"?l=await e():(e.parent_workflow_id=this.parent_workflow_id,e.use_state_singleton=this.use_state_singleton,e.state=this.state,l=await e.execute())):(this.log(_.step.CONDITIONAL_FALSE_BRANCH_EXECUTED,`Condition not met for step: ${this.name}, executing false branch`),typeof t=="function"?l=await t():(t.parent_workflow_id=this.parent_workflow_id,t.use_state_singleton=this.use_state_singleton,t.state=this.state,l=await t.execute())),{message:`Conditional step ${this.name} completed`,result:l}}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,true_callable:this.true_callable_registry_key?{type:s.callable_types.FUNCTION,value:this.true_callable_registry_key}:s.serializeCallableField(this._true_callable_raw),false_callable:this.false_callable_registry_key?{type:s.callable_types.FUNCTION,value:this.false_callable_registry_key}:s.serializeCallableField(this._false_callable_raw)}}static hydrate(e,t=null){const l=e.true_callable,a=e.false_callable;return super.hydrate({...e,true_callable:s.hydrateCallableField(l,t),false_callable:s.hydrateCallableField(a,t),true_callable_registry_key:l?.type===s.callable_types.FUNCTION?l.value:null,false_callable_registry_key:a?.type===s.callable_types.FUNCTION?a.value:null},t)}}r.registerStepClass(r);export{r as default};
2
2
  //# sourceMappingURL=conditional_step.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/conditional_step.js"],
4
- "sourcesContent": ["import Step from './step.js';\nimport LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * ConditionalStep class for branching logic based on conditions.\n * @class ConditionalStep\n * @extends LogicStep\n */\nexport default class ConditionalStep extends LogicStep {\n static step_name = 'conditional';\n\n /**\n * Creates a new ConditionalStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {Function|Step|Workflow} [options.true_callable=async () => {}] - Callable to execute if condition is true.\n * @param {Function|Step|Workflow} [options.false_callable=async () => {}] - Callable to execute if condition is false.\n * @param {string|null} [options.true_callable_registry_key=null] - Optional key to reference true_callable to be rehydrated after serialization.\n * @param {string|null} [options.false_callable_registry_key=null] - Optional key to reference false_callable to be rehydrated after serialization.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n true_callable = async () => {},\n false_callable = async () => {},\n true_callable_registry_key = null,\n false_callable_registry_key = null,\n }) {\n super({\n name,\n conditional\n });\n\n // Optional keys to reference true_callable/false_callable to be rehydrated after serialization.\n this.true_callable_registry_key = true_callable_registry_key;\n this.false_callable_registry_key = false_callable_registry_key;\n\n // Keep the raw (unbound) originals for serialization - binding renames a function\n // (e.g. \"falseBranch\" -> \"bound falseBranch\"), which would break registry lookups on hydrate.\n this._true_callable_raw = true_callable;\n this._false_callable_raw = false_callable;\n\n // Bind function callables to this step instance for state access\n if (typeof true_callable === 'function') {\n this.true_callable = true_callable.bind(this);\n } else {\n this.true_callable = true_callable;\n }\n\n if (typeof false_callable === 'function') {\n this.false_callable = false_callable.bind(this);\n } else {\n this.false_callable = false_callable;\n }\n\n this.callable = this.conditional.bind(this);\n }\n\n /**\n * Executes the appropriate branch based on the condition evaluation. When the executed branch\n * is a `Step`/`Workflow` (not a plain function), it is stamped with this step's own\n * `parent_workflow_id`/`use_state_singleton`/`state` first - true/false_callable are never\n * added to the parent workflow via `addStep()`, so this is the only way they end up sharing\n * its state instead of their own, independent one.\n * @async\n * @returns {Promise<*>} The result of the executed branch.\n */\n async conditional() {\n const true_callable = this.true_callable;\n const false_callable = this.false_callable;\n\n let result = null;\n\n if (this.checkCondition()) {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED'),\n `Condition met for step: ${this.name}, executing true branch`\n );\n\n if (typeof true_callable === 'function') {\n result = await true_callable();\n } else {\n true_callable.parent_workflow_id = this.parent_workflow_id;\n true_callable.use_state_singleton = this.use_state_singleton;\n true_callable.state = this.state;\n result = await true_callable.execute();\n }\n } else {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED'),\n `Condition not met for step: ${this.name}, executing false branch`\n );\n\n if (typeof false_callable === 'function') {\n result = await false_callable();\n } else {\n false_callable.parent_workflow_id = this.parent_workflow_id;\n false_callable.use_state_singleton = this.use_state_singleton;\n false_callable.state = this.state;\n result = await false_callable.execute();\n }\n }\n\n return { message: `Conditional step ${this.name} completed`, result };\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n // The base `callable` is an internal wiring detail (the bound `conditional` method) -\n // ConditionalStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n true_callable: this.true_callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.true_callable_registry_key }\n : Step.serializeCallableField(this._true_callable_raw),\n false_callable: this.false_callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.false_callable_registry_key }\n : Step.serializeCallableField(this._false_callable_raw),\n };\n }\n\n /**\n * Hydrates a parsed step object into a ConditionalStep instance, resolving the true/false branch callables.\n * @param {Object} parsed_step - The parsed step object.\n * @param {import('../callable_registry.js').default|null} [callable_registry] - Registry used to resolve function callables.\n * @returns {ConditionalStep} The hydrated ConditionalStep instance.\n */\n static hydrate(parsed_step, callable_registry = null) {\n const true_descriptor = parsed_step.true_callable;\n const false_descriptor = parsed_step.false_callable;\n\n return super.hydrate({\n ...parsed_step,\n true_callable: Step.hydrateCallableField(true_descriptor, callable_registry),\n false_callable: Step.hydrateCallableField(false_descriptor, callable_registry),\n true_callable_registry_key: true_descriptor?.type === Step.callable_types.FUNCTION\n ? true_descriptor.value\n : null,\n false_callable_registry_key: false_descriptor?.type === Step.callable_types.FUNCTION\n ? false_descriptor.value\n : null,\n }, callable_registry);\n }\n}\n\nConditionalStep.registerStepClass(ConditionalStep);\n"],
5
- "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAOC,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAAsCD,CAAU,CATvD,MASuD,CAAAE,EAAA,wBACrD,OAAO,UAAY,cAenB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,cAAAC,EAAgBH,EAAA,SAAY,CAAC,EAAb,iBAChB,e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O,KAAK,0BAA2B,EAC7EA,EAAK,uBAAuB,KAAK,kBAAkB,EACvD,eAAgB,KAAK,4BACjB,CAAE,KAAMA,EAAK,eAAe,SAAU,MAAO,KAAK,2BAA4B,EAC9EA,EAAK,uBAAuB,KAAK,mBAAmB,CAC1D,CACF,CAQA,OAAO,QAAQW,EAAaC,EAAoB,KAAM,CACpD,MAAMC,EAAkBF,EAAY,cAC9BG,EAAmBH,EAAY,eAErC,OAAO,MAAM,QAAQ,CACnB,GAAGA,EACH,cAAeX,EAAK,qBAAqBa,EAAiBD,CAAiB,EAC3E,eAAgBZ,EAAK,qBAAqBc,EAAkBF,CAAiB,EAC7E,2BAA4BC,GAAiB,OAASb,EAAK,eAAe,SACtEa,EAAgB,MAChB,KACJ,4BAA6BC,GAAkB,OAASd,EAAK,eAAe,SACxEc,EAAiB,MACjB,IACN,EAAGF,CAAiB,CACtB,CACF,CAEAV,EAAgB,kBAAkBA,CAAe",
6
- "names": ["Step", "LogicStep", "ConditionalStep", "__name", "name", "conditional", "true_callable", "false_callable", "true_callable_registry_key", "false_callable_registry_key", "result", "parsed_step", "callable_registry", "true_descriptor", "false_descriptor"]
4
+ "sourcesContent": ["import Step from './step.js';\nimport LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\nimport { event_names } from '../instance_state.js';\n\n/**\n * ConditionalStep class for branching logic based on conditions.\n * @class ConditionalStep\n * @extends LogicStep\n */\nexport default class ConditionalStep extends LogicStep {\n static step_name = 'conditional';\n\n /**\n * Creates a new ConditionalStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {Function|Step|Workflow} [options.true_callable=async () => {}] - Callable to execute if condition is true.\n * @param {Function|Step|Workflow} [options.false_callable=async () => {}] - Callable to execute if condition is false.\n * @param {string|null} [options.true_callable_registry_key=null] - Optional key to reference true_callable to be rehydrated after serialization.\n * @param {string|null} [options.false_callable_registry_key=null] - Optional key to reference false_callable to be rehydrated after serialization.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n true_callable = async () => {},\n false_callable = async () => {},\n true_callable_registry_key = null,\n false_callable_registry_key = null,\n }) {\n super({\n name,\n conditional\n });\n\n // Optional keys to reference true_callable/false_callable to be rehydrated after serialization.\n this.true_callable_registry_key = true_callable_registry_key;\n this.false_callable_registry_key = false_callable_registry_key;\n\n // Keep the raw (unbound) originals for serialization - binding renames a function\n // (e.g. \"falseBranch\" -> \"bound falseBranch\"), which would break registry lookups on hydrate.\n this._true_callable_raw = true_callable;\n this._false_callable_raw = false_callable;\n\n // Bind function callables to this step instance for state access\n if (typeof true_callable === 'function') {\n this.true_callable = true_callable.bind(this);\n } else {\n this.true_callable = true_callable;\n }\n\n if (typeof false_callable === 'function') {\n this.false_callable = false_callable.bind(this);\n } else {\n this.false_callable = false_callable;\n }\n\n this.callable = this.conditional.bind(this);\n }\n\n /**\n * Executes the appropriate branch based on the condition evaluation. When the executed branch\n * is a `Step`/`Workflow` (not a plain function), it is stamped with this step's own\n * `parent_workflow_id`/`use_state_singleton`/`state` first - true/false_callable are never\n * added to the parent workflow via `addStep()`, so this is the only way they end up sharing\n * its state instead of their own, independent one.\n * @async\n * @returns {Promise<*>} The result of the executed branch.\n */\n async conditional() {\n const true_callable = this.true_callable;\n const false_callable = this.false_callable;\n\n let result = null;\n\n if (this.checkCondition()) {\n this.log(\n event_names.step.CONDITIONAL_TRUE_BRANCH_EXECUTED,\n `Condition met for step: ${this.name}, executing true branch`\n );\n\n if (typeof true_callable === 'function') {\n result = await true_callable();\n } else {\n true_callable.parent_workflow_id = this.parent_workflow_id;\n true_callable.use_state_singleton = this.use_state_singleton;\n true_callable.state = this.state;\n result = await true_callable.execute();\n }\n } else {\n this.log(\n event_names.step.CONDITIONAL_FALSE_BRANCH_EXECUTED,\n `Condition not met for step: ${this.name}, executing false branch`\n );\n\n if (typeof false_callable === 'function') {\n result = await false_callable();\n } else {\n false_callable.parent_workflow_id = this.parent_workflow_id;\n false_callable.use_state_singleton = this.use_state_singleton;\n false_callable.state = this.state;\n result = await false_callable.execute();\n }\n }\n\n return { message: `Conditional step ${this.name} completed`, result };\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n // The base `callable` is an internal wiring detail (the bound `conditional` method) -\n // ConditionalStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n true_callable: this.true_callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.true_callable_registry_key }\n : Step.serializeCallableField(this._true_callable_raw),\n false_callable: this.false_callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.false_callable_registry_key }\n : Step.serializeCallableField(this._false_callable_raw),\n };\n }\n\n /**\n * Hydrates a parsed step object into a ConditionalStep instance, resolving the true/false branch callables.\n * @param {Object} parsed_step - The parsed step object.\n * @param {import('../callable_registry.js').default|null} [callable_registry] - Registry used to resolve function callables.\n * @returns {ConditionalStep} The hydrated ConditionalStep instance.\n */\n static hydrate(parsed_step, callable_registry = null) {\n const true_descriptor = parsed_step.true_callable;\n const false_descriptor = parsed_step.false_callable;\n\n return super.hydrate({\n ...parsed_step,\n true_callable: Step.hydrateCallableField(true_descriptor, callable_registry),\n false_callable: Step.hydrateCallableField(false_descriptor, callable_registry),\n true_callable_registry_key: true_descriptor?.type === Step.callable_types.FUNCTION\n ? true_descriptor.value\n : null,\n false_callable_registry_key: false_descriptor?.type === Step.callable_types.FUNCTION\n ? false_descriptor.value\n : null,\n }, callable_registry);\n }\n}\n\nConditionalStep.registerStepClass(ConditionalStep);\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAU,YACj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AAK,oBAC1CA,EAAe,MAAQ,KAAK,MAC5BG,EAAS,MAAMH,EAAe,QAAQ,IAInC,CAAE,QAAS,oBAAoB,KAAK,IAAI,aAAc,OAAAG,CAAO,CACtE,CAMA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EAGjC,SAAU,KACV,cAAe,KAAK,2BAChB,CAAE,KAAMX,EAAK,eAAe,SAAU,MAAO,KAAK,0BAA2B,EAC7EA,EAAK,uBAAuB,KAAK,kBAAkB,EACvD,eAAgB,KAAK,4BACjB,CAAE,KAAMA,EAAK,eAAe,SAAU,MAAO,KAAK,2BAA4B,EAC9EA,EAAK,uBAAuB,KAAK,mBAAmB,CAC1D,CACF,CAQA,OAAO,QAAQY,EAAaC,EAAoB,KAAM,CACpD,MAAMC,EAAkBF,EAAY,cAC9BG,EAAmBH,EAAY,eAErC,OAAO,MAAM,QAAQ,CACnB,GAAGA,EACH,cAAeZ,EAAK,qBAAqBc,EAAiBD,CAAiB,EAC3E,eAAgBb,EAAK,qBAAqBe,EAAkBF,CAAiB,EAC7E,2BAA4BC,GAAiB,OAASd,EAAK,eAAe,SACtEc,EAAgB,MAChB,KACJ,4BAA6BC,GAAkB,OAASf,EAAK,eAAe,SACxEe,EAAiB,MACjB,IACN,EAAGF,CAAiB,CACtB,CACF,CAEAV,EAAgB,kBAAkBA,CAAe",
6
+ "names": ["Step", "LogicStep", "event_names", "ConditionalStep", "__name", "name", "conditional", "true_callable", "false_callable", "true_callable_registry_key", "false_callable_registry_key", "result", "parsed_step", "callable_registry", "true_descriptor", "false_descriptor"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var r=Object.defineProperty;var n=(i,e)=>r(i,"name",{value:e,configurable:!0});import p from"./step.js";import{delay_types as o,step_types as _}from"../../enums/index.js";import y from"node-schedule";import{addMilliseconds as m}from"date-fns";class a extends p{static{n(this,"DelayStep")}static step_name="delay";constructor({name:e,absolute_timestamp:t=new Date,relative_delay_ms:s=0,delay_type:l=o.RELATIVE}){super({name:e,step_type:_.DELAY}),this.delay_type=l,this.absolute_timestamp=new Date(t),this.relative_delay_ms=s,this.callable=this[l].bind(this)}async absolute(){const e=new Date;return this.absolute_timestamp.getTime()<=e.getTime()?(this.log(this.getState("events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:e.toISOString()}):this.delay(this.absolute_timestamp)}async delay(e){return new Promise(t=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`),`Delay scheduled for step: ${this.name} until ${e.toISOString()}`);const s=y.scheduleJob(e,()=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`),`Delay complete for step: ${this.name}. Continuing.`),t({delayed:!0,delay_type:this.delay_type,timestamp:new Date().toISOString()})});this.scheduled_job=s})}async relative(){if(this.relative_delay_ms<=0)return this.log(this.getState("events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:new Date().toISOString()};const e=m(new Date,this.relative_delay_ms);return this.delay(e)}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,delay_type:this.delay_type,absolute_timestamp:this.absolute_timestamp,relative_delay_ms:this.relative_delay_ms}}}a.registerStepClass(a);export{a as default};
1
+ var p=Object.defineProperty;var o=(l,e)=>p(l,"name",{value:e,configurable:!0});import n from"./step.js";import{delay_types as y,step_types as _}from"../../enums/index.js";import{event_names as t}from"../instance_state.js";import m from"node-schedule";import{addMilliseconds as d}from"date-fns";class i extends n{static{o(this,"DelayStep")}static step_name="delay";constructor({name:e,absolute_timestamp:s=new Date,relative_delay_ms:a=0,delay_type:r=y.RELATIVE}){super({name:e,step_type:_.DELAY}),this.delay_type=r,this.absolute_timestamp=new Date(s),this.relative_delay_ms=a,this.callable=this[r].bind(this)}async absolute(){const e=new Date;return this.absolute_timestamp.getTime()<=e.getTime()?(this.log(t.step.DELAY_STEP_ABSOLUTE_COMPLETE,`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:e.toISOString()}):this.delay(this.absolute_timestamp)}async delay(e){return new Promise(s=>{this.log(t.step[`DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`],`Delay scheduled for step: ${this.name} until ${e.toISOString()}`);const a=m.scheduleJob(e,()=>{this.log(t.step[`DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`],`Delay complete for step: ${this.name}. Continuing.`),s({delayed:!0,delay_type:this.delay_type,timestamp:new Date().toISOString()})});this.scheduled_job=a})}async relative(){if(this.relative_delay_ms<=0)return this.log(t.step.DELAY_STEP_RELATIVE_COMPLETE,`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:new Date().toISOString()};const e=d(new Date,this.relative_delay_ms);return this.delay(e)}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,delay_type:this.delay_type,absolute_timestamp:this.absolute_timestamp,relative_delay_ms:this.relative_delay_ms}}}i.registerStepClass(i);export{i as default};
2
2
  //# sourceMappingURL=delay_step.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/delay_step.js"],
4
- "sourcesContent": ["import Step from './step.js';\nimport { delay_types, step_types } from '../../enums/index.js';\nimport schedule from 'node-schedule';\nimport { addMilliseconds } from 'date-fns';\n\n/**\n * DelayStep class for introducing delays in workflow execution.\n * Supports both absolute and relative delays.\n * @class DelayStep\n * @extends Step\n */\nexport default class DelayStep extends Step {\n static step_name = 'delay';\n\n /**\n * Creates a new DelayStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Date|string} [options.absolute_timestamp=new Date()] - Absolute timestamp to delay until.\n * @param {number} [options.relative_delay_ms=0] - Relative delay in milliseconds.\n * @param {string} [options.delay_type=delay_types.RELATIVE] - Type of delay ('absolute' or 'relative').\n */\n constructor({\n name,\n absolute_timestamp = new Date(),\n relative_delay_ms = 0,\n delay_type = delay_types.RELATIVE\n }) {\n super({\n name,\n step_type: step_types.DELAY,\n });\n\n this.delay_type = delay_type;\n this.absolute_timestamp = new Date(absolute_timestamp);\n this.relative_delay_ms = relative_delay_ms;\n\n this.callable = this[delay_type].bind(this);\n }\n\n /**\n * Executes an absolute delay until the specified timestamp. If the timestamp is in the past, it continues immediately.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async absolute() {\n const now = new Date();\n\n if (this.absolute_timestamp.getTime() <= now.getTime()) {\n this.log(\n this.getState('events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE'),\n `No delay for step: ${this.name}. Continuing.`\n );\n return { delayed: false, delay_type: this.delay_type, timestamp: now.toISOString() };\n }\n\n return this.delay(this.absolute_timestamp);\n }\n\n /** Schedules a delay until the specified date and time.\n * @param {Date} delay_until - The date and time to delay until.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async delay(delay_until) {\n return new Promise((resolve) => {\n this.log(\n this.getState(\n `events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`\n ),\n `Delay scheduled for step: ${this.name} until ${delay_until.toISOString()}`\n );\n\n const job = schedule.scheduleJob(delay_until, () => {\n this.log(\n this.getState(\n `events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`\n ),\n `Delay complete for step: ${this.name}. Continuing.`\n );\n resolve({ delayed: true, delay_type: this.delay_type, timestamp: new Date().toISOString() });\n });\n\n this.scheduled_job = job;\n });\n }\n\n /**\n * Executes a relative delay for the specified duration. If the delay duration is zero or negative, it continues immediately.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async relative() {\n if (this.relative_delay_ms <= 0) {\n this.log(\n this.getState('events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE'),\n `No delay for step: ${this.name}. Continuing.`\n );\n return { delayed: false, delay_type: this.delay_type, timestamp: new Date().toISOString() };\n }\n\n const delay_until = addMilliseconds(new Date(), this.relative_delay_ms);\n\n return this.delay(delay_until);\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n // The base `callable` is an internal wiring detail (the bound absolute/relative method) -\n // DelayStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n delay_type: this.delay_type,\n absolute_timestamp: this.absolute_timestamp,\n relative_delay_ms: this.relative_delay_ms,\n };\n }\n}\n\nDelayStep.registerStepClass(DelayStep);\n"],
5
- "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAS,eAAAC,EAAa,cAAAC,MAAkB,uBACxC,OAAOC,MAAc,gBACrB,OAAS,mBAAAC,MAAuB,WAQhC,MAAOC,UAAgCL,CAAK,CAX5C,MAW4C,CAAAM,EAAA,kBAC1C,OAAO,UAAY,QAUnB,YAAY,CACV,KAAAC,EACA,mBAAAC,EAAqB,IAAI,KACzB,kBAAAC,EAAoB,EACpB,WAAAC,EAAaT,EAAY,QAC3B,EAAG,CACD,MAAM,CACJ,KAAAM,EACA,UAAWL,EAAW,KACxB,CAAC,EAED,KAAK,WAAaQ,EAClB,KAAK,mBAAqB,IAAI,KAAKF,CAAkB,EACrD,KAAK,kBAAoBC,EAEzB,KAAK,SAAW,KAAKC,CAAU,EAAE,KAAK,IAAI,CAC5C,CAMA,MAAM,UAAW,CACf,MAAMC,EAAM,IAAI,KAEhB,OAAI,KAAK,mBAAmB,QAAQ,GAAKA,EAAI,QAAQ,GACnD,KAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAWA,EAAI,YAAY,CAAE,GAG9E,KAAK,MAAM,KAAK,kBAAkB,CAC3C,CAMA,MAAM,MAAMC,EAAa,CACvB,OAAO,IAAI,QAASC,GAAY,CAC9B,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,YACrE,EACA,6BAA6B,KAAK,IAAI,UAAUD,EAAY,YAAY,CAAC,EAC3E,EAEA,MAAME,EAAMX,EAAS,YAAYS,EAAa,IAAM,CAClD,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,WACrE,EACA,4BAA4B,KAAK,IAAI,eACvC,EACAC,EAAQ,CAAE,QAAS,GAAM,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,CAAC,CAC7F,CAAC,EAED,KAAK,cAAgBC,CACvB,CAAC,CACH,CAMA,MAAM,UAAW,CACf,GAAI,KAAK,mBAAqB,EAC5B,YAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,EAG5F,MAAMF,EAAcR,EAAgB,IAAI,KAAQ,KAAK,iBAAiB,EAEtE,OAAO,KAAK,MAAMQ,CAAW,CAC/B,CAMA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EAGjC,SAAU,KACV,WAAY,KAAK,WACjB,mBAAoB,KAAK,mBACzB,kBAAmB,KAAK,iBAC1B,CACF,CACF,CAEAP,EAAU,kBAAkBA,CAAS",
6
- "names": ["Step", "delay_types", "step_types", "schedule", "addMilliseconds", "DelayStep", "__name", "name", "absolute_timestamp", "relative_delay_ms", "delay_type", "now", "delay_until", "resolve", "job"]
4
+ "sourcesContent": ["import Step from './step.js';\nimport { delay_types, step_types } from '../../enums/index.js';\nimport { event_names } from '../instance_state.js';\nimport schedule from 'node-schedule';\nimport { addMilliseconds } from 'date-fns';\n\n/**\n * DelayStep class for introducing delays in workflow execution.\n * Supports both absolute and relative delays.\n * @class DelayStep\n * @extends Step\n */\nexport default class DelayStep extends Step {\n static step_name = 'delay';\n\n /**\n * Creates a new DelayStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Date|string} [options.absolute_timestamp=new Date()] - Absolute timestamp to delay until.\n * @param {number} [options.relative_delay_ms=0] - Relative delay in milliseconds.\n * @param {string} [options.delay_type=delay_types.RELATIVE] - Type of delay ('absolute' or 'relative').\n */\n constructor({\n name,\n absolute_timestamp = new Date(),\n relative_delay_ms = 0,\n delay_type = delay_types.RELATIVE\n }) {\n super({\n name,\n step_type: step_types.DELAY,\n });\n\n this.delay_type = delay_type;\n this.absolute_timestamp = new Date(absolute_timestamp);\n this.relative_delay_ms = relative_delay_ms;\n\n this.callable = this[delay_type].bind(this);\n }\n\n /**\n * Executes an absolute delay until the specified timestamp. If the timestamp is in the past, it continues immediately.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async absolute() {\n const now = new Date();\n\n if (this.absolute_timestamp.getTime() <= now.getTime()) {\n this.log(\n event_names.step.DELAY_STEP_ABSOLUTE_COMPLETE,\n `No delay for step: ${this.name}. Continuing.`\n );\n return { delayed: false, delay_type: this.delay_type, timestamp: now.toISOString() };\n }\n\n return this.delay(this.absolute_timestamp);\n }\n\n /** Schedules a delay until the specified date and time.\n * @param {Date} delay_until - The date and time to delay until.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async delay(delay_until) {\n return new Promise((resolve) => {\n this.log(\n event_names.step[`DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`],\n `Delay scheduled for step: ${this.name} until ${delay_until.toISOString()}`\n );\n\n const job = schedule.scheduleJob(delay_until, () => {\n this.log(\n event_names.step[`DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`],\n `Delay complete for step: ${this.name}. Continuing.`\n );\n resolve({ delayed: true, delay_type: this.delay_type, timestamp: new Date().toISOString() });\n });\n\n this.scheduled_job = job;\n });\n }\n\n /**\n * Executes a relative delay for the specified duration. If the delay duration is zero or negative, it continues immediately.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async relative() {\n if (this.relative_delay_ms <= 0) {\n this.log(\n event_names.step.DELAY_STEP_RELATIVE_COMPLETE,\n `No delay for step: ${this.name}. Continuing.`\n );\n return { delayed: false, delay_type: this.delay_type, timestamp: new Date().toISOString() };\n }\n\n const delay_until = addMilliseconds(new Date(), this.relative_delay_ms);\n\n return this.delay(delay_until);\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n // The base `callable` is an internal wiring detail (the bound absolute/relative method) -\n // DelayStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n delay_type: this.delay_type,\n absolute_timestamp: this.absolute_timestamp,\n relative_delay_ms: this.relative_delay_ms,\n };\n }\n}\n\nDelayStep.registerStepClass(DelayStep);\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAS,eAAAC,EAAa,cAAAC,MAAkB,uBACxC,OAAS,eAAAC,MAAmB,uBAC5B,OAAOC,MAAc,gBACrB,OAAS,mBAAAC,MAAuB,WAQhC,MAAOC,UAAgCN,CAAK,CAZ5C,MAY4C,CAAAO,EAAA,kBAC1C,OAAO,UAAY,QAUnB,YAAY,CACV,KAAAC,EACA,mBAAAC,EAAqB,IAAI,KACzB,kBAAAC,EAAoB,EACpB,WAAAC,EAAaV,EAAY,QAC3B,EAAG,CACD,MAAM,CACJ,KAAAO,EACA,UAAWN,EAAW,KACxB,CAAC,EAED,KAAK,WAAaS,EAClB,KAAK,mBAAqB,IAAI,KAAKF,CAAkB,EACrD,KAAK,kBAAoBC,EAEzB,KAAK,SAAW,KAAKC,CAAU,EAAE,KAAK,IAAI,CAC5C,CAMA,MAAM,UAAW,CACf,MAAMC,EAAM,IAAI,KAEhB,OAAI,KAAK,mBAAmB,QAAQ,GAAKA,EAAI,QAAQ,GACnD,KAAK,IACHT,EAAY,KAAK,6BACjB,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAWS,EAAI,YAAY,CAAE,GAG9E,KAAK,MAAM,KAAK,kBAAkB,CAC3C,CAMA,MAAM,MAAMC,EAAa,CACvB,OAAO,IAAI,QAASC,GAAY,CAC9B,KAAK,IACHX,EAAY,KAAK,cAAc,KAAK,WAAW,YAAY,CAAC,YAAY,EACxE,6BAA6B,KAAK,IAAI,UAAUU,EAAY,YAAY,CAAC,EAC3E,EAEA,MAAME,EAAMX,EAAS,YAAYS,EAAa,IAAM,CAClD,KAAK,IACHV,EAAY,KAAK,cAAc,KAAK,WAAW,YAAY,CAAC,WAAW,EACvE,4BAA4B,KAAK,IAAI,eACvC,EACAW,EAAQ,CAAE,QAAS,GAAM,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,CAAC,CAC7F,CAAC,EAED,KAAK,cAAgBC,CACvB,CAAC,CACH,CAMA,MAAM,UAAW,CACf,GAAI,KAAK,mBAAqB,EAC5B,YAAK,IACHZ,EAAY,KAAK,6BACjB,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,EAG5F,MAAMU,EAAcR,EAAgB,IAAI,KAAQ,KAAK,iBAAiB,EAEtE,OAAO,KAAK,MAAMQ,CAAW,CAC/B,CAMA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EAGjC,SAAU,KACV,WAAY,KAAK,WACjB,mBAAoB,KAAK,mBACzB,kBAAmB,KAAK,iBAC1B,CACF,CACF,CAEAP,EAAU,kBAAkBA,CAAS",
6
+ "names": ["Step", "delay_types", "step_types", "event_names", "schedule", "addMilliseconds", "DelayStep", "__name", "name", "absolute_timestamp", "relative_delay_ms", "delay_type", "now", "delay_until", "resolve", "job"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var i=Object.defineProperty;var l=(r,t)=>i(r,"name",{value:t,configurable:!0});import a from"./logic_step.js";import s from"../../enums/flow_control_types.js";import"../../enums/index.js";class o extends a{static{l(this,"FlowControlStep")}static step_name="flow_control";constructor({conditional:t={subject:null,operator:null,value:null},name:n,flow_control_type:e=s.BREAK}){if(super({name:n,conditional:t}),!Object.values(s).includes(e))throw new Error(`Invalid flow control type: ${e}`);this.flow_control_type=e,this.callable=this.shouldFlowControl.bind(this)}async shouldFlowControl(){return this.checkCondition()?(this.log(this.getState("events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED"),`Break condition met for step: ${this.name}`),this.setParentWorkflowValue(this.parent_workflow_id,`should_${this.flow_control_type}`,!0),!0):(this.log(this.getState("events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED"),`Break condition not met for step: ${this.name}`),this.setParentWorkflowValue(this.parent_workflow_id,`should_${this.flow_control_type}`,!1),!1)}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,flow_control_type:this.flow_control_type}}}o.registerStepClass(o);export{o as default};
1
+ var a=Object.defineProperty;var l=(r,t)=>a(r,"name",{value:t,configurable:!0});import p from"./logic_step.js";import s from"../../enums/flow_control_types.js";import"../../enums/index.js";import{event_names as i}from"../instance_state.js";class e extends p{static{l(this,"FlowControlStep")}static step_name="flow_control";constructor({conditional:t={subject:null,operator:null,value:null},name:n,flow_control_type:o=s.BREAK}){if(super({name:n,conditional:t}),!Object.values(s).includes(o))throw new Error(`Invalid flow control type: ${o}`);this.flow_control_type=o,this.callable=this.shouldFlowControl.bind(this)}async shouldFlowControl(){return this.checkCondition()?(this.log(i.step.CONDITIONAL_TRUE_BRANCH_EXECUTED,`Break condition met for step: ${this.name}`),this.setParentWorkflowValue(this.parent_workflow_id,`should_${this.flow_control_type}`,!0),!0):(this.log(i.step.CONDITIONAL_FALSE_BRANCH_EXECUTED,`Break condition not met for step: ${this.name}`),this.setParentWorkflowValue(this.parent_workflow_id,`should_${this.flow_control_type}`,!1),!1)}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,flow_control_type:this.flow_control_type}}}e.registerStepClass(e);export{e as default};
2
2
  //# sourceMappingURL=flow_control_step.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/flow_control_step.js"],
4
- "sourcesContent": ["import LogicStep from './logic_step.js';\nimport flow_control_types from '../../enums/flow_control_types.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * FlowControlStep class for controlling workflow execution flow (break or skip).\n * @class FlowControlStep\n * @extends LogicStep\n */\nexport default class FlowControlStep extends LogicStep {\n static step_name = 'flow_control';\n\n /**\n * Creates a new FlowControlStep instance.\n * @param {Object} options - Configuration options.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {string} [options.name] - Name of the step.\n * @param {string} [options.flow_control_type=flow_control_types.BREAK] - Type of flow control.\n * @throws {Error} Throws if flow_control_type is invalid.\n */\n constructor({\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n name,\n flow_control_type = flow_control_types.BREAK,\n }) {\n super({\n name,\n conditional\n });\n\n if (!Object.values(flow_control_types).includes(flow_control_type)) {\n throw new Error(`Invalid flow control type: ${flow_control_type}`);\n }\n\n this.flow_control_type = flow_control_type;\n this.callable = this.shouldFlowControl.bind(this);\n }\n\n /**\n * Evaluates the condition and sets the appropriate flow control flag.\n * @async\n * @returns {Promise<boolean>} True if the flow control should be activated.\n */\n async shouldFlowControl() {\n if (this.checkCondition()) {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED'),\n `Break condition met for step: ${this.name}`\n );\n this.setParentWorkflowValue(this.parent_workflow_id, `should_${this.flow_control_type}`, true);\n\n return true;\n } else {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED'),\n `Break condition not met for step: ${this.name}`\n );\n this.setParentWorkflowValue(this.parent_workflow_id, `should_${this.flow_control_type}`, false);\n\n return false;\n }\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n // The base `callable` is an internal wiring detail (the bound `shouldFlowControl` method) -\n // FlowControlStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n flow_control_type: this.flow_control_type,\n };\n }\n}\n\nFlowControlStep.registerStepClass(FlowControlStep);\n"],
5
- "mappings": "+EAAA,OAAOA,MAAe,kBACtB,OAAOC,MAAwB,oCAC/B,MAA6C,uBAO7C,MAAOC,UAAsCF,CAAU,CATvD,MASuD,CAAAG,EAAA,wBACrD,OAAO,UAAY,eAanB,YAAY,CACV,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,KAAAC,EACA,kBAAAC,EAAoBL,EAAmB,KACzC,EAAG,CAMD,GALA,MAAM,CACJ,KAAAI,EACA,YAAAD,CACF,CAAC,EAEG,CAAC,OAAO,OAAOH,CAAkB,EAAE,SAASK,CAAiB,EAC/D,MAAM,IAAI,MAAM,8BAA8BA,CAAiB,EAAE,EAGnE,KAAK,kBAAoBA,EACzB,KAAK,SAAW,KAAK,kBAAkB,KAAK,IAAI,CAClD,CAOA,MAAM,mBAAoB,CACxB,OAAI,KAAK,eAAe,GACtB,KAAK,IACH,KAAK,SAAS,0DAA0D,EACxE,iCAAiC,KAAK,IAAI,EAC5C,EACA,KAAK,uBAAuB,KAAK,mBAAoB,UAAU,KAAK,iBAAiB,GAAI,EAAI,EAEtF,KAEP,KAAK,IACH,KAAK,SAAS,2DAA2D,EACzE,qCAAqC,KAAK,IAAI,EAChD,EACA,KAAK,uBAAuB,KAAK,mBAAoB,UAAU,KAAK,iBAAiB,GAAI,EAAK,EAEvF,GAEX,CAMA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EAGjC,SAAU,KACV,kBAAmB,KAAK,iBAC1B,CACF,CACF,CAEAJ,EAAgB,kBAAkBA,CAAe",
6
- "names": ["LogicStep", "flow_control_types", "FlowControlStep", "__name", "conditional", "name", "flow_control_type"]
4
+ "sourcesContent": ["import LogicStep from './logic_step.js';\nimport flow_control_types from '../../enums/flow_control_types.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\nimport { event_names } from '../instance_state.js';\n\n/**\n * FlowControlStep class for controlling workflow execution flow (break or skip).\n * @class FlowControlStep\n * @extends LogicStep\n */\nexport default class FlowControlStep extends LogicStep {\n static step_name = 'flow_control';\n\n /**\n * Creates a new FlowControlStep instance.\n * @param {Object} options - Configuration options.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {string} [options.name] - Name of the step.\n * @param {string} [options.flow_control_type=flow_control_types.BREAK] - Type of flow control.\n * @throws {Error} Throws if flow_control_type is invalid.\n */\n constructor({\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n name,\n flow_control_type = flow_control_types.BREAK,\n }) {\n super({\n name,\n conditional\n });\n\n if (!Object.values(flow_control_types).includes(flow_control_type)) {\n throw new Error(`Invalid flow control type: ${flow_control_type}`);\n }\n\n this.flow_control_type = flow_control_type;\n this.callable = this.shouldFlowControl.bind(this);\n }\n\n /**\n * Evaluates the condition and sets the appropriate flow control flag.\n * @async\n * @returns {Promise<boolean>} True if the flow control should be activated.\n */\n async shouldFlowControl() {\n if (this.checkCondition()) {\n this.log(\n event_names.step.CONDITIONAL_TRUE_BRANCH_EXECUTED,\n `Break condition met for step: ${this.name}`\n );\n this.setParentWorkflowValue(this.parent_workflow_id, `should_${this.flow_control_type}`, true);\n\n return true;\n } else {\n this.log(\n event_names.step.CONDITIONAL_FALSE_BRANCH_EXECUTED,\n `Break condition not met for step: ${this.name}`\n );\n this.setParentWorkflowValue(this.parent_workflow_id, `should_${this.flow_control_type}`, false);\n\n return false;\n }\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n // The base `callable` is an internal wiring detail (the bound `shouldFlowControl` method) -\n // FlowControlStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n flow_control_type: this.flow_control_type,\n };\n }\n}\n\nFlowControlStep.registerStepClass(FlowControlStep);\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAe,kBACtB,OAAOC,MAAwB,oCAC/B,MAA6C,uBAC7C,OAAS,eAAAC,MAAmB,uBAO5B,MAAOC,UAAsCH,CAAU,CAVvD,MAUuD,CAAAI,EAAA,wBACrD,OAAO,UAAY,eAanB,YAAY,CACV,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,KAAAC,EACA,kBAAAC,EAAoBN,EAAmB,KACzC,EAAG,CAMD,GALA,MAAM,CACJ,KAAAK,EACA,YAAAD,CACF,CAAC,EAEG,CAAC,OAAO,OAAOJ,CAAkB,EAAE,SAASM,CAAiB,EAC/D,MAAM,IAAI,MAAM,8BAA8BA,CAAiB,EAAE,EAGnE,KAAK,kBAAoBA,EACzB,KAAK,SAAW,KAAK,kBAAkB,KAAK,IAAI,CAClD,CAOA,MAAM,mBAAoB,CACxB,OAAI,KAAK,eAAe,GACtB,KAAK,IACHL,EAAY,KAAK,iCACjB,iCAAiC,KAAK,IAAI,EAC5C,EACA,KAAK,uBAAuB,KAAK,mBAAoB,UAAU,KAAK,iBAAiB,GAAI,EAAI,EAEtF,KAEP,KAAK,IACHA,EAAY,KAAK,kCACjB,qCAAqC,KAAK,IAAI,EAChD,EACA,KAAK,uBAAuB,KAAK,mBAAoB,UAAU,KAAK,iBAAiB,GAAI,EAAK,EAEvF,GAEX,CAMA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EAGjC,SAAU,KACV,kBAAmB,KAAK,iBAC1B,CACF,CACF,CAEAC,EAAgB,kBAAkBA,CAAe",
6
+ "names": ["LogicStep", "flow_control_types", "event_names", "FlowControlStep", "__name", "conditional", "name", "flow_control_type"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var c=Object.defineProperty;var n=(r,o)=>c(r,"name",{value:o,configurable:!0});import _ from"./step.js";import{step_types as p}from"../../enums/index.js";class i extends _{static{n(this,"LogicStep")}static step_name="logic";constructor({name:o,callable:a=n(async()=>{},"callable"),callable_registry_key:s=null,conditional:t={operator:null,subject:null,value:null}}){super({name:o,step_type:p.LOGIC,callable:a,callable_registry_key:s}),this.setConditional(t)}checkCondition(){const o=this.conditional_config.subject,a=this.conditional_config.value,s=this.conditional_config.operator,t=typeof o=="function"?o():o,e=!(s===this.getState("conditional_step_comparators.CUSTOM_FUNCTION"))&&typeof a=="function"?a():a;switch(s){case this.getState("conditional_step_comparators.STRICT_EQUALS"):case this.getState("conditional_step_comparators.SIGN_STRICT_EQUALS"):return t===e;case this.getState("conditional_step_comparators.SIGN_EQUALS"):case this.getState("conditional_step_comparators.EQUALS"):return t==e;case this.getState("conditional_step_comparators.NOT_EQUALS"):case this.getState("conditional_step_comparators.SIGN_NOT_EQUALS"):return t!=e;case this.getState("conditional_step_comparators.STRICT_NOT_EQUALS"):case this.getState("conditional_step_comparators.SIGN_STRICT_NOT_EQUALS"):return t!==e;case this.getState("conditional_step_comparators.GREATER_THAN"):case this.getState("conditional_step_comparators.SIGN_GREATER_THAN"):return t>e;case this.getState("conditional_step_comparators.LESS_THAN"):case this.getState("conditional_step_comparators.SIGN_LESS_THAN"):return t<e;case this.getState("conditional_step_comparators.GREATER_THAN_OR_EQUAL"):case this.getState("conditional_step_comparators.SIGN_GREATER_THAN_OR_EQUAL"):return t>=e;case this.getState("conditional_step_comparators.LESS_THAN_OR_EQUAL"):case this.getState("conditional_step_comparators.SIGN_LESS_THAN_OR_EQUAL"):return t<=e;case this.getState("conditional_step_comparators.STRING_CONTAINS"):case this.getState("conditional_step_comparators.STRING_INCLUDES"):case this.getState("conditional_step_comparators.ARRAY_CONTAINS"):case this.getState("conditional_step_comparators.ARRAY_INCLUDES"):return(Array.isArray(t)||typeof t=="string")&&t.includes(e);case this.getState("conditional_step_comparators.IN"):return(Array.isArray(e)||typeof e=="string")&&e.includes(t);case this.getState("conditional_step_comparators.STRING_NOT_CONTAINS"):case this.getState("conditional_step_comparators.STRING_NOT_INCLUDES"):case this.getState("conditional_step_comparators.ARRAY_NOT_CONTAINS"):case this.getState("conditional_step_comparators.ARRAY_NOT_INCLUDES"):return(Array.isArray(t)||typeof t=="string")&&!t.includes(e);case this.getState("conditional_step_comparators.NOT_IN"):return(Array.isArray(e)||typeof e=="string")&&!e.includes(t);case this.getState("conditional_step_comparators.EMPTY"):return t===""||t===null||t===void 0||t.length===0;case this.getState("conditional_step_comparators.NOT_EMPTY"):return t!==""&&t!==null&&t!==void 0&&t.length>0;case this.getState("conditional_step_comparators.REGEX_MATCH"):if(typeof e!="string")throw new Error("Regex input must be a string.");return new RegExp(e).test(t);case this.getState("conditional_step_comparators.REGEX_NOT_MATCH"):if(typeof e!="string")throw new Error("Regex input must be a string.");return!new RegExp(e).test(t);case this.getState("conditional_step_comparators.STRING_STARTS_WITH"):return typeof t=="string"&&typeof e=="string"&&t.startsWith(e);case this.getState("conditional_step_comparators.STRING_ENDS_WITH"):return typeof t=="string"&&typeof e=="string"&&t.endsWith(e);case this.getState("conditional_step_comparators.NULLISH"):return t==null;case this.getState("conditional_step_comparators.NOT_NULLISH"):return t!=null;case this.getState("conditional_step_comparators.IS_TYPE"):return typeof t===e;case this.getState("conditional_step_comparators.IS_NOT_TYPE"):return typeof t!==e;case this.getState("conditional_step_comparators.CUSTOM_FUNCTION"):if(typeof e!="function")throw new Error(`Invalid custom function: ${e}`);return e(t);default:throw new Error(`Unknown operator: ${s}`)}}conditionalIsValid(){return this.conditional_config.subject!==null&&this.conditional_config.subject!==void 0&&this.conditional_config.operator!==null&&this.conditional_config.operator!==void 0}setConditional(o){this.conditional_config={subject:o.subject,operator:o.operator,value:o.value}}prepareForSerialization(){return{...super.prepareForSerialization(),conditional:{...this.conditional_config}}}}i.registerStepClass(i);export{i as default};
1
+ var _=Object.defineProperty;var i=(a,r)=>_(a,"name",{value:r,configurable:!0});import u from"./step.js";import{conditional_step_comparators as t,step_types as T}from"../../enums/index.js";class c extends u{static{i(this,"LogicStep")}static step_name="logic";constructor({name:r,callable:s=i(async()=>{},"callable"),callable_registry_key:o=null,conditional:e={operator:null,subject:null,value:null}}){super({name:r,step_type:T.LOGIC,callable:s,callable_registry_key:o}),this.setConditional(e)}checkCondition(){const r=this.conditional_config.subject,s=this.conditional_config.value,o=this.conditional_config.operator,e=typeof r=="function"?r():r,n=!(o===t.CUSTOM_FUNCTION)&&typeof s=="function"?s():s;switch(o){case t.STRICT_EQUALS:case t.SIGN_STRICT_EQUALS:return e===n;case t.SIGN_EQUALS:case t.EQUALS:return e==n;case t.NOT_EQUALS:case t.SIGN_NOT_EQUALS:return e!=n;case t.STRICT_NOT_EQUALS:case t.SIGN_STRICT_NOT_EQUALS:return e!==n;case t.GREATER_THAN:case t.SIGN_GREATER_THAN:return e>n;case t.LESS_THAN:case t.SIGN_LESS_THAN:return e<n;case t.GREATER_THAN_OR_EQUAL:case t.SIGN_GREATER_THAN_OR_EQUAL:return e>=n;case t.LESS_THAN_OR_EQUAL:case t.SIGN_LESS_THAN_OR_EQUAL:return e<=n;case t.STRING_CONTAINS:case t.STRING_INCLUDES:case t.ARRAY_CONTAINS:case t.ARRAY_INCLUDES:return(Array.isArray(e)||typeof e=="string")&&e.includes(n);case t.IN:return(Array.isArray(n)||typeof n=="string")&&n.includes(e);case t.STRING_NOT_CONTAINS:case t.STRING_NOT_INCLUDES:case t.ARRAY_NOT_CONTAINS:case t.ARRAY_NOT_INCLUDES:return(Array.isArray(e)||typeof e=="string")&&!e.includes(n);case t.NOT_IN:return(Array.isArray(n)||typeof n=="string")&&!n.includes(e);case t.EMPTY:return e===""||e===null||e===void 0||e.length===0;case t.NOT_EMPTY:return e!==""&&e!==null&&e!==void 0&&e.length>0;case t.REGEX_MATCH:if(typeof n!="string")throw new Error("Regex input must be a string.");return new RegExp(n).test(e);case t.REGEX_NOT_MATCH:if(typeof n!="string")throw new Error("Regex input must be a string.");return!new RegExp(n).test(e);case t.STRING_STARTS_WITH:return typeof e=="string"&&typeof n=="string"&&e.startsWith(n);case t.STRING_ENDS_WITH:return typeof e=="string"&&typeof n=="string"&&e.endsWith(n);case t.NULLISH:return e==null;case t.NOT_NULLISH:return e!=null;case t.IS_TYPE:return typeof e===n;case t.IS_NOT_TYPE:return typeof e!==n;case t.CUSTOM_FUNCTION:if(typeof n!="function")throw new Error(`Invalid custom function: ${n}`);return n(e);default:throw new Error(`Unknown operator: ${o}`)}}conditionalIsValid(){return this.conditional_config.subject!==null&&this.conditional_config.subject!==void 0&&this.conditional_config.operator!==null&&this.conditional_config.operator!==void 0}setConditional(r){this.conditional_config={subject:r.subject,operator:r.operator,value:r.value}}prepareForSerialization(){return{...super.prepareForSerialization(),conditional:{...this.conditional_config}}}}c.registerStepClass(c);export{c as default};
2
2
  //# sourceMappingURL=logic_step.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/logic_step.js"],
4
- "sourcesContent": ["import Step from './step.js';\nimport { conditional_step_comparators, step_types } from '../../enums/index.js';\n\n/**\n * LogicStep class for conditional logic operations.\n * @class LogicStep\n * @extends Step\n */\nexport default class LogicStep extends Step {\n static step_name = 'logic';\n\n /**\n * Creates a new LogicStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function, optional} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {Function} [options.callable=async () => {}] - Function to execute.\n * @param {string|null} [options.callable_registry_key=null] - Optional key to reference the callable to be rehydrated after serialization.\n */\n constructor({\n name,\n callable = async () => {},\n callable_registry_key = null,\n conditional = {\n operator: null,\n subject: null,\n value: null,\n },\n }) {\n super({\n name,\n step_type: step_types.LOGIC,\n callable,\n callable_registry_key,\n });\n\n this.setConditional(conditional);\n }\n\n /**\n * Evaluates the conditional expression.\n * Supports function subjects and values - they are called to get the actual value.\n * @returns {boolean} True if the condition is met.\n * @throws {Error} Throws if operator is unknown.\n */\n checkCondition() {\n const raw_subject = this.conditional_config.subject;\n const raw_value = this.conditional_config.value;\n const operator = this.conditional_config.operator;\n \n // Resolve subject - call it if it's a function\n const subject = typeof raw_subject === 'function' ? raw_subject() : raw_subject;\n \n // Don't resolve value for CUSTOM_FUNCTION - the value IS the function to call\n const is_custom_function = operator === this.getState('conditional_step_comparators.CUSTOM_FUNCTION');\n const value = (!is_custom_function && typeof raw_value === 'function') ? raw_value() : raw_value;\n\n switch (operator) {\n case this.getState('conditional_step_comparators.STRICT_EQUALS'):\n case this.getState('conditional_step_comparators.SIGN_STRICT_EQUALS'):\n return subject === value;\n case this.getState('conditional_step_comparators.SIGN_EQUALS'):\n case this.getState('conditional_step_comparators.EQUALS'):\n return subject == value;\n case this.getState('conditional_step_comparators.NOT_EQUALS'):\n case this.getState('conditional_step_comparators.SIGN_NOT_EQUALS'):\n return subject != value;\n case this.getState('conditional_step_comparators.STRICT_NOT_EQUALS'):\n case this.getState('conditional_step_comparators.SIGN_STRICT_NOT_EQUALS'):\n return subject !== value;\n case this.getState('conditional_step_comparators.GREATER_THAN'):\n case this.getState('conditional_step_comparators.SIGN_GREATER_THAN'):\n return subject > value;\n case this.getState('conditional_step_comparators.LESS_THAN'):\n case this.getState('conditional_step_comparators.SIGN_LESS_THAN'):\n return subject < value;\n case this.getState('conditional_step_comparators.GREATER_THAN_OR_EQUAL'):\n case this.getState('conditional_step_comparators.SIGN_GREATER_THAN_OR_EQUAL'):\n return subject >= value;\n case this.getState('conditional_step_comparators.LESS_THAN_OR_EQUAL'):\n case this.getState('conditional_step_comparators.SIGN_LESS_THAN_OR_EQUAL'):\n return subject <= value;\n case this.getState('conditional_step_comparators.STRING_CONTAINS'):\n case this.getState('conditional_step_comparators.STRING_INCLUDES'):\n case this.getState('conditional_step_comparators.ARRAY_CONTAINS'):\n case this.getState('conditional_step_comparators.ARRAY_INCLUDES'):\n return (Array.isArray(subject) || typeof subject === 'string') && subject.includes(value);\n case this.getState('conditional_step_comparators.IN'):\n return (Array.isArray(value) || typeof value === 'string') && value.includes(subject);\n case this.getState('conditional_step_comparators.STRING_NOT_CONTAINS'):\n case this.getState('conditional_step_comparators.STRING_NOT_INCLUDES'):\n case this.getState('conditional_step_comparators.ARRAY_NOT_CONTAINS'):\n case this.getState('conditional_step_comparators.ARRAY_NOT_INCLUDES'):\n return (Array.isArray(subject) || typeof subject === 'string') && !subject.includes(value);\n case this.getState('conditional_step_comparators.NOT_IN'):\n return (Array.isArray(value) || typeof value === 'string') && !value.includes(subject);\n case this.getState('conditional_step_comparators.EMPTY'):\n return subject === '' || subject === null || subject === undefined || subject.length === 0;\n case this.getState('conditional_step_comparators.NOT_EMPTY'):\n return subject !== '' && subject !== null && subject !== undefined && subject.length > 0;\n case this.getState('conditional_step_comparators.REGEX_MATCH'):\n if (typeof value !== 'string') {\n throw new Error(`Regex input must be a string.`);\n }\n const regex = new RegExp(value);\n return regex.test(subject);\n case this.getState('conditional_step_comparators.REGEX_NOT_MATCH'):\n if (typeof value !== 'string') {\n throw new Error(`Regex input must be a string.`);\n }\n const not_match_regex = new RegExp(value);\n return !not_match_regex.test(subject);\n case this.getState('conditional_step_comparators.STRING_STARTS_WITH'):\n return typeof subject === 'string' && typeof value === 'string' && subject.startsWith(value);\n case this.getState('conditional_step_comparators.STRING_ENDS_WITH'):\n return typeof subject === 'string' && typeof value === 'string' && subject.endsWith(value);\n case this.getState('conditional_step_comparators.NULLISH'):\n return subject === null || subject === undefined;\n case this.getState('conditional_step_comparators.NOT_NULLISH'):\n return subject !== null && subject !== undefined;\n case this.getState('conditional_step_comparators.IS_TYPE'):\n return typeof subject === value;\n case this.getState('conditional_step_comparators.IS_NOT_TYPE'):\n return typeof subject !== value;\n case this.getState('conditional_step_comparators.CUSTOM_FUNCTION'):\n if (typeof value !== 'function') {\n throw new Error(`Invalid custom function: ${value}`);\n }\n return value(subject);\n default:\n throw new Error(`Unknown operator: ${operator}`);\n }\n }\n\n /**\n * Checks if the conditional configuration is valid.\n * A valid conditional has subject and operator set (not null/undefined).\n * Functions are valid as subject or value - they will be called during checkCondition().\n * @returns {boolean} True if conditional is valid.\n */\n conditionalIsValid() {\n // Check if all conditional properties are set (not null or undefined)\n // Can't use falsy check here because valid values could be falsy (e.g. empty string, 0, false)\n // Functions are valid - they'll be called to get the actual value\n return (\n this.conditional_config.subject !== null &&\n this.conditional_config.subject !== undefined &&\n this.conditional_config.operator !== null &&\n this.conditional_config.operator !== undefined\n );\n }\n\n /**\n * Sets the conditional properties.\n * @param {Object} conditional - Conditional configuration object.\n */\n setConditional(conditional) {\n this.conditional_config = { subject: conditional.subject, operator: conditional.operator, value: conditional.value };\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * Note: function-valued subject/value are not persisted - there's no registry for them,\n * only the plain-callable field supports registry-based rehydration.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n conditional: { ...this.conditional_config },\n };\n }\n}\n\nLogicStep.registerStepClass(LogicStep);\n"],
5
- "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAuC,cAAAC,MAAkB,uBAOzD,MAAOC,UAAgCF,CAAK,CAR5C,MAQ4C,CAAAG,EAAA,kBAC1C,OAAO,UAAY,QAanB,YAAY,CACV,KAA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AS,+CAA+C,EAChE,OAAO,OAAOD,GAAY,UAAY,OAAOC,GAAU,UAAYD,EAAQ,SAASC,CAAK,EAC3F,KAAK,KAAK,SAAS,sCAAsC,EACvD,OAAOD,GAAY,KACrB,KAAK,KAAK,SAAS,0CAA0C,EAC3D,OAAOA,GAAY,KACrB,KAAK,KAAK,SAAS,sCAAsC,EACvD,OAAO,OAAOA,IAAYC,EAC5B,KAAK,KAAK,SAAS,0CAA0C,EAC3D,OAAO,OAAOD,IAAYC,EAC5B,KAAK,KAAK,SAAS,8CAA8C,EAC/D,GAAI,OAAOA,GAAU,WACnB,MAAM,IAAI,MAAM,4BAA4BA,CAAK,EAAE,EAErD,OAAOA,EAAMD,CAAO,EACtB,QACE,MAAM,IAAI,MAAM,qBAAqBD,CAAQ,EAAE,CACnD,CACF,CAQA,oBAAqB,CAInB,OACE,KAAK,mBAAmB,UAAY,MACpC,KAAK,mBAAmB,UAAY,QACpC,KAAK,mBAAmB,WAAa,MACrC,KAAK,mBAAmB,WAAa,MAEzC,CAMA,eAAeH,EAAa,CAC1B,KAAK,mBAAqB,CAAE,QAASA,EAAY,QAAS,SAAUA,EAAY,SAAU,MAAOA,EAAY,KAAM,CACrH,CAQA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EACjC,YAAa,CAAE,GAAG,KAAK,kBAAmB,CAC5C,CACF,CACF,CAEAL,EAAU,kBAAkBA,CAAS",
6
- "names": ["Step", "step_types", "LogicStep", "__name", "name", "callable", "callable_registry_key", "conditional", "raw_subject", "raw_value", "operator", "subject", "value"]
4
+ "sourcesContent": ["import Step from './step.js';\nimport { conditional_step_comparators, step_types } from '../../enums/index.js';\n\n/**\n * LogicStep class for conditional logic operations.\n * @class LogicStep\n * @extends Step\n */\nexport default class LogicStep extends Step {\n static step_name = 'logic';\n\n /**\n * Creates a new LogicStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function, optional} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {Function} [options.callable=async () => {}] - Function to execute.\n * @param {string|null} [options.callable_registry_key=null] - Optional key to reference the callable to be rehydrated after serialization.\n */\n constructor({\n name,\n callable = async () => {},\n callable_registry_key = null,\n conditional = {\n operator: null,\n subject: null,\n value: null,\n },\n }) {\n super({\n name,\n step_type: step_types.LOGIC,\n callable,\n callable_registry_key,\n });\n\n this.setConditional(conditional);\n }\n\n /**\n * Evaluates the conditional expression.\n * Supports function subjects and values - they are called to get the actual value.\n * @returns {boolean} True if the condition is met.\n * @throws {Error} Throws if operator is unknown.\n */\n checkCondition() {\n const raw_subject = this.conditional_config.subject;\n const raw_value = this.conditional_config.value;\n const operator = this.conditional_config.operator;\n \n // Resolve subject - call it if it's a function\n const subject = typeof raw_subject === 'function' ? raw_subject() : raw_subject;\n \n // Don't resolve value for CUSTOM_FUNCTION - the value IS the function to call\n const is_custom_function = operator === conditional_step_comparators.CUSTOM_FUNCTION;\n const value = (!is_custom_function && typeof raw_value === 'function') ? raw_value() : raw_value;\n\n switch (operator) {\n case conditional_step_comparators.STRICT_EQUALS:\n case conditional_step_comparators.SIGN_STRICT_EQUALS:\n return subject === value;\n case conditional_step_comparators.SIGN_EQUALS:\n case conditional_step_comparators.EQUALS:\n return subject == value;\n case conditional_step_comparators.NOT_EQUALS:\n case conditional_step_comparators.SIGN_NOT_EQUALS:\n return subject != value;\n case conditional_step_comparators.STRICT_NOT_EQUALS:\n case conditional_step_comparators.SIGN_STRICT_NOT_EQUALS:\n return subject !== value;\n case conditional_step_comparators.GREATER_THAN:\n case conditional_step_comparators.SIGN_GREATER_THAN:\n return subject > value;\n case conditional_step_comparators.LESS_THAN:\n case conditional_step_comparators.SIGN_LESS_THAN:\n return subject < value;\n case conditional_step_comparators.GREATER_THAN_OR_EQUAL:\n case conditional_step_comparators.SIGN_GREATER_THAN_OR_EQUAL:\n return subject >= value;\n case conditional_step_comparators.LESS_THAN_OR_EQUAL:\n case conditional_step_comparators.SIGN_LESS_THAN_OR_EQUAL:\n return subject <= value;\n case conditional_step_comparators.STRING_CONTAINS:\n case conditional_step_comparators.STRING_INCLUDES:\n case conditional_step_comparators.ARRAY_CONTAINS:\n case conditional_step_comparators.ARRAY_INCLUDES:\n return (Array.isArray(subject) || typeof subject === 'string') && subject.includes(value);\n case conditional_step_comparators.IN:\n return (Array.isArray(value) || typeof value === 'string') && value.includes(subject);\n case conditional_step_comparators.STRING_NOT_CONTAINS:\n case conditional_step_comparators.STRING_NOT_INCLUDES:\n case conditional_step_comparators.ARRAY_NOT_CONTAINS:\n case conditional_step_comparators.ARRAY_NOT_INCLUDES:\n return (Array.isArray(subject) || typeof subject === 'string') && !subject.includes(value);\n case conditional_step_comparators.NOT_IN:\n return (Array.isArray(value) || typeof value === 'string') && !value.includes(subject);\n case conditional_step_comparators.EMPTY:\n return subject === '' || subject === null || subject === undefined || subject.length === 0;\n case conditional_step_comparators.NOT_EMPTY:\n return subject !== '' && subject !== null && subject !== undefined && subject.length > 0;\n case conditional_step_comparators.REGEX_MATCH:\n if (typeof value !== 'string') {\n throw new Error(`Regex input must be a string.`);\n }\n const regex = new RegExp(value);\n return regex.test(subject);\n case conditional_step_comparators.REGEX_NOT_MATCH:\n if (typeof value !== 'string') {\n throw new Error(`Regex input must be a string.`);\n }\n const not_match_regex = new RegExp(value);\n return !not_match_regex.test(subject);\n case conditional_step_comparators.STRING_STARTS_WITH:\n return typeof subject === 'string' && typeof value === 'string' && subject.startsWith(value);\n case conditional_step_comparators.STRING_ENDS_WITH:\n return typeof subject === 'string' && typeof value === 'string' && subject.endsWith(value);\n case conditional_step_comparators.NULLISH:\n return subject === null || subject === undefined;\n case conditional_step_comparators.NOT_NULLISH:\n return subject !== null && subject !== undefined;\n case conditional_step_comparators.IS_TYPE:\n return typeof subject === value;\n case conditional_step_comparators.IS_NOT_TYPE:\n return typeof subject !== value;\n case conditional_step_comparators.CUSTOM_FUNCTION:\n if (typeof value !== 'function') {\n throw new Error(`Invalid custom function: ${value}`);\n }\n return value(subject);\n default:\n throw new Error(`Unknown operator: ${operator}`);\n }\n }\n\n /**\n * Checks if the conditional configuration is valid.\n * A valid conditional has subject and operator set (not null/undefined).\n * Functions are valid as subject or value - they will be called during checkCondition().\n * @returns {boolean} True if conditional is valid.\n */\n conditionalIsValid() {\n // Check if all conditional properties are set (not null or undefined)\n // Can't use falsy check here because valid values could be falsy (e.g. empty string, 0, false)\n // Functions are valid - they'll be called to get the actual value\n return (\n this.conditional_config.subject !== null &&\n this.conditional_config.subject !== undefined &&\n this.conditional_config.operator !== null &&\n this.conditional_config.operator !== undefined\n );\n }\n\n /**\n * Sets the conditional properties.\n * @param {Object} conditional - Conditional configuration object.\n */\n setConditional(conditional) {\n this.conditional_config = { subject: conditional.subject, operator: conditional.operator, value: conditional.value };\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * Note: function-valued subject/value are not persisted - there's no registry for them,\n * only the plain-callable field supports registry-based rehydration.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n conditional: { ...this.conditional_config },\n };\n }\n}\n\nLogicStep.registerStepClass(LogicStep);\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAS,gCAAAC,EAA8B,cAAAC,MAAkB,uBAOzD,MAAOC,UAAgCH,CAAK,CAR5C,MAQ4C,CAAAI,EAAA,kBAC1C,OAAO,UAAY,QAanB,YAAY,CACV,KAAAC,EACA,SAAAC,EAAWF,EAAA,SAAY,CAAC,EAAb,YACX,sBAAAG,EAAwB,KACxB,YAAAC,EAAc,CACZ,SAAU,KACV,QAAS,KACT,MAAO,IACT,CACF,EAAG,CACD,MAAM,CACJ,KAAAH,EACA,UAAWH,EAAW,MACtB,SAAAI,EACA,sBAAAC,CAC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A,eAAeH,EAAa,CAC1B,KAAK,mBAAqB,CAAE,QAASA,EAAY,QAAS,SAAUA,EAAY,SAAU,MAAOA,EAAY,KAAM,CACrH,CAQA,yBAA0B,CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EACjC,YAAa,CAAE,GAAG,KAAK,kBAAmB,CAC5C,CACF,CACF,CAEAL,EAAU,kBAAkBA,CAAS",
6
+ "names": ["Step", "conditional_step_comparators", "step_types", "LogicStep", "__name", "name", "callable", "callable_registry_key", "conditional", "raw_subject", "raw_value", "operator", "subject", "value"]
7
7
  }