@ronaldroe/micro-flow 1.3.8 → 2.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.
- package/README.md +53 -12
- package/dist/src/classes/base.js +2 -2
- package/dist/src/classes/base.js.map +3 -3
- package/dist/src/classes/callable_registry.js +1 -1
- package/dist/src/classes/callable_registry.js.map +2 -2
- package/dist/src/classes/events/event.js +1 -1
- package/dist/src/classes/events/event.js.map +3 -3
- package/dist/src/classes/index.js +1 -1
- package/dist/src/classes/index.js.map +3 -3
- package/dist/src/classes/state.js +1 -1
- package/dist/src/classes/state.js.map +3 -3
- package/dist/src/classes/steps/case.js +1 -1
- package/dist/src/classes/steps/case.js.map +3 -3
- package/dist/src/classes/steps/conditional_step.js +1 -1
- package/dist/src/classes/steps/conditional_step.js.map +3 -3
- package/dist/src/classes/steps/delay_step.js +1 -1
- package/dist/src/classes/steps/delay_step.js.map +2 -2
- package/dist/src/classes/steps/flow_control_step.js +1 -1
- package/dist/src/classes/steps/flow_control_step.js.map +2 -2
- package/dist/src/classes/steps/logic_step.js +1 -1
- package/dist/src/classes/steps/logic_step.js.map +3 -3
- package/dist/src/classes/steps/loop_step.js +1 -1
- package/dist/src/classes/steps/loop_step.js.map +3 -3
- package/dist/src/classes/steps/step.js +1 -1
- package/dist/src/classes/steps/step.js.map +3 -3
- package/dist/src/classes/steps/switch_step.js +1 -1
- package/dist/src/classes/steps/switch_step.js.map +3 -3
- package/dist/src/classes/workflow.js +1 -1
- package/dist/src/classes/workflow.js.map +3 -3
- package/dist/src/enums/delay_types.js.map +1 -1
- package/dist/src/enums/logic_step_types.js.map +3 -3
- package/dist/src/enums/sub_step_types.js +1 -1
- package/dist/src/enums/sub_step_types.js.map +2 -2
- package/package.json +1 -1
- package/src/classes/base.js +42 -11
- package/src/classes/callable_registry.js +82 -0
- package/src/classes/events/event.js +3 -3
- package/src/classes/index.js +2 -1
- package/src/classes/state.js +278 -8
- package/src/classes/steps/case.js +34 -4
- package/src/classes/steps/conditional_step.js +69 -3
- package/src/classes/steps/delay_step.js +18 -0
- package/src/classes/steps/flow_control_step.js +18 -2
- package/src/classes/steps/logic_step.js +26 -8
- package/src/classes/steps/loop_step.js +88 -3
- package/src/classes/steps/step.js +228 -16
- package/src/classes/steps/switch_step.js +66 -8
- package/src/classes/workflow.js +237 -40
- package/src/enums/delay_types.js +1 -1
- package/src/enums/logic_step_types.js +2 -2
- package/src/enums/sub_step_types.js +10 -10
|
@@ -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"],
|
|
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,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CAC/B,CACF",
|
|
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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ACjB,mBAAoB,KAAK,mBACzB,kBAAmB,KAAK,iBAC1B,CACF,CACF,CAEAP,EAAU,kBAAkBA,CAAS",
|
|
6
6
|
"names": ["Step", "delay_types", "step_types", "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
|
|
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};
|
|
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.
|
|
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,
|
|
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
6
|
"names": ["LogicStep", "flow_control_types", "FlowControlStep", "__name", "conditional", "name", "flow_control_type"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
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};
|
|
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 */\n constructor({\n name,\n callable = async () => {},\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
|
|
5
|
-
"mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAuC,cAAAC,MAAkB,uBAOzD,MAAOC,UAAgCF,CAAK,CAR5C,MAQ4C,CAAAG,EAAA,kBAC1C,OAAO,UAAY,
|
|
6
|
-
"names": ["Step", "step_types", "LogicStep", "__name", "name", "callable", "conditional", "
|
|
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,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,CACF,CAAC,EAED,KAAK,eAAeC,CAAW,CACjC,CAQA,gBAAiB,CACf,MAAMC,EAAc,KAAK,mBAAmB,QACtCC,EAAY,KAAK,mBAAmB,MACpCC,EAAW,KAAK,mBAAmB,SAGnCC,EAAU,OAAOH,GAAgB,WAAaA,EAAY,EAAIA,EAI9DI,EAAS,EADYF,IAAa,KAAK,SAAS,8CAA8C,IAC9D,OAAOD,GAAc,WAAcA,EAAU,EAAIA,EAEvF,OAAQC,EAAU,CAChB,KAAK,KAAK,SAAS,4CAA4C,EAC/D,KAAK,KAAK,SAAS,iDAAiD,EAClE,OAAOC,IAAYC,EACrB,KAAK,KAAK,SAAS,0CAA0C,EAC7D,KAAK,KAAK,SAAS,qCAAqC,EACtD,OAAOD,GAAWC,EACpB,KAAK,KAAK,SAAS,yCAAyC,EAC5D,KAAK,KAAK,SAAS,8CAA8C,EAC/D,OAAOD,GAAWC,EACpB,KAAK,KAAK,SAAS,gDAAgD,EACnE,KAAK,KAAK,SAAS,qDAAqD,EACtE,OAAOD,IAAYC,EACrB,KAAK,KAAK,SAAS,2CAA2C,EAC9D,KAAK,KAAK,SAAS,gDAAgD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ep", "__name", "name", "callable", "callable_registry_key", "conditional", "raw_subject", "raw_value", "operator", "subject", "value"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=Object.defineProperty;var a=(n,t)=>c(n,"name",{value:t,configurable:!0});import{loop_types as u,step_types as b}from"../../enums/index.js";import i from"./step.js";import f from"./logic_step.js";import"../../enums/index.js";class r extends f{static{a(this,"LoopStep")}static step_name=b.LOOP;constructor({name:t,iterable:e,callable:l=a(async()=>{},"callable"),conditional:o={operator:null,subject:null,value:null},loop_type:p=u.FOR_EACH,iterations:h=0,max_iterations:s=1e3,loop_callable_registry_key:_=null}){super({name:t,conditional:o}),this.iterable=e,this.loop_type=p,this.iterations=h>s?s:h,this.max_iterations=s,this.results=[],this.current_item=null,this.loop_callable_registry_key=_,this._loop_callable_type=this.getCallableType(l),this._loop_callable_object=l,this._loop_callable=this._loop_callable_type==="function"?l.bind(this):l.execute.bind(l),this.callable=this[`${p}_loop`].bind(this)}propagateStateToLoopCallable(){this._loop_callable_type!=="function"&&(this._loop_callable_object.parent_workflow_id=this.parent_workflow_id,this._loop_callable_object.use_state_singleton=this.use_state_singleton,this._loop_callable_object.state=this.state)}async generator_loop(){if(!this._loop_callable.constructor.name.includes("Generator"))throw new Error("Iterable must be a generator function for generator loops");this.propagateStateToLoopCallable();let t=0;for await(const e of this._loop_callable())if(this.results.push(e),++t>=this.max_iterations)break;return this.iterations=t,{message:`Generator loop ${this.name} completed after ${t} iterations`,result:this.results}}async for_loop(){this.propagateStateToLoopCallable();const t=this.iterations;let e=0;for(;e<t;e++)this.results.push(await this._loop_callable());return this.iterations=e,{message:`For loop ${this.name} completed after ${e} iterations`,result:this.results}}async for_each_loop(){if(!this.iterable)throw new Error("Iterable is required for for_each loops");this.propagateStateToLoopCallable(),typeof this.iterable=="function"&&(this.iterable=this.iterable());let t=0;for(const e of this.iterable)t++,this.current_item=e,this.results.push(await this._loop_callable());return this.iterations=t,{message:`For each loop ${this.name} completed after ${t} iterations`,result:this.results}}async while_loop(){if(!this.conditionalIsValid())throw new Error("Valid conditional is required for while loops");this.propagateStateToLoopCallable();let t=0;for(;this.checkCondition()&&t<this.max_iterations;)t++,this.results.push(await this._loop_callable());return this.iterations=t,{message:`While loop ${this.name} completed after ${t} iterations`,result:this.results}}prepareForSerialization(){return{...super.prepareForSerialization(),callable:this.loop_callable_registry_key?{type:i.callable_types.FUNCTION,value:this.loop_callable_registry_key}:i.serializeCallableField(this._loop_callable_object),loop_type:this.loop_type,iterations:this.iterations,max_iterations:this.max_iterations,iterable:Array.isArray(this.iterable)?this.iterable:null,results:this.results}}static hydrate(t,e=null){const l=t.callable,o=super.hydrate({...t,callable:i.hydrateCallableField(l,e),loop_callable_registry_key:l?.type===i.callable_types.FUNCTION?l.value:null},e);return o.results=t.results??[],o}}r.registerStepClass(r);export{r as default};
|
|
2
2
|
//# sourceMappingURL=loop_step.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/classes/steps/loop_step.js"],
|
|
4
|
-
"sourcesContent": ["import { loop_types, step_types } from '../../enums/index.js';\nimport LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * LoopStep class for executing loops within a workflow.\n * @class LoopStep\n * @extends LogicStep\n */\nexport default class LoopStep extends LogicStep {\n static step_name = step_types.LOOP;\n\n /**\n * Creates a new LoopStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Array|Iterable|Function} options.iterable - Iterable to loop over or function returning an iterable. Required for 'for_each' and 'generator' loops.\n * @param {Function} [options.callable=async () => {}] - Function to execute for each iteration.\n * @param {Object} [options.conditional] - Conditional configuration for while loops. Required for 'while' loops.\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.loop_type=loop_types.FOR_EACH] - Type of loop ('for', 'for_each', 'while', or 'generator').\n * @param {number} [options.iterations=0] - Number of iterations to execute. Only used for 'for' loops.\n * @param {number} [options.max_iterations=1000] - Maximum number of iterations to prevent infinite loops.\n */\n constructor({\n name,\n iterable,\n callable = async () => {},\n conditional = {\n operator: null,\n subject: null,\n value: null,\n },\n loop_type = loop_types.FOR_EACH,\n iterations = 0,\n max_iterations = 1000,\n }) {\n super({ name, conditional });\n this.iterable = iterable;\n this.loop_type = loop_type;\n this.iterations = iterations > max_iterations ? max_iterations : iterations;\n this.max_iterations = max_iterations;\n this.results = [];\n this.current_item = null;\n\n // Store the user's callable separately so loop methods can invoke it.\n // this._callable will be set to the loop method by the setter below.\n
|
|
5
|
-
"mappings": "+EAAA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,uBACvC,OAAOC,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAA+BD,CAAU,
|
|
6
|
-
"names": ["loop_types", "step_types", "LogicStep", "LoopStep", "__name", "name", "iterable", "callable", "conditional", "loop_type", "iterations", "max_iterations", "
|
|
4
|
+
"sourcesContent": ["import { loop_types, step_types } from '../../enums/index.js';\nimport Step from './step.js';\nimport LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * LoopStep class for executing loops within a workflow.\n * @class LoopStep\n * @extends LogicStep\n */\nexport default class LoopStep extends LogicStep {\n static step_name = step_types.LOOP;\n\n /**\n * Creates a new LoopStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Array|Iterable|Function} options.iterable - Iterable to loop over or function returning an iterable. Required for 'for_each' and 'generator' loops.\n * @param {Function} [options.callable=async () => {}] - Function to execute for each iteration.\n * @param {Object} [options.conditional] - Conditional configuration for while loops. Required for 'while' loops.\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.loop_type=loop_types.FOR_EACH] - Type of loop ('for', 'for_each', 'while', or 'generator').\n * @param {number} [options.iterations=0] - Number of iterations to execute. Only used for 'for' loops.\n * @param {number} [options.max_iterations=1000] - Maximum number of iterations to prevent infinite loops.\n * @param {string|null} [options.loop_callable_registry_key=null] - Optional key to reference the per-iteration callable to be rehydrated after serialization.\n */\n constructor({\n name,\n iterable,\n callable = async () => {},\n conditional = {\n operator: null,\n subject: null,\n value: null,\n },\n loop_type = loop_types.FOR_EACH,\n iterations = 0,\n max_iterations = 1000,\n loop_callable_registry_key = null,\n }) {\n super({ name, conditional });\n this.iterable = iterable;\n this.loop_type = loop_type;\n this.iterations = iterations > max_iterations ? max_iterations : iterations;\n this.max_iterations = max_iterations;\n this.results = [];\n this.current_item = null;\n\n // Optional key to reference the per-iteration callable to be rehydrated after serialization.\n this.loop_callable_registry_key = loop_callable_registry_key;\n\n // Store the user's callable separately so loop methods can invoke it.\n // this._callable will be set to the loop method by the setter below.\n // The raw object is kept too (distinct from the bound version) so serialization\n // can recover the original function/Step/Workflow instead of the loop-runner method.\n this._loop_callable_type = this.getCallableType(callable);\n this._loop_callable_object = callable;\n this._loop_callable = this._loop_callable_type === 'function'\n ? callable.bind(this)\n : callable.execute.bind(callable);\n\n this.callable = this[`${loop_type}_loop`].bind(this);\n }\n\n /**\n * When the per-iteration callable is a `Step`/`Workflow` (not a plain function), stamps it with\n * this loop step's own `parent_workflow_id`/`use_state_singleton`/`state` right before the loop\n * runs - mirrors what `Workflow.addStep()` does for top-level steps, since a loop callable is\n * never added to the workflow directly.\n */\n propagateStateToLoopCallable() {\n if (this._loop_callable_type === 'function') {\n return;\n }\n\n this._loop_callable_object.parent_workflow_id = this.parent_workflow_id;\n this._loop_callable_object.use_state_singleton = this.use_state_singleton;\n this._loop_callable_object.state = this.state;\n }\n\n /**\n * Executes a generator/async generator and appends yielded values to results.\n * @throws {Error} If the callable is not a generator or async generator function.\n * @returns {Object} - An object containing a message and the results of the loop.\n */\n async generator_loop() {\n if (!this._loop_callable.constructor.name.includes('Generator')) {\n throw new Error('Iterable must be a generator function for generator loops');\n }\n\n this.propagateStateToLoopCallable();\n\n let iterations = 0;\n // Use for await...of to handle both sync and async generators\n for await (const item of this._loop_callable()) {\n this.results.push(item);\n\n if (++iterations >= this.max_iterations) {\n break;\n }\n }\n\n this.iterations = iterations;\n\n return {\n message: `Generator loop ${this.name} completed after ${iterations} iterations`,\n result: this.results\n };\n }\n\n /**\n * Executes a for loop calling the callable for a set number of iterations\n * @returns {Object} - An object containing a message and the results of the loop.\n */\n async for_loop() {\n this.propagateStateToLoopCallable();\n\n const target = this.iterations;\n let i = 0;\n for (; i < target; i++) {\n this.results.push(await this._loop_callable());\n }\n\n this.iterations = i;\n\n return {\n message: `For loop ${this.name} completed after ${i} iterations`,\n result: this.results\n };\n }\n\n /**\n * Executes the callable for each item in the iterable.\n * @throws {Error} If the iterable is not provided.\n * @returns {Object} - An object containing a message and the results of the loop.\n */\n async for_each_loop() {\n if (!this.iterable) {\n throw new Error('Iterable is required for for_each loops');\n }\n\n this.propagateStateToLoopCallable();\n\n if (typeof this.iterable === 'function') {\n this.iterable = this.iterable();\n }\n\n let iterations = 0;\n for (const item of this.iterable) {\n iterations++;\n this.current_item = item;\n this.results.push(await this._loop_callable());\n }\n\n this.iterations = iterations;\n\n return {\n message: `For each loop ${this.name} completed after ${iterations} iterations`,\n result: this.results\n };\n }\n\n /**\n * Executes the callable while the condition is true.\n * @throws {Error} If the conditional is not valid.\n * @returns {Object} - An object containing a message and the results of the loop.\n */\n async while_loop() {\n if (!this.conditionalIsValid()) {\n throw new Error('Valid conditional is required for while loops');\n }\n\n this.propagateStateToLoopCallable();\n\n let iterations = 0;\n while (this.checkCondition() && iterations < this.max_iterations) {\n iterations++;\n this.results.push(await this._loop_callable());\n }\n\n this.iterations = iterations;\n\n return {\n message: `While loop ${this.name} completed after ${iterations} iterations`,\n result: this.results\n };\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * Note: a function-valued `iterable` is not persisted, since there's no registry for it.\n * @returns {Object} An object containing the step's properties ready for serialization.\n */\n prepareForSerialization() {\n return {\n ...super.prepareForSerialization(),\n callable: this.loop_callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.loop_callable_registry_key }\n : Step.serializeCallableField(this._loop_callable_object),\n loop_type: this.loop_type,\n iterations: this.iterations,\n max_iterations: this.max_iterations,\n iterable: Array.isArray(this.iterable) ? this.iterable : null,\n results: this.results,\n };\n }\n\n /**\n * Hydrates a parsed step object into a LoopStep instance, resolving the per-iteration callable.\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 {LoopStep} The hydrated LoopStep instance.\n */\n static hydrate(parsed_step, callable_registry = null) {\n const callable_descriptor = parsed_step.callable;\n\n const instance = super.hydrate({\n ...parsed_step,\n callable: Step.hydrateCallableField(callable_descriptor, callable_registry),\n loop_callable_registry_key: callable_descriptor?.type === Step.callable_types.FUNCTION\n ? callable_descriptor.value\n : null,\n }, callable_registry);\n\n instance.results = parsed_step.results ?? [];\n\n return instance;\n }\n}\n\nLoopStep.registerStepClass(LoopStep);\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,uBACvC,OAAOC,MAAU,YACjB,OAAOC,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAA+BD,CAAU,CAVhD,MAUgD,CAAAE,EAAA,iBAC9C,OAAO,UAAYJ,EAAW,KAiB9B,YAAY,CACV,KAAAK,EACA,SAAAC,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,YAAAI,EAAc,CACZ,SAAU,KACV,QAAS,KACT,MAAO,IACT,EACA,UAAAC,EAAYV,EAAW,SACvB,WAAAW,EAAa,EACb,eAAAC,EAAiB,IACj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,MACpB,IACN,EAAGD,CAAiB,EAEpB,OAAAE,EAAS,QAAUH,EAAY,SAAW,CAAC,EAEpCG,CACT,CACF,CAEAhB,EAAS,kBAAkBA,CAAQ",
|
|
6
|
+
"names": ["loop_types", "step_types", "Step", "LogicStep", "LoopStep", "__name", "name", "iterable", "callable", "conditional", "loop_type", "iterations", "max_iterations", "loop_callable_registry_key", "item", "target", "i", "parsed_step", "callable_registry", "callable_descriptor", "instance"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=Object.defineProperty;var n=(h,t)=>c(h,"name",{value:t,configurable:!0});import _ from"../base.js";import p from"../workflow.js";import{base_types as o,step_types as f}from"../../enums/index.js";const u={};class r extends _{static{n(this,"Step")}static step_name="step";#t=null;static callable_types={FUNCTION:"function",STEP:"step",WORKFLOW:"workflow"};constructor({name:t,callable:e=n(async()=>{},"callable"),callable_registry_key:s=null,max_retries:i=0,max_timeout_ms:a=3e4,step_type:l=f.ACTION,sub_step_type:y=null}){super({name:t,base_type:o.STEP}),this.callable=e,this.callable_registry_key=s,this.#t=e,this.max_retries=i,this.retry_count=0,this.max_timeout_ms=a,this.step_type=l,this.sub_step_type=y,this.errors=[],this.result=null,this.retry_results=[],this.timeout=null}async execute(){this.timeout||(this.timeout=new Promise((s,i)=>setTimeout(i,this.max_timeout_ms,new Error(`Step "${this.name}" timed out after ${this.max_timeout_ms}ms`)))),this.markAsRunning();try{this.result=await Promise.race([this._callable(),this.timeout])}catch(s){if(this.max_retries&&this.retry_count<this.max_retries)this.retry_count++,this.retry_results.push({retry_count:this.retry_count,result:await this.execute()});else if(this.errors.push(s),this.markAsFailed(),this.getState("exit_on_error"))throw s}const{FAILED:t,COMPLETE:e}=this.getState("statuses")[this.base_type];return[t,e].includes(this.status)||this.markAsComplete(),["step","workflow"].includes(this.callable_type)?this.#t:this.prepareForSerialization()}getCallableType(t){return r.getCallableType(t)}static getCallableType(t){if(t&&t.base_type===o.WORKFLOW)return r.callable_types.WORKFLOW;if(t&&t.base_type===o.STEP)return r.callable_types.STEP;if(typeof t=="function")return r.callable_types.FUNCTION;throw new Error("Invalid callable type. Must be one of function, Step, or Workflow.")}static registerStepClass(t){u[t.step_name]=t}static resolveStepClass(t){return u[t]??r}static serializeCallableField(t){if(t==null)return null;const e=r.getCallableType(t);return e===r.callable_types.FUNCTION?{type:e,value:t.name}:{type:e,value:t.prepareForSerialization()}}static hydrateCallableField(t,e=null){if(t==null)return;if(typeof t=="function"||t instanceof r||t?.base_type)return t;const{type:s,value:i}=t;if(s===r.callable_types.FUNCTION){if(!e||!e.has(i))throw new Error(`Callable registry key "${i}" not found in registry or registry not provided.`);return e.get(i)}if(s===r.callable_types.STEP)return r.hydrateAny(i,e);if(s===r.callable_types.WORKFLOW)return p.hydrate(i,e);throw new Error(`Unknown callable type "${s}" encountered during hydration.`)}static hydrateAny(t,e=null){return r.resolveStepClass(t.class_name).hydrate(t,e)}prepareForSerialization(){const t={id:this.id,class_name:this.constructor.step_name,name:this.name,callable_type:this.callable_type,step_type:this.step_type,sub_step_type:this.sub_step_type,max_retries:this.max_retries,max_timeout_ms:this.max_timeout_ms,retry_count:this.retry_count,retry_results:this.retry_results,errors:this.errors,result:this.result,timing:this.timing,status:this.status,parent_workflow_id:this.parent_workflow_id};return t.callable=this.callable_registry_key?{type:r.callable_types.FUNCTION,value:this.callable_registry_key}:r.serializeCallableField(this.#t),t}setParentWorkflowValue(t,e,s){const i=this.getState("workflows")[t];if(!i)throw new Error(`Parent workflow with ID ${t} not found.`);i[e]=s}serialize(){return JSON.stringify(this.prepareForSerialization())}toJSON(){return this.prepareForSerialization()}set callable(t){this.callable_type=this.getCallableType(t),["step","workflow"].includes(this.callable_type)?(this.callable_type==="step"&&(t.parent_workflow_id=this.parent_workflow_id??null),this._callable=t.execute.bind(t)):this._callable=t.bind(this)}static hydrateSerialized(t,e=null){if(typeof t!="string")throw new Error("Invalid serialized step. Must be a string.");return r.hydrateAny(JSON.parse(t),e)}static hydrate(t,e=null){const s=t.callable,i=r.hydrateCallableField(s,e),a=s?.type===r.callable_types.FUNCTION?s.value:null,l=new this({...t,callable:i,callable_registry_key:a});return l.id=t.id,l.retry_count=t.retry_count??0,l.retry_results=t.retry_results??[],l.errors=t.errors??[],l.result=t.result??null,l.timing=t.timing,l.status=t.status,l.parent_workflow_id=t.parent_workflow_id??null,l}}r.registerStepClass(r);export{r as default};
|
|
2
2
|
//# sourceMappingURL=step.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/classes/steps/step.js"],
|
|
4
|
-
"sourcesContent": ["import Base from '../base.js';\nimport Workflow from '../workflow.js';\nimport { base_types, step_types } from '../../enums/index.js';\n\n/**\n * Step class representing an executable unit within a workflow.\n * @class Step\n * @extends Base\n */\nexport default class Step extends Base {\n static step_name = 'step';\n #callable_object = null;\n\n /**\n * Creates a new Step instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Function|Step|Workflow} [options.callable=async () => {}] - Function, Step, or Workflow to execute.\n * @param {number} [options.max_retries=0] - Maximum number of retries on failure.\n * @param {number} [options.max_timeout_ms=30000] - Maximum execution time in milliseconds before timing out.\n * @param {string} [options.step_type=step_types.ACTION] - Type of the step.\n * @param {sub_step_types|null} [options.sub_step_type=null] - Sub-type of the step (use values from the sub_step_types enum).\n */\n constructor({\n name,\n callable = async () => {},\n max_retries = 0,\n max_timeout_ms = 30000,\n step_type = step_types.ACTION,\n sub_step_type = null,\n }) {\n super({ name, base_type: base_types.STEP });\n\n this.callable = callable;\n\n // Store off the original callable object, because if it's a Step or Workflow,\n // this.callable is set to the execute method of that object, but we may need to access its properties later.\n this.#callable_object = callable;\n\n this.max_retries = max_retries;\n this.retry_count = 0;\n this.max_timeout_ms = max_timeout_ms;\n this.step_type = step_type;\n this.sub_step_type = sub_step_type;\n\n this.errors = [];\n this.result = null;\n this.retry_results = [];\n this.timeout = null;\n }\n\n /**\n * Executes the step's callable function, Step, or Workflow.\n * @async\n * @returns {Promise<Step>} The step instance with execution results.\n */\n async execute() {\n if (!this.timeout ) {\n this.timeout = new Promise((_, reject) =>\n setTimeout(reject, this.max_timeout_ms, new Error(`Step \"${this.name}\" timed out after ${this.max_timeout_ms}ms`))\n );\n }\n\n this.markAsRunning();\n\n try {\n this.result = await Promise.race([this._callable(), this.timeout]);\n } catch (error) {\n if (this.max_retries && this.retry_count < this.max_retries) {\n this.retry_count++;\n this.retry_results.push({\n retry_count: this.retry_count,\n result: await this.execute(),\n });\n } else {\n this.errors.push(error);\n\n this.markAsFailed();\n\n if (this.getState('exit_on_error')) {\n throw error;\n }\n }\n\n }\n\n const { FAILED, COMPLETE } = this.getState('statuses')[this.base_type];\n\n if (! [FAILED, COMPLETE].includes(this.status)) {\n this.markAsComplete();\n }\n\n if (['step', 'workflow'].includes(this.callable_type)) {\n return this.#callable_object;\n }\n\n return this;\n }\n\n /**\n * Determines the type of the callable (function, step, or workflow).\n * @param {Function|Step|Workflow} callable - The callable to check.\n * @returns {string} The type: 'function', 'step', or 'workflow'.\n * @throws {Error} Throws if callable type is invalid.\n */\n getCallableType(callable) {\n if (callable && callable.base_type === base_types.WORKFLOW) {\n return 'workflow';\n } else if (callable && callable.base_type === base_types.STEP) {\n return 'step';\n } else if (typeof callable === 'function') {\n return 'function';\n } \n\n throw new Error('Invalid callable type. Must be one of function, Step, or Workflow.');\n }\n\n /**\n * Sets a value in the parent workflow's state.\n * @param {string} workflowId - ID of the parent workflow.\n * @param {string} path - Path in the workflow state to set.\n * @param {*} value - Value to set at the specified path.\n * @throws {Error} Throws if parent workflow is not found.\n */\n setParentWorkflowValue(workflowId, path, value) {\n const parentWorkflow = this.getState('workflows')[workflowId];\n\n if (!parentWorkflow) {\n throw new Error(`Parent workflow with ID ${workflowId} not found.`);\n }\n\n parentWorkflow[path] = value;\n }\n\n /**\n * Sets the callable for the step and determines its type.\n * @param {Function|Step|Workflow} callable - The callable to set.\n */\n set callable(callable) {\n this.callable_type = this.getCallableType(callable);\n\n if (['step', 'workflow'].includes(this.callable_type)) {\n if (this.callable_type === 'step') {\n callable.parentWorkflowId = this.parentWorkflowId ?? null;\n }\n\n this._callable = callable.execute.bind(callable);\n } else {\n this._callable = callable.bind(this);\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "+EAAA,OAAOA,MAAU,aACjB,
|
|
6
|
-
"names": ["Base", "base_types", "step_types", "Step", "__name", "#callable_object", "name", "callable", "max_retries", "max_timeout_ms", "step_type", "sub_step_type", "_", "reject", "error", "FAILED", "COMPLETE", "
|
|
4
|
+
"sourcesContent": ["import Base from '../base.js';\nimport Workflow from '../workflow.js';\nimport { base_types, step_types } from '../../enums/index.js';\n\n// Populated by each Step subclass file registering itself (see the bottom of\n// step.js and each subclass file) - keeps this file from importing every\n// subclass directly, which would create an import cycle through the hierarchy.\nconst step_class_registry = {};\n\n/**\n * Step class representing an executable unit within a workflow.\n * @class Step\n * @extends Base\n */\nexport default class Step extends Base {\n static step_name = 'step';\n #callable_object = null;\n static callable_types = {\n FUNCTION: 'function',\n STEP: 'step',\n WORKFLOW: 'workflow',\n }\n\n /**\n * Creates a new Step instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Function|Step|Workflow} [options.callable=async () => {}] - Function, Step, or Workflow to execute.\n * @param {number} [options.max_retries=0] - Maximum number of retries on failure.\n * @param {number} [options.max_timeout_ms=30000] - Maximum execution time in milliseconds before timing out.\n * @param {string} [options.step_type=step_types.ACTION] - Type of the step.\n * @param {sub_step_types|null} [options.sub_step_type=null] - Sub-type of the step (use values from the sub_step_types enum).\n */\n constructor({\n name,\n callable = async () => {},\n callable_registry_key = null,\n max_retries = 0,\n max_timeout_ms = 30000,\n step_type = step_types.ACTION,\n sub_step_type = null,\n }) {\n super({ name, base_type: base_types.STEP });\n\n this.callable = callable;\n\n // Optional key to reference the callable to be rehydrated after serialization.\n this.callable_registry_key = callable_registry_key;\n\n // Store off the original callable object, because if it's a Step or Workflow,\n // this.callable is set to the execute method of that object, but we may need to access its properties later.\n this.#callable_object = callable;\n\n this.max_retries = max_retries;\n this.retry_count = 0;\n this.max_timeout_ms = max_timeout_ms;\n this.step_type = step_type;\n this.sub_step_type = sub_step_type;\n\n this.errors = [];\n this.result = null;\n this.retry_results = [];\n this.timeout = null;\n }\n\n /**\n * Executes the step's callable function, Step, or Workflow.\n * @async\n * @returns {Promise<Step>} The step instance with execution results.\n */\n async execute() {\n if (!this.timeout) {\n this.timeout = new Promise((_, reject) =>\n setTimeout(\n reject,\n this.max_timeout_ms,\n new Error(`Step \"${this.name}\" timed out after ${this.max_timeout_ms}ms`)\n )\n );\n }\n\n this.markAsRunning();\n\n try {\n this.result = await Promise.race([this._callable(), this.timeout]);\n } catch (error) {\n if (this.max_retries && this.retry_count < this.max_retries) {\n this.retry_count++;\n this.retry_results.push({\n retry_count: this.retry_count,\n result: await this.execute(),\n });\n } else {\n this.errors.push(error);\n\n this.markAsFailed();\n\n if (this.getState('exit_on_error')) {\n throw error;\n }\n }\n }\n\n const { FAILED, COMPLETE } = this.getState('statuses')[this.base_type];\n\n if (![FAILED, COMPLETE].includes(this.status)) {\n this.markAsComplete();\n }\n\n if (['step', 'workflow'].includes(this.callable_type)) {\n return this.#callable_object;\n }\n\n return this.prepareForSerialization();\n }\n\n /**\n * Determines the type of the callable (function, step, or workflow).\n * @param {Function|Step|Workflow} callable - The callable to check.\n * @returns {string} The type: 'function', 'step', or 'workflow'.\n * @throws {Error} Throws if callable type is invalid.\n */\n getCallableType(callable) {\n return Step.getCallableType(callable);\n }\n\n /**\n * Determines the type of the callable (function, step, or workflow).\n * @param {Function|Step|Workflow} callable - The callable to check.\n * @returns {string} The type: 'function', 'step', or 'workflow'.\n * @throws {Error} Throws if callable type is invalid.\n */\n static getCallableType(callable) {\n if (callable && callable.base_type === base_types.WORKFLOW) {\n return Step.callable_types.WORKFLOW;\n } else if (callable && callable.base_type === base_types.STEP) {\n return Step.callable_types.STEP;\n } else if (typeof callable === 'function') {\n return Step.callable_types.FUNCTION;\n }\n\n throw new Error('Invalid callable type. Must be one of function, Step, or Workflow.');\n }\n\n /**\n * Registers a Step subclass so hydration can rebuild instances of the correct type.\n * Called as a side effect at the bottom of each step subclass file.\n * @param {typeof Step} StepClass - The Step subclass to register, keyed by its static `step_name`.\n */\n static registerStepClass(StepClass) {\n step_class_registry[StepClass.step_name] = StepClass;\n }\n\n /**\n * Resolves a `step_name` (as stored in `class_name` on a serialized step) to its class.\n * Falls back to the base `Step` class if the name is unknown.\n * @param {string} step_name - The step_name to resolve.\n * @returns {typeof Step} The resolved Step subclass.\n */\n static resolveStepClass(step_name) {\n return step_class_registry[step_name] ?? Step;\n }\n\n /**\n * Serializes a callable-like value (function, Step, or Workflow) into a plain, JSON-safe descriptor.\n * @param {Function|Step|Workflow|null} callable - The callable to serialize.\n * @returns {Object|null} A `{ type, value }` descriptor, or null if no callable was given.\n */\n static serializeCallableField(callable) {\n if (callable === null || callable === undefined) {\n return null;\n }\n\n const type = Step.getCallableType(callable);\n\n if (type === Step.callable_types.FUNCTION) {\n return { type, value: callable.name };\n }\n\n return { type, value: callable.prepareForSerialization() };\n }\n\n /**\n * Hydrates a callable-like descriptor (as produced by `serializeCallableField`) back into a\n * live function, Step, or Workflow. Idempotent - passing an already-hydrated value through\n * returns it unchanged, since subclass `hydrate` overrides may resolve a field before\n * delegating to a superclass `hydrate` that would otherwise try to resolve it again.\n * @param {Object|Function|Step|Workflow|null} serialized - The descriptor (or already-hydrated value) to hydrate.\n * @param {import('../callable_registry.js').default|null} [callable_registry] - Registry used to resolve function callables.\n * @returns {Function|Step|Workflow|undefined} The hydrated callable, or undefined if nothing was given.\n * @throws {Error} Throws if a function callable can't be found in the registry, or the descriptor type is unknown.\n */\n static hydrateCallableField(serialized, callable_registry = null) {\n if (serialized === null || serialized === undefined) {\n return undefined;\n }\n\n if (typeof serialized === 'function' || serialized instanceof Step || serialized?.base_type) {\n return serialized;\n }\n\n const { type, value } = serialized;\n\n if (type === Step.callable_types.FUNCTION) {\n if (!callable_registry || !callable_registry.has(value)) {\n throw new Error(`Callable registry key \"${value}\" not found in registry or registry not provided.`);\n }\n\n return callable_registry.get(value);\n }\n\n if (type === Step.callable_types.STEP) {\n return Step.hydrateAny(value, callable_registry);\n }\n\n if (type === Step.callable_types.WORKFLOW) {\n return Workflow.hydrate(value, callable_registry);\n }\n\n throw new Error(`Unknown callable type \"${type}\" encountered during hydration.`);\n }\n\n /**\n * Hydrates a parsed step object into an instance of its correct Step subclass,\n * resolved from its serialized `class_name`.\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 {Step} The hydrated Step (or subclass) instance.\n */\n static hydrateAny(parsed_step, callable_registry = null) {\n const StepClass = Step.resolveStepClass(parsed_step.class_name);\n\n return StepClass.hydrate(parsed_step, callable_registry);\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 const serialized_step = {\n id: this.id,\n class_name: this.constructor.step_name,\n name: this.name,\n callable_type: this.callable_type,\n step_type: this.step_type,\n sub_step_type: this.sub_step_type,\n max_retries: this.max_retries,\n max_timeout_ms: this.max_timeout_ms,\n retry_count: this.retry_count,\n retry_results: this.retry_results,\n errors: this.errors,\n result: this.result,\n timing: this.timing,\n status: this.status,\n parent_workflow_id: this.parent_workflow_id,\n };\n\n serialized_step.callable = this.callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.callable_registry_key }\n : Step.serializeCallableField(this.#callable_object);\n\n return serialized_step;\n }\n\n /**\n * Sets a value in the parent workflow's state.\n * @param {string} workflow_id - ID of the parent workflow.\n * @param {string} path - Path in the workflow state to set.\n * @param {*} value - Value to set at the specified path.\n * @throws {Error} Throws if parent workflow is not found.\n */\n setParentWorkflowValue(workflow_id, path, value) {\n const parent_workflow = this.getState('workflows')[workflow_id];\n\n if (!parent_workflow) {\n throw new Error(`Parent workflow with ID ${workflow_id} not found.`);\n }\n\n parent_workflow[path] = value;\n }\n\n /**\n * Serializes the step into a JSON string.\n * @returns {string} The JSON string representation of the step.\n */\n serialize() {\n return JSON.stringify(this.prepareForSerialization());\n }\n\n /**\n * Custom JSON serializer\n * @returns {Object} The JSON representation of the step.\n */\n toJSON() {\n return this.prepareForSerialization();\n }\n\n /**\n * Sets the callable for the step and determines its type.\n * @param {Function|Step|Workflow} callable - The callable to set.\n */\n set callable(callable) {\n this.callable_type = this.getCallableType(callable);\n\n if (['step', 'workflow'].includes(this.callable_type)) {\n if (this.callable_type === 'step') {\n callable.parent_workflow_id = this.parent_workflow_id ?? null;\n }\n\n this._callable = callable.execute.bind(callable);\n } else {\n this._callable = callable.bind(this);\n }\n }\n\n /**\n * Deserializes a JSON string into a Step instance and hydrates it, dispatching to the correct subclass.\n * @param {string} serialized_step - The JSON string representation of the step.\n * @param {import('../callable_registry.js').default|null} [callable_registry] - Registry used to resolve function callables.\n * @returns {Step} The hydrated Step (or subclass) instance.\n * @throws {Error} Throws if the serialized step is not a string.\n */\n static hydrateSerialized(serialized_step, callable_registry = null) {\n if (typeof serialized_step !== 'string') {\n throw new Error('Invalid serialized step. Must be a string.');\n }\n\n return Step.hydrateAny(JSON.parse(serialized_step), callable_registry);\n }\n\n /**\n * Hydrates a parsed step object into an instance of `this` class, resolving its callable\n * (and restoring execution metadata) from the serialized data.\n * Subclasses with extra callable-like fields (e.g. ConditionalStep's true_callable/false_callable)\n * should resolve those fields with `Step.hydrateCallableField` and delegate to `super.hydrate()`.\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 {Step} The hydrated Step instance.\n * @throws {Error} Throws if a callable registry key is specified but not found in the registry.\n */\n static hydrate(parsed_step, callable_registry = null) {\n const callable_descriptor = parsed_step.callable;\n const callable = Step.hydrateCallableField(callable_descriptor, callable_registry);\n const callable_registry_key = callable_descriptor?.type === Step.callable_types.FUNCTION\n ? callable_descriptor.value\n : null;\n\n const instance = new this({ ...parsed_step, callable, callable_registry_key });\n\n instance.id = parsed_step.id;\n instance.retry_count = parsed_step.retry_count ?? 0;\n instance.retry_results = parsed_step.retry_results ?? [];\n instance.errors = parsed_step.errors ?? [];\n instance.result = parsed_step.result ?? null;\n instance.timing = parsed_step.timing;\n instance.status = parsed_step.status;\n instance.parent_workflow_id = parsed_step.parent_workflow_id ?? null;\n\n return instance;\n }\n}\n\nStep.registerStepClass(Step);\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAU,aACjB,OAAOC,MAAc,iBACrB,OAAS,cAAAC,EAAY,cAAAC,MAAkB,uBAKvC,MAAMC,EAAsB,CAAC,EAO7B,MAAOC,UAA2BL,CAAK,CAdvC,MAcuC,CAAAM,EAAA,aACrC,OAAO,UAAY,OACnBC,GAAmB,KACnB,OAAO,eAAiB,CACtB,SAAU,WACV,KAAM,OACN,SAAU,UACZ,EAYA,YAAY,CACV,KAAAC,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,sBAAAI,EAAwB,KACxB,YAAAC,EAAc,EACd,eAAAC,EAAiB,IACjB,UAAAC,EAAYV,EAAW,OACvB,cAAAW,EAAgB,IAClB,EAAG,CACD,MAAM,CAAE,KAAAN,EAAM,UAAWN,EAAW,IAAK,CAAC,EAE1C,KAAK,SAAWO,EAGhB,KAAK,sBAAwBC,EAI7B,KAAKH,GAAmBE,EAExB,KAAK,YAAcE,EACnB,KAAK,YAAc,EACnB,KAAK,eAAiBC,EACtB,KAAK,UAAYC,EACjB,KAAK,cAAgBC,EAErB,KAAK,OAAS,CAAC,EACf,KAAK,OAAS,KACd,KAAK,cAAgB,CAAC,EACtB,KAAK,QAAU,IACjB,CAOA,MAAM,SAAU,CACT,KAAK,UACR,KAAK,QAAU,IAAI,QAAQ,CAACC,EAAGC,IAC7B,WACEA,EACA,KAAK,eACL,IA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,CAAC,EACzCM,EAAS,OAASN,EAAY,QAAU,KACxCM,EAAS,OAASN,EAAY,OAC9BM,EAAS,OAASN,EAAY,OAC9BM,EAAS,mBAAqBN,EAAY,oBAAsB,KAEzDM,CACT,CACF,CAEA3B,EAAK,kBAAkBA,CAAI",
|
|
6
|
+
"names": ["Base", "Workflow", "base_types", "step_types", "step_class_registry", "Step", "__name", "#callable_object", "name", "callable", "callable_registry_key", "max_retries", "max_timeout_ms", "step_type", "sub_step_type", "_", "reject", "error", "FAILED", "COMPLETE", "StepClass", "step_name", "type", "serialized", "callable_registry", "value", "parsed_step", "serialized_step", "workflow_id", "path", "parent_workflow", "callable_descriptor", "instance"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var c=(r,e)=>u(r,"name",{value:e,configurable:!0});import s from"./step.js";class l extends s{static{c(this,"SwitchStep")}static step_name="switch";constructor({name:e,cases:a=[],default_callable:t=c(async()=>{},"default_callable"),subject:i=null,default_callable_registry_key:_=null}){super({name:e,step_type:l.step_name}),this.cases=a,this.default_callable_registry_key=_,this._default_callable_type=this.getCallableType(t),this._default_callable_raw=t,this.default_callable=this._default_callable_type==="function"?t.bind(this):t.execute.bind(t),this.subject=i,this.callable=this.switch.bind(this)}async switch(){const e=typeof this.subject=="function"?this.subject():this.subject;for(const t of this.cases)if(t.switch_subject=e,t.parent_workflow_id=this.parent_workflow_id,t.use_state_singleton=this.use_state_singleton,t.state=this.state,await t.checkCondition())return this.log(this.getState("events.step.event_names.SWITCH_CASE_MATCHED"),`Case matched for step: ${this.name}, executing case callable`),(await t.execute()).result;this._default_callable_type!=="function"&&(this._default_callable_raw.parent_workflow_id=this.parent_workflow_id,this._default_callable_raw.use_state_singleton=this.use_state_singleton,this._default_callable_raw.state=this.state);const a=await this.default_callable();return this._default_callable_type!=="function"?a.result:a}prepareForSerialization(){return{...super.prepareForSerialization(),callable:null,cases:this.cases.map(e=>e.prepareForSerialization()),default_callable:this.default_callable_registry_key?{type:s.callable_types.FUNCTION,value:this.default_callable_registry_key}:s.serializeCallableField(this._default_callable_raw),subject:typeof this.subject=="function"?null:this.subject}}static hydrate(e,a=null){const t=e.default_callable;return super.hydrate({...e,cases:(e.cases??[]).map(i=>s.hydrateAny(i,a)),default_callable:s.hydrateCallableField(t,a),default_callable_registry_key:t?.type===s.callable_types.FUNCTION?t.value:null},a)}}l.registerStepClass(l);export{l as default};
|
|
2
2
|
//# sourceMappingURL=switch_step.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/classes/steps/switch_step.js"],
|
|
4
|
-
"sourcesContent": ["import Step from './step.js';\n\n/**\n * SwitchStep class for implementing switch/case logic in workflows.\n * Evaluates cases in order and executes the first matching case, or a default callable if no cases match.\n * @class SwitchStep\n * @extends Step\n */\nexport default class SwitchStep extends Step {\n static step_name = 'switch';\n\n /**\n * Creates a new SwitchStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Array<Case|LogicStep>} [options.cases=[]] - Array of Case or LogicStep instances to evaluate. LogicStep instances MUST have conditional.subject set.\n * @param {Function|Step|Workflow} [options.default_callable=async () => {}] - Function, Step, or Workflow to execute if no cases match.\n * @param {*|Function} [options.subject=null] - Subject value to evaluate against each case. Can be a function that returns the value.\n */\n constructor({\n name,\n cases = [],\n default_callable = async () => {},\n subject = null
|
|
5
|
-
"mappings": "+EAAA,OAAOA,MAAU,YAQjB,MAAOC,UAAiCD,CAAK,CAR7C,MAQ6C,CAAAE,EAAA,mBAC3C,OAAO,UAAY,
|
|
6
|
-
"names": ["Step", "SwitchStep", "__name", "name", "cases", "default_callable", "subject", "
|
|
4
|
+
"sourcesContent": ["import Step from './step.js';\n\n/**\n * SwitchStep class for implementing switch/case logic in workflows.\n * Evaluates cases in order and executes the first matching case, or a default callable if no cases match.\n * @class SwitchStep\n * @extends Step\n */\nexport default class SwitchStep extends Step {\n static step_name = 'switch';\n\n /**\n * Creates a new SwitchStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Array<Case|LogicStep>} [options.cases=[]] - Array of Case or LogicStep instances to evaluate. LogicStep instances MUST have conditional.subject set.\n * @param {Function|Step|Workflow} [options.default_callable=async () => {}] - Function, Step, or Workflow to execute if no cases match.\n * @param {*|Function} [options.subject=null] - Subject value to evaluate against each case. Can be a function that returns the value.\n * @param {string|null} [options.default_callable_registry_key=null] - Optional key to reference default_callable to be rehydrated after serialization.\n */\n constructor({\n name,\n cases = [],\n default_callable = async () => {},\n subject = null,\n default_callable_registry_key = null,\n }) {\n super({\n name,\n step_type: SwitchStep.step_name,\n });\n\n this.cases = cases;\n this.default_callable_registry_key = default_callable_registry_key;\n this._default_callable_type = this.getCallableType(default_callable);\n this._default_callable_raw = default_callable;\n this.default_callable = this._default_callable_type === 'function'\n ? default_callable.bind(this)\n : default_callable.execute.bind(default_callable);\n this.subject = subject;\n\n this.callable = this.switch.bind(this);\n }\n\n /**\n * Executes the switch logic by evaluating each case in order.\n * Returns the result of the first matching case, or the default callable if no match.\n * Every `Case` (and, if it's a `Step`/`Workflow`, `default_callable`) is stamped with this\n * step's own `parent_workflow_id`/`use_state_singleton`/`state` before it runs, since `cases`\n * lives on this step rather than the parent workflow's `_steps`, so it never goes through\n * `Workflow.addStep()` to pick those up on its own.\n * @returns {Promise<*>} The result of the matched case or default callable.\n */\n async switch() {\n // Resolve subject once - call it if it's a function\n const resolved_subject = typeof this.subject === 'function' ? this.subject() : this.subject;\n \n for (const switch_case of this.cases) {\n switch_case.switch_subject = resolved_subject;\n // Cases live in `this.cases`, not the workflow's `_steps` array, so they never go through\n // Workflow.addStep() - stamp them here instead, mirroring what addStep() does.\n switch_case.parent_workflow_id = this.parent_workflow_id;\n switch_case.use_state_singleton = this.use_state_singleton;\n switch_case.state = this.state;\n\n const is_matched = await switch_case.checkCondition();\n\n if (is_matched) {\n this.log(\n this.getState('events.step.event_names.SWITCH_CASE_MATCHED'),\n `Case matched for step: ${this.name}, executing case callable`\n );\n\n // Return the case's result value directly, not the Case object.\n // This keeps result structure consistent: switchStep.result contains the\n // callable's return value, matching how Step.result works.\n const case_result = await switch_case.execute();\n return case_result.result;\n }\n }\n\n // Unwrap Step/Workflow results for consistency with case results\n if (this._default_callable_type !== 'function') {\n this._default_callable_raw.parent_workflow_id = this.parent_workflow_id;\n this._default_callable_raw.use_state_singleton = this.use_state_singleton;\n this._default_callable_raw.state = this.state;\n }\n\n const default_result = await this.default_callable();\n if (this._default_callable_type !== 'function') {\n return default_result.result;\n }\n return default_result;\n }\n\n /**\n * Inserts safely serializable properties of the step into a new object for serialization.\n * Note: a function-valued `subject` is not persisted, since there's no registry for it.\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 `switch` method) -\n // SwitchStep's constructor doesn't take a callable, so it isn't real data to persist.\n callable: null,\n cases: this.cases.map(switch_case => switch_case.prepareForSerialization()),\n default_callable: this.default_callable_registry_key\n ? { type: Step.callable_types.FUNCTION, value: this.default_callable_registry_key }\n : Step.serializeCallableField(this._default_callable_raw),\n subject: typeof this.subject === 'function' ? null : this.subject,\n };\n }\n\n /**\n * Hydrates a parsed step object into a SwitchStep instance, resolving its cases and default callable.\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 {SwitchStep} The hydrated SwitchStep instance.\n */\n static hydrate(parsed_step, callable_registry = null) {\n const default_descriptor = parsed_step.default_callable;\n\n return super.hydrate({\n ...parsed_step,\n cases: (parsed_step.cases ?? []).map(switch_case => Step.hydrateAny(switch_case, callable_registry)),\n default_callable: Step.hydrateCallableField(default_descriptor, callable_registry),\n default_callable_registry_key: default_descriptor?.type === Step.callable_types.FUNCTION\n ? default_descriptor.value\n : null,\n }, callable_registry);\n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CACxB,MAAO,CACL,GAAG,MAAM,wBAAwB,EAGjC,SAAU,KACV,MAAO,KAAK,MAAM,IAAID,GAAeA,EAAY,wBAAwB,CAAC,EAC1E,iBAAkB,KAAK,8BACnB,CAAE,KAAMT,EAAK,eAAe,SAAU,MAAO,KAAK,6BAA8B,EAChFA,EAAK,uBAAuB,KAAK,qBAAqB,EAC1D,QAAS,OAAO,KAAK,SAAY,WAAa,KAAO,KAAK,OAC5D,CACF,CAQA,OAAO,QAAQW,EAAaC,EAAoB,KAAM,CACpD,MAAMC,EAAqBF,EAAY,iBAEvC,OAAO,MAAM,QAAQ,CACnB,GAAGA,EACH,OAAQA,EAAY,OAAS,CAAC,GAAG,IAAIF,GAAeT,EAAK,WAAWS,EAAaG,CAAiB,CAAC,EACnG,iBAAkBZ,EAAK,qBAAqBa,EAAoBD,CAAiB,EACjF,8BAA+BC,GAAoB,OAASb,EAAK,eAAe,SAC5Ea,EAAmB,MACnB,IACN,EAAGD,CAAiB,CACtB,CACF,CAEAX,EAAW,kBAAkBA,CAAU",
|
|
6
|
+
"names": ["Step", "SwitchStep", "__name", "name", "cases", "default_callable", "subject", "default_callable_registry_key", "resolved_subject", "switch_case", "default_result", "parsed_step", "callable_registry", "default_descriptor"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var u=Object.defineProperty;var h=(_,t)=>u(_,"name",{value:t,configurable:!0});import d from"crypto";import m from"./base.js";import f from"./callable_registry.js";import c from"./steps/step.js";import o from"./state.js";import{base_types as w}from"../enums/index.js";class a extends m{static{h(this,"Workflow")}constructor({name:t,callable_registry:s=null,exit_on_error:e=!1,result_per_step:i=!1,result_per_step_function:r=null,steps:n=[],throw_on_empty:p=!1,use_state_singleton:l=!1}){super({name:t,base_type:w.WORKFLOW,use_state_singleton:l}),this.callable_registry=s??new f,this.current_session_id=null,this.exit_on_error=e,this.result_per_step=i,this.sessions={},this.throw_on_empty=p,this.result_per_step_function=r,this._steps=[],this.steps_by_id={},this.addSteps(n),this.initializeWorkflowState()}async execute(){if(this.current_session_id||(this.current_session_id=d.randomUUID()),this.isEmpty()){if(this.throw_on_empty)throw new Error("Cannot execute an empty workflow");return this.markAsComplete(),await this.prepareResult("Workflow is empty",null),this}const t=this.status===this.getState("statuses.workflow").PAUSED,s=this._steps.findIndex(i=>i.id===this.current_step),e=t?s+1:0;this.markAsRunning();for(let i=e;i<this._steps.length;i++){if(this.should_break){this.log(this.getState("event_names.workflow").WORKFLOW_BREAK_EXECUTED,`Workflow "${this.name}" execution broken at step ${this._steps[i].name} - ${this._steps[i].id}.`);break}if(this.should_skip){this.log(this.getState("events.workflow.event_names.WORKFLOW_STEP_SKIPPED"),`Workflow "${this.name}" skipping step ${this._steps[i].name} - ${this._steps[i].id}.`),this.should_skip=!1;continue}this.current_step=this._steps[i].id;try{const r=await this.step();await this.prepareResult("Success",r)}catch(r){if(this.markAsFailed(),await this.prepareResult(`Workflow execution failed at step ${this.steps_by_id[this.current_step].name} - ${this.current_step}`,{error:r}),this.exit_on_error)return this}if(this.should_pause)return this.markAsPaused(),this.should_pause=!1,this}return this.markAsComplete(),this.prepareForSerialization()}async resume(){return this.should_pause=!1,this.timing.resume_time=new Date,this.getState("events.workflow").emit(this.getState("event_names.workflow").WORKFLOW_RESUMED,this.getState()),this.execute()}async step(){const t=this.steps_by_id[this.current_step],s=await t.execute();if(t.status===this.getState("statuses.step.FAILED"))throw t.errors[t.errors.length-1]??new Error(`Step "${t.name}" failed`);return s}addStep(t){if(typeof t.getCallableType!="function")throw new Error("Invalid input. Must be an instance of Step.");Array.isArray(this._steps)||(this._steps=[]),(!this.steps_by_id||typeof this.steps_by_id!="object")&&(this.steps_by_id={}),this.steps_by_id[t.id]=t,t.parent_workflow_id=this.id,t.parent_workflow=this.prepareForSerialization(),t.use_state_singleton=this.use_state_singleton,t.state=this.state,this._steps.push(t)}addStepAtIndex(t,s){(!this.steps_by_id||typeof this.steps_by_id!="object")&&(this.steps_by_id={}),this.steps_by_id[t.id]=t,t.parent_workflow_id=this.id,t.parent_workflow=this.prepareForSerialization(),t.use_state_singleton=this.use_state_singleton,t.state=this.state,this._steps.splice(s,0,t)}addSteps(t){if(!Array.isArray(t))throw new Error("Invalid input. Must be an array of Step instances.");t.forEach(s=>this.addStep(s))}clearSteps(){this._steps=[],this.steps_by_id={}}closeCurrentSession(){this.current_session_id&&(this.sessions[this.current_session_id]={results:[...this.results],status:this.status,timing:{...this.timing},closed_at:new Date},this.current_session_id=null)}deleteStep(t){Array.isArray(this._steps)||(this._steps=[]),this._steps=this._steps.filter(s=>s.id!==t)}deleteStepByIndex(t){Array.isArray(this._steps)||(this._steps=[]),this._steps.splice(t,1)}getStateFromPropertyPath(t,s=!0){return this.use_state_singleton?(console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),o.getFromPropertyPath(t,s)):this.state.getStateFromPropertyPath(t)}initializeWorkflowState(){this.current_step=this.isEmpty()?null:this._steps[0].id,this.results=this.results??[],this.sessions=this.sessions??{},this.should_break=this.should_break??!1,this.should_continue=this.should_continue??!1,this.should_pause=this.should_pause??!1,this.should_skip=this.should_skip??!1,this.status=this.status??this.getState("statuses.workflow").CREATED,this.timing={...this.timing,create_time:this.timing?.create_time??new Date,pause_time:this.timing?.pause_time??null,resume_time:this.timing?.resume_time??null};const t=this.getState("workflows");t[this.id]=this,this.setState("workflows",t),this.log(this.getState("event_names.workflow").WORKFLOW_CREATED,`Workflow "${this.name}" initialized.`)}isEmpty(){return!Array.isArray(this._steps)||!this._steps.length}markAsComplete(){super.markAsComplete(),this.closeCurrentSession()}markAsCreated(){return this.timing.create_time=new Date,this.log(this.getState("event_names.workflow").WORKFLOW_CREATED,`Workflow "${this.name}" created.`),this.getState("statuses.workflow").CREATED}markAsFailed(){super.markAsFailed(),this.closeCurrentSession()}markAsPaused(){this.timing.pause_time=new Date,this.status=this.getState("statuses.workflow").PAUSED,this.getState("events.workflow").emit(this.getState("event_names.workflow").WORKFLOW_PAUSED,this.getState())}markAsResumed(){this.timing.resume_time=new Date,this.status=this.getState("statuses.workflow").RUNNING,this.getState("events.workflow").emit(this.getState("event_names.workflow").WORKFLOW_RESUMED,this.getState())}moveStep(t,s){const[e]=this._steps.splice(t,1);this._steps.splice(s,0,e),this.getState("events.workflow").emit(this.getState("event_names.workflow").WORKFLOW_STEP_MOVED,this.getState())}parseStatePath(t){return this.use_state_singleton?o.parsePath(t):this.state.parseStatePath(t)}pause(){this.should_pause=!0,this.timing.pause_time=new Date,this.getState("events.workflow").emit(this.getState("event_names.workflow").WORKFLOW_PAUSED,this.getState())}popStep(){return this._steps.pop()}prepareForSerialization(){return{id:this.id,current_session_id:this.current_session_id,current_step:this.current_step,exit_on_error:this.exit_on_error,name:this.name,sessions:this.sessions,status:this.status,steps:this._steps.map(s=>s.prepareForSerialization()),throw_on_empty:this.throw_on_empty,timing:this.timing,results:this.results,use_state_singleton:this.use_state_singleton}}async prepareResult(t,s){this.result_per_step&&typeof this.result_per_step_function=="function"&&await this.result_per_step_function(this.prepareForSerialization());const e={message:t,data:s};this.results.push(e)}pushStep(t){this.addStep(t)}pushSteps(t){t.forEach(s=>this.addStep(s))}serialize(){return JSON.stringify(this.prepareForSerialization())}setStateToPropertyPath(t,s,e=!0){if(this.use_state_singleton){console.warn("The state singleton has been deprecated. Use the .prepareForSerialization() method on the workflow instance instead."),o.setToPropertyPath(t,s,e);return}this.state.setStateToPropertyPath(t,s)}shiftStep(){return this._steps.shift()}unshiftStep(t){if(typeof t.getCallableType!="function")throw new Error("Invalid step type. Must be an instance of Step.");(!this.steps_by_id||typeof this.steps_by_id!="object")&&(this.steps_by_id={}),this.steps_by_id[t.id]=t,t.parent_workflow_id=this.id,t.use_state_singleton=this.use_state_singleton,t.state=this.state,this._steps.unshift(t)}toJSON(){return this.prepareForSerialization()}get steps(){return this._steps}set steps(t){this.addSteps(t)}static hydrateSerialized(t,s=null){if(typeof t!="string")throw new Error("Invalid serialized workflow. Must be a string.");const e=JSON.parse(t);return a.hydrate(e,s)}static hydrate(t,s=null){if(typeof t!="object"||t===null)throw new Error("Invalid parsed workflow. Must be a valid object.");const e=new a({name:t.name,callable_registry:s,exit_on_error:t.exit_on_error,steps:t.steps.map(n=>c.hydrateAny(n,s)),throw_on_empty:t.throw_on_empty,use_state_singleton:t.use_state_singleton??!1}),i=e.id;e.id=t.id;const r=e.getState("workflows");return delete r[i],r[e.id]=e,e.setState("workflows",r),e.steps.forEach(n=>{n.parent_workflow_id=e.id}),e.current_session_id=t.current_session_id,e.current_step=t.current_step??e.current_step,e.sessions=t.sessions??{},e.status=t.status,e.timing=t.timing,e.results=t.results,e}}export{a as default};
|
|
2
2
|
//# sourceMappingURL=workflow.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/classes/workflow.js"],
|
|
4
|
-
"sourcesContent": ["import crypto from 'crypto';\nimport Base from './base.js';\nimport { base_types } from '../enums/index.js';\n\n/**\n * Workflow class for managing and executing a sequence of steps.\n * @class Workflow\n * @extends Base\n */\nexport default class Workflow extends Base {\n /**\n * Creates a new Workflow instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the workflow.\n * @param {boolean} [options.exit_on_error=false] - Whether to exit on error.\n * @param {Array<Step>} [options.steps=[]] - Array of steps to add to the workflow.\n * @param {boolean} [options.throw_on_empty=false] - Whether to throw error if workflow is empty.\n */\n constructor({\n name,\n exit_on_error = false,\n steps = [],\n throw_on_empty = false\n }) {\n super({ name, base_type: base_types.WORKFLOW });\n\n this.initializeWorkflowState();\n\n this.addSteps(steps);\n\n this.exit_on_error = exit_on_error;\n this.throw_on_empty = throw_on_empty;\n this.sessions = {};\n this.current_session_id = null;\n }\n\n /**\n * Executes the workflow by running all steps in sequence.\n * @async\n * @returns {Promise<Workflow>} The workflow instance with execution results.\n * @throws {Error} Throws if workflow is empty and throw_on_empty is true.\n */\n async execute() {\n if (!this.current_session_id) {\n this.current_session_id = crypto.randomUUID();\n }\n\n if (this.isEmpty()) {\n if (this.throw_on_empty) {\n throw new Error('Cannot execute an empty workflow');\n }\n\n this.markAsComplete();\n this.prepareResult('Workflow is empty', null);\n return this;\n }\n \n this.markAsRunning();\n\n for (let i = 0; i < this._steps.length; i++) {\n if (this.should_break) {\n this.log(this.getState('event_names.workflow').WORKFLOW_BREAK_EXECUTED, `Workflow \"${this.name}\" execution broken at step ${this._steps[i].name} - ${this._steps[i].id}.`);\n break;\n }\n\n if (this.should_skip) {\n this.log(\n this.getState('events.workflow.event_names.WORKFLOW_STEP_SKIPPED'),\n `Workflow \"${this.name}\" skipping step ${this._steps[i].name} - ${this._steps[i].id}.`\n );\n this.should_skip = false;\n continue;\n }\n\n this.current_step = this._steps[i].id;\n\n try {\n const step_result = await this.step();\n this.prepareResult('Success', step_result);\n } catch (error) {\n this.markAsFailed();\n this.prepareResult(`Workflow execution failed at step ${this.steps_by_id[this.current_step].name} - ${this.current_step}`, { error });\n \n if (this.exit_on_error) {\n return this;\n }\n }\n\n if (this.should_pause) {\n this.markAsPaused();\n this.should_pause = false;\n return this;\n }\n }\n\n this.markAsComplete();\n return this;\n }\n\n /**\n * Resumes a paused workflow.\n * @async\n * @returns {Promise<Workflow>} The workflow instance.\n */\n async resume() {\n this.should_pause = false;\n this.timing.resume_time = new Date();\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_RESUMED,\n this.getState()\n );\n return this.execute();\n }\n\n /**\n * Executes a single step in the workflow.\n * @async\n * @returns {Promise<*>} The result of the step execution.\n */\n async step() {\n const step = this.steps_by_id[this.current_step];\n\n step.parentWorkflowId = this.id;\n const result = await step.execute();\n\n if (step.status === this.getState('statuses.step.FAILED')) {\n throw step.errors[step.errors.length - 1] ?? new Error(`Step \"${step.name}\" failed`);\n }\n\n return result;\n }\n\n /**\n * Adds a step to the workflow.\n * @param {Step} step - The step to add.\n * @throws {Error} Throws if step is not a valid Step instance.\n */\n addStep(step) {\n if (typeof step.getCallableType !== 'function') {\n throw new Error('Invalid step type. Must be an instance of Step.');\n }\n\n if (!Array.isArray(this._steps)) {\n this._steps = [];\n }\n\n if (!this.steps_by_id || typeof this.steps_by_id !== 'object') {\n this.steps_by_id = {};\n }\n\n this.steps_by_id[step.id] = step;\n\n step.parentWorkflowId = this.id;\n this._steps.push(step);\n }\n\n /**\n * Adds a step at a specific index in the workflow.\n * @param {Step} step - The step to add.\n * @param {number} index - The index at which to insert the step.\n */\n addStepAtIndex(step, index) {\n if (!this.steps_by_id || typeof this.steps_by_id !== 'object') {\n this.steps_by_id = {};\n }\n\n this.steps_by_id[step.id] = step;\n step.parentWorkflowId = this.id;\n this._steps.splice(index, 0, step);\n }\n\n /**\n * Adds multiple steps to the workflow.\n * @param {Step[]} steps - Array of steps to add.\n */\n addSteps(steps) {\n steps.forEach(step => this.addStep(step));\n }\n\n /**\n * Clears all steps from the workflow.\n */\n clearSteps() {\n this._steps = [];\n }\n\n /**\n * Closes the current session and stores a snapshot of the workflow state.\n */\n closeCurrentSession() {\n if (!this.current_session_id) {\n return;\n }\n\n this.sessions[this.current_session_id] = {\n results: [...this.results],\n status: this.status,\n timing: { ...this.timing },\n closed_at: new Date()\n };\n this.current_session_id = null;\n }\n\n /**\n * Deletes a step from the workflow by its ID.\n * @param {string} stepId - The ID of the step to delete.\n */\n deleteStep(stepId) {\n this._steps = this._steps.filter(step => step.id !== stepId);\n }\n\n /**\n * Deletes a step from the workflow by its index.\n * @param {number} index - The index of the step to delete.\n */\n deleteStepByIndex(index) {\n this._steps.splice(index, 1);\n }\n\n /**\n * Initializes the workflow state with default values.\n */\n initializeWorkflowState() {\n this.results = [];\n this.exit_on_error = false;\n this.current_step = null;\n this.should_break = false;\n this.should_continue = false;\n this.should_pause = false;\n this.should_skip = false;\n this.status = this.getState('statuses.workflow').CREATED;\n this._steps = [];\n this.throw_on_empty = this.throw_on_empty;\n this.timing = {\n ...this.timing,\n create_time: new Date(),\n pause_time: null,\n resume_time: null,\n }\n\n const workflows = this.getState('workflows');\n workflows[this.id] = this;\n this.setState('workflows', workflows);\n\n this.log(\n this.getState('event_names.workflow').WORKFLOW_CREATED,\n `Workflow \"${this.name}\" initialized.`\n );\n }\n\n /**\n * Checks if the workflow has no steps.\n * @returns {boolean} True if the workflow is empty.\n */\n isEmpty() {\n return !this._steps || !this._steps.length\n }\n\n /**\n * Marks the workflow as complete and closes the current session.\n */\n markAsComplete() {\n super.markAsComplete();\n this.closeCurrentSession();\n }\n\n /**\n * Marks the workflow as created.\n * @returns {string} The CREATED status.\n */\n markAsCreated() {\n this.timing.create_time = new Date();\n \n this.log(\n this.getState('event_names.workflow').WORKFLOW_CREATED,\n `Workflow \"${this.name}\" created.`\n );\n\n return this.getState('statuses.workflow').CREATED;\n }\n\n /**\n * Marks the workflow as failed and closes the current session.\n */\n markAsFailed() {\n super.markAsFailed();\n this.closeCurrentSession();\n }\n\n /**\n * Marks the workflow as paused.\n */\n markAsPaused() {\n this.timing.pause_time = new Date();\n this.status = this.getState('statuses.workflow').PAUSED;\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_PAUSED,\n this.getState()\n );\n }\n \n /**\n * Marks the workflow as resumed.\n */\n markAsResumed() {\n this.timing.resume_time = new Date();\n this.status = this.getState('statuses.workflow').RUNNING;\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_RESUMED,\n this.getState()\n );\n }\n\n /**\n * Moves a step from one index to another.\n * @param {number} fromIndex - The current index of the step.\n * @param {number} toIndex - The target index for the step.\n */\n moveStep(fromIndex, toIndex) {\n const [step] = this._steps.splice(fromIndex, 1);\n this._steps.splice(toIndex, 0, step);\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_STEP_MOVED,\n this.getState()\n );\n }\n\n /**\n * Pauses the workflow execution.\n */\n pause() {\n this.should_pause = true;\n this.timing.pause_time = new Date();\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_PAUSED,\n this.getState()\n );\n }\n\n /**\n * Removes and returns the last step from the workflow.\n * @returns {Step} The last step.\n */\n popStep() {\n return this._steps.pop();\n }\n\n /**\n * Prepares a result object and adds it to the results array.\n * @param {string} message - Result message.\n * @param {*} data - Result data.\n */\n prepareResult(message, data) {\n this.results.push({ message, data });\n }\n\n /**\n * Adds a step to the end of the workflow.\n * @param {Step} step - The step to add.\n */\n pushStep(step) {\n this.addStep(step);\n }\n\n /**\n * Adds multiple steps to the end of the workflow.\n * @param {Step[]} steps - Array of steps to add.\n */\n pushSteps(steps) {\n steps.forEach(step => this.addStep(step));\n }\n\n /**\n * Removes and returns the first step from the workflow.\n * @returns {Step} The first step.\n */\n shiftStep() {\n return this._steps.shift();\n }\n\n /**\n * Adds a step to the beginning of the workflow.\n * @param {Step} step - The step to add.\n * @throws {Error} Throws if step is not a valid Step instance.\n */\n unshiftStep(step) {\n if (typeof step.getCallableType !== 'function') {\n throw new Error('Invalid step type. Must be an instance of Step.');\n }\n\n if (!this.steps_by_id || typeof this.steps_by_id !== 'object') {\n this.steps_by_id = {};\n }\n\n this.steps_by_id[step.id] = step;\n\n step.parentWorkflowId = this.id;\n this._steps.unshift(step);\n }\n\n /**\n * Gets the array of steps in the workflow.\n * @returns {Step[]} Array of steps.\n */\n get steps() {\n return this._steps;\n }\n\n /**\n * Sets the steps array by adding multiple steps.\n * @param {Step[]} steps - Array of steps to add.\n */\n set steps(steps) {\n steps.forEach((step, index) => {\n if (typeof step.getCallableType !== 'function') {\n throw new Error(`Invalid step type. Step at index ${index} is not an instance of Step.`);\n }\n });\n\n this.addSteps(steps);\n }\n}\n"],
|
|
5
|
-
"mappings": "+EAAA,OAAOA,MAAY,SACnB,OAAOC,MAAU,YACjB,OAAS,cAAAC,MAAkB,oBAO3B,MAAOC,UAA+
|
|
6
|
-
"names": ["crypto", "Base", "base_types", "Workflow", "__name", "name", "exit_on_error", "steps", "throw_on_empty", "
|
|
4
|
+
"sourcesContent": ["import crypto from 'crypto';\nimport Base from './base.js';\nimport CallableRegistry from './callable_registry.js';\nimport Step from './steps/step.js';\nimport State from './state.js';\nimport { base_types } from '../enums/index.js';\n\n/**\n * Workflow class for managing and executing a sequence of steps.\n * @class Workflow\n * @extends Base\n */\nexport default class Workflow extends Base {\n /**\n * Creates a new Workflow instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the workflow.\n * @param {CallableRegistry|null} [options.callable_registry=null] - Registry for callable objects.\n * @param {boolean} [options.exit_on_error=false] - Whether to exit on error.\n * @param {Array<Step>} [options.steps=[]] - Array of steps to add to the workflow.\n * @param {boolean} [options.throw_on_empty=false] - Whether to throw error if workflow is empty.\n * @param {boolean} [options.use_state_singleton=false] - Deprecated. When true, this workflow (and every\n * `Step` it owns) reads/writes `getState`/`setState`/`deleteState` calls through the process-wide `State`\n * singleton instead of this workflow's own state.\n */\n constructor({\n name,\n callable_registry = null,\n exit_on_error = false,\n result_per_step = false,\n result_per_step_function = null,\n steps = [],\n throw_on_empty = false,\n use_state_singleton = false,\n }) {\n super({ name, base_type: base_types.WORKFLOW, use_state_singleton });\n\n this.callable_registry = callable_registry ?? new CallableRegistry();\n this.current_session_id = null;\n this.exit_on_error = exit_on_error;\n this.result_per_step = result_per_step;\n this.sessions = {};\n this.throw_on_empty = throw_on_empty;\n this.result_per_step_function = result_per_step_function;\n\n // _steps/steps_by_id must exist before initializeWorkflowState(): it reads this._steps\n // (to set current_step) and logs, which serializes `this` - both need this._steps to\n // already be an array, even when no steps are passed (addSteps([]) never calls addStep,\n // so it wouldn't otherwise get initialized).\n this._steps = [];\n this.steps_by_id = {};\n this.addSteps(steps);\n this.initializeWorkflowState();\n }\n\n /**\n * Executes the workflow by running all steps in sequence.\n * If the workflow is currently `paused`, resumes from the step after the one\n * that was running when it paused, rather than starting over from the beginning.\n * @async\n * @returns {Promise<Workflow>} The workflow instance with execution results.\n * @throws {Error} Throws if workflow is empty and throw_on_empty is true.\n */\n async execute() {\n if (!this.current_session_id) {\n this.current_session_id = crypto.randomUUID();\n }\n\n if (this.isEmpty()) {\n if (this.throw_on_empty) {\n throw new Error('Cannot execute an empty workflow');\n }\n\n this.markAsComplete();\n await this.prepareResult('Workflow is empty', null);\n return this;\n }\n\n const is_resuming = this.status === this.getState('statuses.workflow').PAUSED;\n const paused_at_index = this._steps.findIndex(step => step.id === this.current_step);\n const start_index = is_resuming ? paused_at_index + 1 : 0;\n\n this.markAsRunning();\n\n for (let i = start_index; i < this._steps.length; i++) {\n if (this.should_break) {\n this.log(this.getState('event_names.workflow').WORKFLOW_BREAK_EXECUTED, `Workflow \"${this.name}\" execution broken at step ${this._steps[i].name} - ${this._steps[i].id}.`);\n break;\n }\n\n if (this.should_skip) {\n this.log(\n this.getState('events.workflow.event_names.WORKFLOW_STEP_SKIPPED'),\n `Workflow \"${this.name}\" skipping step ${this._steps[i].name} - ${this._steps[i].id}.`\n );\n this.should_skip = false;\n continue;\n }\n\n this.current_step = this._steps[i].id;\n\n try {\n const step_result = await this.step();\n await this.prepareResult('Success', step_result);\n } catch (error) {\n this.markAsFailed();\n await this.prepareResult(`Workflow execution failed at step ${this.steps_by_id[this.current_step].name} - ${this.current_step}`, { error });\n \n if (this.exit_on_error) {\n return this;\n }\n }\n\n if (this.should_pause) {\n this.markAsPaused();\n this.should_pause = false;\n return this;\n }\n }\n\n this.markAsComplete();\n return this.prepareForSerialization();\n }\n\n /**\n * Resumes a paused workflow.\n * @async\n * @returns {Promise<Workflow>} The workflow instance.\n */\n async resume() {\n this.should_pause = false;\n this.timing.resume_time = new Date();\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_RESUMED,\n this.getState()\n );\n return this.execute();\n }\n\n /**\n * Executes a single step in the workflow.\n * @async\n * @returns {Promise<*>} The result of the step execution.\n */\n async step() {\n const step = this.steps_by_id[this.current_step];\n\n const result = await step.execute();\n\n if (step.status === this.getState('statuses.step.FAILED')) {\n throw step.errors[step.errors.length - 1] ?? new Error(`Step \"${step.name}\" failed`);\n }\n\n return result;\n }\n\n /**\n * Adds a step to the workflow.\n * @param {Step} step - The step to add.\n * @throws {Error} Throws if step is not a valid Step instance.\n */\n addStep(step) {\n // This check only ensures that the getCallableType method exists,\n // which is a characteristic of Step instances\n if (typeof step.getCallableType !== 'function') {\n throw new Error('Invalid input. Must be an instance of Step.');\n }\n\n if (!Array.isArray(this._steps)) {\n this._steps = [];\n }\n\n if (!this.steps_by_id || typeof this.steps_by_id !== 'object') {\n this.steps_by_id = {};\n }\n\n this.steps_by_id[step.id] = step;\n\n step.parent_workflow_id = this.id;\n step.parent_workflow = this.prepareForSerialization();\n step.use_state_singleton = this.use_state_singleton;\n step.state = this.state;\n this._steps.push(step);\n }\n\n /**\n * Adds a step at a specific index in the workflow.\n * @param {Step} step - The step to add.\n * @param {number} index - The index at which to insert the step.\n */\n addStepAtIndex(step, index) {\n if (!this.steps_by_id || typeof this.steps_by_id !== 'object') {\n this.steps_by_id = {};\n }\n\n this.steps_by_id[step.id] = step;\n step.parent_workflow_id = this.id;\n step.parent_workflow = this.prepareForSerialization();\n step.use_state_singleton = this.use_state_singleton;\n step.state = this.state;\n this._steps.splice(index, 0, step);\n }\n\n /**\n * Adds multiple steps to the workflow.\n * @param {Step[]} steps - Array of steps to add.\n */\n addSteps(steps) {\n if (!Array.isArray(steps)) {\n throw new Error('Invalid input. Must be an array of Step instances.');\n }\n\n steps.forEach(step => this.addStep(step));\n }\n\n /**\n * Clears all steps from the workflow.\n */\n clearSteps() {\n this._steps = [];\n this.steps_by_id = {};\n }\n\n /**\n * Closes the current session and stores a snapshot of the workflow state.\n */\n closeCurrentSession() {\n if (!this.current_session_id) {\n return;\n }\n\n this.sessions[this.current_session_id] = {\n results: [...this.results],\n status: this.status,\n timing: { ...this.timing },\n closed_at: new Date()\n };\n this.current_session_id = null;\n }\n\n /**\n * Deletes a step from the workflow by its ID.\n * @param {string} stepId - The ID of the step to delete.\n */\n deleteStep(stepId) {\n if (!Array.isArray(this._steps)) {\n this._steps = [];\n }\n\n this._steps = this._steps.filter(step => step.id !== stepId);\n }\n\n /**\n * Deletes a step from the workflow by its index.\n * @param {number} index - The index of the step to delete.\n */\n deleteStepByIndex(index) {\n if (!Array.isArray(this._steps)) {\n this._steps = [];\n }\n\n this._steps.splice(index, 1);\n }\n\n /**\n * Resolves a nested property path within this workflow's own state - the low-level counterpart\n * to `getState()`. Falls back to the deprecated `State` singleton's resolver when\n * `use_state_singleton` is `true`.\n * @param {string} path - Path to the state property.\n * @param {boolean} [emit=true] - Only meaningful when `use_state_singleton` is `true`; whether\n * to emit the singleton's `GET_FROM_PROPERTY_PATH` state event.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\n getStateFromPropertyPath(path, emit = true) {\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.getFromPropertyPath(path, emit);\n }\n\n return this.state.getStateFromPropertyPath(path);\n }\n\n /**\n * Initializes the workflow state with default values.\n */\n initializeWorkflowState() {\n this.current_step = ! this.isEmpty() ? this._steps[0].id : null;\n this.results = this.results ?? [];\n this.sessions = this.sessions ?? {};\n this.should_break = this.should_break ?? false;\n this.should_continue = this.should_continue ?? false;\n this.should_pause = this.should_pause ?? false;\n this.should_skip = this.should_skip ?? false;\n this.status = this.status ?? this.getState('statuses.workflow').CREATED;\n this.timing = {\n ...this.timing,\n create_time: this.timing?.create_time ?? new Date(),\n pause_time: this.timing?.pause_time ?? null,\n resume_time: this.timing?.resume_time ?? null,\n }\n\n const workflows = this.getState('workflows');\n workflows[this.id] = this;\n this.setState('workflows', workflows);\n\n this.log(\n this.getState('event_names.workflow').WORKFLOW_CREATED,\n `Workflow \"${this.name}\" initialized.`\n );\n }\n\n /**\n * Checks if the workflow has no steps.\n * @returns {boolean} True if the workflow is empty.\n */\n isEmpty() {\n return !Array.isArray(this._steps) || !this._steps.length;\n }\n\n /**\n * Marks the workflow as complete and closes the current session.\n */\n markAsComplete() {\n super.markAsComplete();\n this.closeCurrentSession();\n }\n\n /**\n * Marks the workflow as created.\n * @returns {string} The CREATED status.\n */\n markAsCreated() {\n this.timing.create_time = new Date();\n \n this.log(\n this.getState('event_names.workflow').WORKFLOW_CREATED,\n `Workflow \"${this.name}\" created.`\n );\n\n return this.getState('statuses.workflow').CREATED;\n }\n\n /**\n * Marks the workflow as failed and closes the current session.\n */\n markAsFailed() {\n super.markAsFailed();\n this.closeCurrentSession();\n }\n\n /**\n * Marks the workflow as paused.\n */\n markAsPaused() {\n this.timing.pause_time = new Date();\n this.status = this.getState('statuses.workflow').PAUSED;\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_PAUSED,\n this.getState()\n );\n }\n \n /**\n * Marks the workflow as resumed.\n */\n markAsResumed() {\n this.timing.resume_time = new Date();\n this.status = this.getState('statuses.workflow').RUNNING;\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_RESUMED,\n this.getState()\n );\n }\n\n /**\n * Moves a step from one index to another.\n * @param {number} fromIndex - The current index of the step.\n * @param {number} toIndex - The target index for the step.\n */\n moveStep(fromIndex, toIndex) {\n const [step] = this._steps.splice(fromIndex, 1);\n this._steps.splice(toIndex, 0, step);\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_STEP_MOVED,\n this.getState()\n );\n }\n\n /**\n * Parses a property path string into an array of keys, supporting both dot notation and\n * bracket notation (e.g. `\"users[0].name\"`). Pure utility - not affected by `use_state_singleton`.\n * @param {string} path - The path to parse.\n * @returns {string[]} Array of property keys.\n */\n parseStatePath(path) {\n return this.use_state_singleton ? State.parsePath(path) : this.state.parseStatePath(path);\n }\n\n /**\n * Pauses the workflow execution.\n */\n pause() {\n this.should_pause = true;\n this.timing.pause_time = new Date();\n\n this.getState('events.workflow').emit(\n this.getState('event_names.workflow').WORKFLOW_PAUSED,\n this.getState()\n );\n }\n\n /**\n * Removes and returns the last step from the workflow.\n * @returns {Step} The last step.\n */\n popStep() {\n return this._steps.pop();\n }\n\n /**\n * Inserts safely serializable properties of the workflow into a new object for serialization.\n * @returns {Object} An object containing the workflow's properties ready for serialization.\n */\n prepareForSerialization() {\n const serialized_workflow = {\n id: this.id,\n current_session_id: this.current_session_id,\n current_step: this.current_step,\n exit_on_error: this.exit_on_error,\n name: this.name,\n sessions: this.sessions,\n status: this.status,\n steps: this._steps.map(step => step.prepareForSerialization()),\n throw_on_empty: this.throw_on_empty,\n timing: this.timing,\n results: this.results,\n use_state_singleton: this.use_state_singleton,\n };\n\n return serialized_workflow;\n }\n\n /**\n * Prepares a result object and adds it to the results array.\n * @param {string} message - Result message.\n * @param {*} data - Result data.\n */\n async prepareResult(message, data) {\n if (this.result_per_step && typeof this.result_per_step_function === 'function') {\n await this.result_per_step_function(this.prepareForSerialization());\n }\n\n const result = { message, data };\n this.results.push(result);\n }\n\n /**\n * Adds a step to the end of the workflow.\n * @param {Step} step - The step to add.\n */\n pushStep(step) {\n this.addStep(step);\n }\n\n /**\n * Adds multiple steps to the end of the workflow.\n * @param {Step[]} steps - Array of steps to add.\n */\n pushSteps(steps) {\n steps.forEach(step => this.addStep(step));\n }\n\n /**\n * Serializes the workflow into a JSON string.\n * @returns {string} The JSON string representation of the workflow.\n */\n serialize() {\n return JSON.stringify(this.prepareForSerialization());\n }\n\n /**\n * Sets a nested property value within this workflow's own state, creating intermediate\n * objects/arrays as needed - the low-level counterpart to `setState()`. Falls back to the\n * deprecated `State` singleton's setter when `use_state_singleton` is `true`.\n * @param {string} path - Path to the state property.\n * @param {*} value - The value to set at the specified path.\n * @param {boolean} [emit=true] - Only meaningful when `use_state_singleton` is `true`; whether\n * to emit the singleton's `SET_TO_PROPERTY_PATH` state event.\n */\n setStateToPropertyPath(path, value, emit = true) {\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.setToPropertyPath(path, value, emit);\n return;\n }\n\n this.state.setStateToPropertyPath(path, value);\n }\n\n /**\n * Removes and returns the first step from the workflow.\n * @returns {Step} The first step.\n */\n shiftStep() {\n return this._steps.shift();\n }\n\n /**\n * Adds a step to the beginning of the workflow.\n * @param {Step} step - The step to add.\n * @throws {Error} Throws if step is not a valid Step instance.\n */\n unshiftStep(step) {\n if (typeof step.getCallableType !== 'function') {\n throw new Error('Invalid step type. Must be an instance of Step.');\n }\n\n if (!this.steps_by_id || typeof this.steps_by_id !== 'object') {\n this.steps_by_id = {};\n }\n\n this.steps_by_id[step.id] = step;\n\n step.parent_workflow_id = this.id;\n step.use_state_singleton = this.use_state_singleton;\n step.state = this.state;\n this._steps.unshift(step);\n }\n\n /**\n * Custom JSON serializer\n * @returns {Object} The JSON representation of the workflow.\n */\n toJSON() {\n return this.prepareForSerialization();\n }\n\n /**\n * Gets the array of steps in the workflow.\n * @returns {Step[]} Array of steps.\n */\n get steps() {\n return this._steps;\n }\n\n /**\n * Sets the steps array by adding multiple steps.\n * @param {Step[]} steps - Array of steps to add.\n */\n set steps(steps) {\n this.addSteps(steps);\n }\n\n /**\n * Deserializes a JSON string into a Workflow instance and hydrates it.\n * @param {string} serialized_workflow - The JSON string representation of the workflow.\n * @param {CallableRegistry|null} [callable_registry] - Registry used to resolve function callables in the workflow's steps.\n * @returns {Workflow} The hydrated Workflow instance.\n * @throws {Error} Throws if the serialized workflow is not a string.\n */\n static hydrateSerialized(serialized_workflow, callable_registry = null) {\n // TODO: Validate structure of serialized workflow\n if (typeof serialized_workflow !== 'string') {\n throw new Error('Invalid serialized workflow. Must be a string.');\n }\n\n const parsed = JSON.parse(serialized_workflow);\n\n return Workflow.hydrate(parsed, callable_registry);\n }\n\n /**\n * Hydrates a parsed workflow object into a Workflow instance.\n * @param {Object} parsed_workflow - The parsed workflow object.\n * @param {CallableRegistry|null} [callable_registry] - Registry used to resolve function callables in the workflow's steps.\n * @returns {Workflow} The hydrated Workflow instance.\n * @throws {Error} Throws if the parsed workflow is not a valid object.\n */\n static hydrate(parsed_workflow, callable_registry = null) {\n // TODO: Validate structure of serialized workflow\n // TODO: Use event system to handle errors?\n if (typeof parsed_workflow !== 'object' || parsed_workflow === null) {\n throw new Error('Invalid parsed workflow. Must be a valid object.');\n }\n\n const hydrated_workflow = new Workflow({\n name: parsed_workflow.name,\n callable_registry,\n exit_on_error: parsed_workflow.exit_on_error,\n steps: parsed_workflow.steps.map(step => Step.hydrateAny(step, callable_registry)),\n throw_on_empty: parsed_workflow.throw_on_empty,\n use_state_singleton: parsed_workflow.use_state_singleton ?? false,\n });\n\n // The constructor above (via Base) always generates a fresh id, and addStep() has\n // already stamped that fresh id onto each step's parent_workflow_id and registered\n // the workflow under it in its own state's `workflows` registry. Restoring the real id\n // below would otherwise leave both of those referencing a discarded id, so fix them up here too.\n const stale_id = hydrated_workflow.id;\n hydrated_workflow.id = parsed_workflow.id;\n\n const workflows = hydrated_workflow.getState('workflows');\n delete workflows[stale_id];\n workflows[hydrated_workflow.id] = hydrated_workflow;\n hydrated_workflow.setState('workflows', workflows);\n\n hydrated_workflow.steps.forEach(step => {\n step.parent_workflow_id = hydrated_workflow.id;\n });\n\n hydrated_workflow.current_session_id = parsed_workflow.current_session_id;\n hydrated_workflow.current_step = parsed_workflow.current_step ?? hydrated_workflow.current_step;\n hydrated_workflow.sessions = parsed_workflow.sessions ?? {};\n hydrated_workflow.status = parsed_workflow.status;\n hydrated_workflow.timing = parsed_workflow.timing;\n hydrated_workflow.results = parsed_workflow.results;\n\n return hydrated_workflow;\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAY,SACnB,OAAOC,MAAU,YACjB,OAAOC,MAAsB,yBAC7B,OAAOC,MAAU,kBACjB,OAAOC,MAAW,aAClB,OAAS,cAAAC,MAAkB,oBAO3B,MAAOC,UAA+BL,CAAK,CAZ3C,MAY2C,CAAAM,EAAA,iBAazC,YAAY,CACV,KAAAC,EACA,kBAAAC,EAAoB,KACpB,cAAAC,EAAgB,GAChB,gBAAAC,EAAkB,GAClB,yBAAAC,EAA2B,KAC3B,MAAAC,EAAQ,CA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BAAA1B,EACA,cAAe0B,EAAgB,cAC/B,MAAOA,EAAgB,MAAM,IAAIjB,GAAQf,EAAK,WAAWe,EAAMT,CAAiB,CAAC,EACjF,eAAgB0B,EAAgB,eAChC,oBAAqBA,EAAgB,qBAAuB,EAC9D,CAAC,EAMKE,EAAWD,EAAkB,GACnCA,EAAkB,GAAKD,EAAgB,GAEvC,MAAMR,EAAYS,EAAkB,SAAS,WAAW,EACxD,cAAOT,EAAUU,CAAQ,EACzBV,EAAUS,EAAkB,EAAE,EAAIA,EAClCA,EAAkB,SAAS,YAAaT,CAAS,EAEjDS,EAAkB,MAAM,QAAQlB,GAAQ,CACtCA,EAAK,mBAAqBkB,EAAkB,EAC9C,CAAC,EAEDA,EAAkB,mBAAqBD,EAAgB,mBACvDC,EAAkB,aAAeD,EAAgB,cAAgBC,EAAkB,aACnFA,EAAkB,SAAWD,EAAgB,UAAY,CAAC,EAC1DC,EAAkB,OAASD,EAAgB,OAC3CC,EAAkB,OAASD,EAAgB,OAC3CC,EAAkB,QAAUD,EAAgB,QAErCC,CACT,CACF",
|
|
6
|
+
"names": ["crypto", "Base", "CallableRegistry", "Step", "State", "base_types", "Workflow", "__name", "name", "callable_registry", "exit_on_error", "result_per_step", "result_per_step_function", "steps", "throw_on_empty", "use_state_singleton", "is_resuming", "paused_at_index", "step", "start_index", "step_result", "error", "result", "index", "stepId", "path", "emit", "workflows", "fromIndex", "toIndex", "message", "data", "value", "serialized_workflow", "parsed", "parsed_workflow", "hydrated_workflow", "stale_id"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/enums/delay_types.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Enumeration of delay types for DelayStep.\n * \n * @enum {string}\n * @readonly\n * @example\n * import delay_types from 'micro-flow';\n * \n * const
|
|
4
|
+
"sourcesContent": ["/**\n * Enumeration of delay types for DelayStep.\n * \n * @enum {string}\n * @readonly\n * @example\n * import delay_types from 'micro-flow';\n * \n * const delay_step = new DelayStep({\n * name: 'wait-5-seconds',\n * delay_type: delay_types.RELATIVE,\n * delay_duration: 5000\n * });\n */\nconst delay_types = {\n /**\n * Delay until a specific absolute timestamp or Date.\n * Use with delay_timestamp property.\n * @type {string}\n */\n ABSOLUTE: 'absolute',\n \n /**\n * Delay for a relative duration in milliseconds.\n * Use with delay_duration property.\n * @type {string}\n */\n RELATIVE: 'relative',\n};\n\nexport default delay_types;\n"],
|
|
5
5
|
"mappings": "AAcA,MAAMA,EAAc,CAMlB,SAAU,WAOV,SAAU,UACZ,EAEA,IAAOC,EAAQD",
|
|
6
6
|
"names": ["delay_types", "delay_types_default"]
|
|
7
7
|
}
|