@ronaldroe/micro-flow 0.4.0 → 1.2.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.
@@ -1,2 +1,2 @@
1
- var a=Object.defineProperty;var s=(n,t)=>a(n,"name",{value:t,configurable:!0});import r from"./logic_step.js";import"../../enums/index.js";class o extends r{static{s(this,"Case")}static step_name="case";constructor({name:t,conditional:e={subject:null,operator:null,value:null},callable:i=s(async()=>{},"callable"),force_subject_override:c=!1}){super({name:t,step_type:o.step_name,callable:i}),this.conditional=e,this.force_subject_override=c,this.is_matched=!1}set switch_subject(t){const e=t!=null,i=this.conditional.subject!==null&&this.conditional.subject!==void 0;if(!e&&!i)throw new Error(`No subject set for case step: ${this.name}, using default equality check`);if(e&&(!i||this.force_subject_override)&&(this.conditional.subject=t),!this.conditionalIsValid())throw new Error(`Invalid conditional configuration for case step: ${this.name}`)}}export{o as default};
1
+ var a=Object.defineProperty;var o=(n,t)=>a(n,"name",{value:t,configurable:!0});import r from"./logic_step.js";import"../../enums/index.js";class s extends r{static{o(this,"Case")}static step_name="case";constructor({name:t,conditional:e={subject:null,operator:null,value:null},callable:i=o(async()=>{},"callable"),force_subject_override:c=!1}){super({name:t,step_type:s.step_name,callable:i}),this.conditional_config=e,this.force_subject_override=c,this.is_matched=!1}set switch_subject(t){const e=t!=null,i=this.conditional_config.subject!==null&&this.conditional_config.subject!==void 0;if(!e&&!i)throw new Error(`No subject set for case step: ${this.name}, using default equality check`);if(e&&(!i||this.force_subject_override)&&(this.conditional_config.subject=t),!this.conditionalIsValid())throw new Error(`Invalid conditional configuration for case step: ${this.name}`)}}export{s as default};
2
2
  //# sourceMappingURL=case.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/case.js"],
4
- "sourcesContent": ["import LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * Case class representing a single case in a switch statement.\n * Used in conjunction with SwitchStep to create switch/case logic.\n * @class Case\n * @extends LogicStep\n */\nexport default class Case extends LogicStep {\n static step_name = 'case';\n\n /**\n * Creates a new Case instance.\n * Note: Plain LogicStep instances can be used in place of Case, but they MUST have conditional.subject set.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the case.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*} [options.conditional.subject=null] - Subject to evaluate (typically set by SwitchStep).\n * @param {conditional_step_comparators|string} [options.conditional.operator=null] - Comparison operator.\n * @param {*} [options.conditional.value=null] - Value to compare against.\n * @param {Function|Step|Workflow} [options.callable=async () => {}] - Function, Step, or Workflow to execute when case matches.\n * @param {boolean} [options.force_subject_override=false] - Force override of subject even if already set.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n callable = async () => {},\n force_subject_override = false,\n }) {\n super({\n name,\n step_type: Case.step_name,\n callable,\n });\n\n this.conditional = conditional;\n this.force_subject_override = force_subject_override;\n\n this.is_matched = false;\n }\n\n /**\n * Sets the switch subject from the parent SwitchStep.\n * Automatically sets the conditional subject if not already set or if force_subject_override is true.\n * @param {*} subject - The subject value from the SwitchStep.\n * @throws {Error} If no subject is provided and conditional.subject is not set.\n * @throws {Error} If the resulting conditional configuration is invalid.\n */\n set switch_subject(subject) {\n const subjectProvided = subject !== null && subject !== undefined;\n const hasExistingSubject = this.conditional.subject !== null && this.conditional.subject !== undefined;\n\n if (!subjectProvided && !hasExistingSubject) {\n throw new Error(`No subject set for case step: ${this.name}, using default equality check`);\n }\n\n if (subjectProvided && (!hasExistingSubject || this.force_subject_override)) {\n this.conditional.subject = subject;\n }\n\n if (!this.conditionalIsValid()) {\n throw new Error(`Invalid conditional configuration for case step: ${this.name}`);\n }\n }\n}\n"],
5
- "mappings": "+EAAA,OAAOA,MAAe,kBACtB,MAA6C,uBAQ7C,MAAOC,UAA2BD,CAAU,CAT5C,MAS4C,CAAAE,EAAA,aAC1C,OAAO,UAAY,OAcnB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,uBAAAI,EAAyB,EAC3B,EAAG,CACD,MAAM,CACJ,KAAAH,EACA,UAAWF,EAAK,UAChB,SAAAI,CACF,CAAC,EAED,KAAK,YAAcD,EACnB,KAAK,uBAAyBE,EAE9B,KAAK,WAAa,EACpB,CASA,IAAI,eAAeC,EAAS,CAC1B,MAAMC,EAAkBD,GAAY,KAC9BE,EAAqB,KAAK,YAAY,UAAY,MAAQ,KAAK,YAAY,UAAY,OAE7F,GAAI,CAACD,GAAmB,CAACC,EACvB,MAAM,IAAI,MAAM,iCAAiC,KAAK,IAAI,gCAAgC,EAO5F,GAJID,IAAoB,CAACC,GAAsB,KAAK,0BAClD,KAAK,YAAY,QAAUF,GAGzB,CAAC,KAAK,mBAAmB,EAC3B,MAAM,IAAI,MAAM,oDAAoD,KAAK,IAAI,EAAE,CAEnF,CACF",
4
+ "sourcesContent": ["import LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * Case class representing a single case in a switch statement.\n * Used in conjunction with SwitchStep to create switch/case logic.\n * @class Case\n * @extends LogicStep\n */\nexport default class Case extends LogicStep {\n static step_name = 'case';\n\n /**\n * Creates a new Case instance.\n * Note: Plain LogicStep instances can be used in place of Case, but they MUST have conditional.subject set.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the case.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject=null] - Subject to evaluate (typically set by SwitchStep). Can be a function.\n * @param {conditional_step_comparators|string} [options.conditional.operator=null] - Comparison operator.\n * @param {*|Function} [options.conditional.value=null] - Value to compare against. Can be a function that returns the value.\n * @param {Function|Step|Workflow} [options.callable=async () => {}] - Function, Step, or Workflow to execute when case matches.\n * @param {boolean} [options.force_subject_override=false] - Force override of subject even if already set.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n callable = async () => {},\n force_subject_override = false,\n }) {\n super({\n name,\n step_type: Case.step_name,\n callable,\n });\n\n this.conditional_config = conditional;\n this.force_subject_override = force_subject_override;\n\n this.is_matched = false;\n }\n\n /**\n * Sets the switch subject from the parent SwitchStep.\n * Automatically sets the conditional subject if not already set or if force_subject_override is true.\n * @param {*} subject - The subject value from the SwitchStep.\n * @throws {Error} If no subject is provided and conditional.subject is not set.\n * @throws {Error} If the resulting conditional configuration is invalid.\n */\n set switch_subject(subject) {\n const subjectProvided = subject !== null && subject !== undefined;\n const hasExistingSubject = this.conditional_config.subject !== null && this.conditional_config.subject !== undefined;\n\n if (!subjectProvided && !hasExistingSubject) {\n throw new Error(`No subject set for case step: ${this.name}, using default equality check`);\n }\n\n if (subjectProvided && (!hasExistingSubject || this.force_subject_override)) {\n this.conditional_config.subject = subject;\n }\n\n if (!this.conditionalIsValid()) {\n throw new Error(`Invalid conditional configuration for case step: ${this.name}`);\n }\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAe,kBACtB,MAA6C,uBAQ7C,MAAOC,UAA2BD,CAAU,CAT5C,MAS4C,CAAAE,EAAA,aAC1C,OAAO,UAAY,OAcnB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,uBAAAI,EAAyB,EAC3B,EAAG,CACD,MAAM,CACJ,KAAAH,EACA,UAAWF,EAAK,UAChB,SAAAI,CACF,CAAC,EAED,KAAK,mBAAqBD,EAC1B,KAAK,uBAAyBE,EAE9B,KAAK,WAAa,EACpB,CASA,IAAI,eAAeC,EAAS,CAC1B,MAAMC,EAAkBD,GAAY,KAC9BE,EAAqB,KAAK,mBAAmB,UAAY,MAAQ,KAAK,mBAAmB,UAAY,OAE3G,GAAI,CAACD,GAAmB,CAACC,EACvB,MAAM,IAAI,MAAM,iCAAiC,KAAK,IAAI,gCAAgC,EAO5F,GAJID,IAAoB,CAACC,GAAsB,KAAK,0BAClD,KAAK,mBAAmB,QAAUF,GAGhC,CAAC,KAAK,mBAAmB,EAC3B,MAAM,IAAI,MAAM,oDAAoD,KAAK,IAAI,EAAE,CAEnF,CACF",
6
6
  "names": ["LogicStep", "Case", "__name", "name", "conditional", "callable", "force_subject_override", "subject", "subjectProvided", "hasExistingSubject"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var i=Object.defineProperty;var l=(n,t)=>i(n,"name",{value:t,configurable:!0});import s from"./logic_step.js";import"../../enums/index.js";class r extends s{static{l(this,"ConditionalStep")}static step_name="conditional";constructor({name:t,conditional:e={subject:null,operator:null,value:null},true_callable:a=l(async()=>{},"true_callable"),false_callable:o=l(async()=>{},"false_callable")}){super({name:t,conditional:e}),this.true_callable=a,this.false_callable=o,this.callable=this.conditional.bind(this)}async conditional(){const t=this.true_callable;t.parentWorkflowId=this.parentWorkflowId;const e=this.false_callable;e.parentWorkflowId=this.parentWorkflowId;let a=null;return this.checkCondition()?(this.log(this.getState("events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED"),`Condition met for step: ${this.name}, executing true branch`),typeof t=="function"?a=await t():(t.parentWorkflowId=this.parentWorkflowId,a=await t.execute())):(this.log(this.getState("events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED"),`Condition not met for step: ${this.name}, executing false branch`),typeof e=="function"?a=await e():(e.parentWorkflowId=this.parentWorkflowId,a=await e.execute())),{message:`Conditional step ${this.name} completed`,result:a}}}export{r as default};
1
+ var a=Object.defineProperty;var n=(o,e)=>a(o,"name",{value:e,configurable:!0});import l from"./logic_step.js";import"../../enums/index.js";class c extends l{static{n(this,"ConditionalStep")}static step_name="conditional";constructor({name:e,conditional:i={subject:null,operator:null,value:null},true_callable:t=n(async()=>{},"true_callable"),false_callable:s=n(async()=>{},"false_callable")}){super({name:e,conditional:i}),typeof t=="function"?this.true_callable=t.bind(this):this.true_callable=t,typeof s=="function"?this.false_callable=s.bind(this):this.false_callable=s,this.callable=this.conditional.bind(this)}async conditional(){const e=this.true_callable,i=this.false_callable;let t=null;return this.checkCondition()?(this.log(this.getState("events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED"),`Condition met for step: ${this.name}, executing true branch`),typeof e=="function"?t=await e():(e.parentWorkflowId=this.parentWorkflowId,t=await e.execute())):(this.log(this.getState("events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED"),`Condition not met for step: ${this.name}, executing false branch`),typeof i=="function"?t=await i():(i.parentWorkflowId=this.parentWorkflowId,t=await i.execute())),{message:`Conditional step ${this.name} completed`,result:t}}}export{c as default};
2
2
  //# sourceMappingURL=conditional_step.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/conditional_step.js"],
4
- "sourcesContent": ["import LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * ConditionalStep class for branching logic based on conditions.\n * @class ConditionalStep\n * @extends LogicStep\n */\nexport default class ConditionalStep extends LogicStep {\n static step_name = 'conditional';\n\n /**\n * Creates a new ConditionalStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*} [options.conditional.subject] - Subject to evaluate.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*} [options.conditional.value] - Value to compare against.\n * @param {Function|Step|Workflow} [options.true_callable=async () => {}] - Callable to execute if condition is true.\n * @param {Function|Step|Workflow} [options.false_callable=async () => {}] - Callable to execute if condition is false.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n true_callable = async () => {},\n false_callable = async () => {},\n }) {\n super({\n name,\n conditional\n });\n\n this.true_callable = true_callable;\n this.false_callable = false_callable;\n\n this.callable = this.conditional.bind(this);\n }\n\n /**\n * Executes the appropriate branch based on the condition evaluation.\n * @async\n * @returns {Promise<*>} The result of the executed branch.\n */\n async conditional() {\n const true_callable = this.true_callable;\n true_callable.parentWorkflowId = this.parentWorkflowId;\n\n const false_callable = this.false_callable;\n false_callable.parentWorkflowId = this.parentWorkflowId;\n\n let result = null;\n\n if (this.checkCondition()) {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED'),\n `Condition met for step: ${this.name}, executing true branch`\n );\n\n // Normally, the callable is automatically set according to its type\n // Here, they are set separately, so we need to account for types\n if (typeof true_callable === 'function') {\n result = await true_callable();\n } else {\n true_callable.parentWorkflowId = this.parentWorkflowId;\n result = await true_callable.execute();\n }\n } else {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED'),\n `Condition not met for step: ${this.name}, executing false branch`\n );\n\n // Normally, the callable is automatically set according to its type\n // Here, they are set separately, so we need to account for types\n if (typeof false_callable === 'function') {\n result = await false_callable();\n } else {\n false_callable.parentWorkflowId = this.parentWorkflowId;\n result = await false_callable.execute();\n }\n }\n\n return { message: `Conditional step ${this.name} completed`, result };\n }\n}\n"],
5
- "mappings": "+EAAA,OAAOA,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAAsCD,CAAU,CARvD,MAQuD,CAAAE,EAAA,wBACrD,OAAO,UAAY,cAanB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,cAAAC,EAAgBH,EAAA,SAAY,CAAC,EAAb,iBAChB,eAAAI,EAAiBJ,EAAA,SAAY,CAAC,EAAb,iBACnB,EAAG,CACD,MAAM,CACJ,KAAAC,EACA,YAAAC,CACF,CAAC,EAED,KAAK,cAAgBC,EACrB,KAAK,eAAiBC,EAEtB,KAAK,SAAW,KAAK,YAAY,KAAK,IAAI,CAC5C,CAOA,MAAM,aAAc,CAClB,MAAMD,EAAgB,KAAK,cAC3BA,EAAc,iBAAmB,KAAK,iBAEtC,MAAMC,EAAiB,KAAK,eAC5BA,EAAe,iBAAmB,KAAK,iBAEvC,IAAIC,EAAS,KAEb,OAAI,KAAK,eAAe,GACtB,KAAK,IACH,KAAK,SAAS,0DAA0D,EACxE,2BAA2B,KAAK,IAAI,yBACtC,EAII,OAAOF,GAAkB,WAC3BE,EAAS,MAAMF,EAAc,GAE7BA,EAAc,iBAAmB,KAAK,iBACtCE,EAAS,MAAMF,EAAc,QAAQ,KAGvC,KAAK,IACH,KAAK,SAAS,2DAA2D,EACzE,+BAA+B,KAAK,IAAI,0BAC1C,EAII,OAAOC,GAAmB,WAC5BC,EAAS,MAAMD,EAAe,GAE9BA,EAAe,iBAAmB,KAAK,iBACvCC,EAAS,MAAMD,EAAe,QAAQ,IAInC,CAAE,QAAS,oBAAoB,KAAK,IAAI,aAAc,OAAAC,CAAO,CACtE,CACF",
4
+ "sourcesContent": ["import LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * ConditionalStep class for branching logic based on conditions.\n * @class ConditionalStep\n * @extends LogicStep\n */\nexport default class ConditionalStep extends LogicStep {\n static step_name = 'conditional';\n\n /**\n * Creates a new ConditionalStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {Function|Step|Workflow} [options.true_callable=async () => {}] - Callable to execute if condition is true.\n * @param {Function|Step|Workflow} [options.false_callable=async () => {}] - Callable to execute if condition is false.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n true_callable = async () => {},\n false_callable = async () => {},\n }) {\n super({\n name,\n conditional\n });\n\n // Bind function callables to this step instance for state access\n if (typeof true_callable === 'function') {\n this.true_callable = true_callable.bind(this);\n } else {\n this.true_callable = true_callable;\n }\n\n if (typeof false_callable === 'function') {\n this.false_callable = false_callable.bind(this);\n } else {\n this.false_callable = false_callable;\n }\n\n this.callable = this.conditional.bind(this);\n }\n\n /**\n * Executes the appropriate branch based on the condition evaluation.\n * @async\n * @returns {Promise<*>} The result of the executed branch.\n */\n async conditional() {\n const true_callable = this.true_callable;\n const false_callable = this.false_callable;\n\n let result = null;\n\n if (this.checkCondition()) {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED'),\n `Condition met for step: ${this.name}, executing true branch`\n );\n\n if (typeof true_callable === 'function') {\n result = await true_callable();\n } else {\n true_callable.parentWorkflowId = this.parentWorkflowId;\n result = await true_callable.execute();\n }\n } else {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED'),\n `Condition not met for step: ${this.name}, executing false branch`\n );\n\n if (typeof false_callable === 'function') {\n result = await false_callable();\n } else {\n false_callable.parentWorkflowId = this.parentWorkflowId;\n result = await false_callable.execute();\n }\n }\n\n return { message: `Conditional step ${this.name} completed`, result };\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAAsCD,CAAU,CARvD,MAQuD,CAAAE,EAAA,wBACrD,OAAO,UAAY,cAanB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,cAAAC,EAAgBH,EAAA,SAAY,CAAC,EAAb,iBAChB,eAAAI,EAAiBJ,EAAA,SAAY,CAAC,EAAb,iBACnB,EAAG,CACD,MAAM,CACJ,KAAAC,EACA,YAAAC,CACF,CAAC,EAGG,OAAOC,GAAkB,WAC3B,KAAK,cAAgBA,EAAc,KAAK,IAAI,EAE5C,KAAK,cAAgBA,EAGnB,OAAOC,GAAmB,WAC5B,KAAK,eAAiBA,EAAe,KAAK,IAAI,EAE9C,KAAK,eAAiBA,EAGxB,KAAK,SAAW,KAAK,YAAY,KAAK,IAAI,CAC5C,CAOA,MAAM,aAAc,CAClB,MAAMD,EAAgB,KAAK,cACrBC,EAAiB,KAAK,eAE5B,IAAIC,EAAS,KAEb,OAAI,KAAK,eAAe,GACtB,KAAK,IACH,KAAK,SAAS,0DAA0D,EACxE,2BAA2B,KAAK,IAAI,yBACtC,EAEI,OAAOF,GAAkB,WAC3BE,EAAS,MAAMF,EAAc,GAE7BA,EAAc,iBAAmB,KAAK,iBACtCE,EAAS,MAAMF,EAAc,QAAQ,KAGvC,KAAK,IACH,KAAK,SAAS,2DAA2D,EACzE,+BAA+B,KAAK,IAAI,0BAC1C,EAEI,OAAOC,GAAmB,WAC5BC,EAAS,MAAMD,EAAe,GAE9BA,EAAe,iBAAmB,KAAK,iBACvCC,EAAS,MAAMD,EAAe,QAAQ,IAInC,CAAE,QAAS,oBAAoB,KAAK,IAAI,aAAc,OAAAC,CAAO,CACtE,CACF",
6
6
  "names": ["LogicStep", "ConditionalStep", "__name", "name", "conditional", "true_callable", "false_callable", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var o=Object.defineProperty;var n=(i,e)=>o(i,"name",{value:e,configurable:!0});import l from"./step.js";import{delay_types as h,step_types as r}from"../../enums/index.js";import p from"node-schedule";import{addMilliseconds as _}from"date-fns";class m extends l{static{n(this,"DelayStep")}static step_name="delay";constructor({name:e,absolute_timestamp:t=new Date,relative_delay_ms:s=0,delay_type:a=h.RELATIVE}){super({name:e,step_type:r.DELAY}),this.delay_type=a,this.absolute_timestamp=new Date(t),this.relative_delay_ms=s,this.callable=this[a].bind(this)}async absolute(){const e=new Date;return this.absolute_timestamp.getTime()<=e.getTime()?(this.log(this.getState("events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),this):this.delay(this.absolute_timestamp)}async delay(e){return new Promise(t=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`),`Delay scheduled for step: ${this.name} until ${e.toISOString()}`);const s=p.scheduleJob(e,()=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`),`Delay complete for step: ${this.name}. Continuing.`),t(this)});this.scheduled_job=s})}async relative(){if(this.relative_delay_ms<=0)return this.log(this.getState("events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),this;const e=_(new Date,this.relative_delay_ms);return this.delay(e)}}export{m as default};
1
+ var l=Object.defineProperty;var n=(a,e)=>l(a,"name",{value:e,configurable:!0});import o from"./step.js";import{delay_types as p,step_types as r}from"../../enums/index.js";import y from"node-schedule";import{addMilliseconds as _}from"date-fns";class d extends o{static{n(this,"DelayStep")}static step_name="delay";constructor({name:e,absolute_timestamp:t=new Date,relative_delay_ms:s=0,delay_type:i=p.RELATIVE}){super({name:e,step_type:r.DELAY}),this.delay_type=i,this.absolute_timestamp=new Date(t),this.relative_delay_ms=s,this.callable=this[i].bind(this)}async absolute(){const e=new Date;return this.absolute_timestamp.getTime()<=e.getTime()?(this.log(this.getState("events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:e.toISOString()}):this.delay(this.absolute_timestamp)}async delay(e){return new Promise(t=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`),`Delay scheduled for step: ${this.name} until ${e.toISOString()}`);const s=y.scheduleJob(e,()=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`),`Delay complete for step: ${this.name}. Continuing.`),t({delayed:!0,delay_type:this.delay_type,timestamp:new Date().toISOString()})});this.scheduled_job=s})}async relative(){if(this.relative_delay_ms<=0)return this.log(this.getState("events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:new Date().toISOString()};const e=_(new Date,this.relative_delay_ms);return this.delay(e)}}export{d as default};
2
2
  //# sourceMappingURL=delay_step.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/classes/steps/delay_step.js"],
4
- "sourcesContent": ["import Step from './step.js';\nimport { delay_types, step_types } from '../../enums/index.js';\nimport schedule from 'node-schedule';\nimport { addMilliseconds } from 'date-fns';\n\n/**\n * DelayStep class for introducing delays in workflow execution.\n * Supports both absolute and relative delays.\n * @class DelayStep\n * @extends Step\n */\nexport default class DelayStep extends Step {\n static step_name = 'delay';\n\n /**\n * Creates a new DelayStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Date|string} [options.absolute_timestamp=new Date()] - Absolute timestamp to delay until.\n * @param {number} [options.relative_delay_ms=0] - Relative delay in milliseconds.\n * @param {string} [options.delay_type=delay_types.RELATIVE] - Type of delay ('absolute' or 'relative').\n */\n constructor({\n name,\n absolute_timestamp = new Date(),\n relative_delay_ms = 0,\n delay_type = delay_types.RELATIVE\n }) {\n super({\n name,\n step_type: step_types.DELAY,\n });\n\n this.delay_type = delay_type;\n this.absolute_timestamp = new Date(absolute_timestamp);\n this.relative_delay_ms = relative_delay_ms;\n\n this.callable = this[delay_type].bind(this);\n }\n\n /**\n * Executes an absolute delay until the specified timestamp. If the timestamp is in the past, it continues immediately.\n * @returns {Promise<DelayStep>} Resolves with the DelayStep instance 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 this;\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<DelayStep>} Resolves with the DelayStep instance 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(this);\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<DelayStep>} Resolves with the DelayStep instance 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 this;\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,EAAY,QAC3B,EAAG,CACD,MAAM,CACJ,KAAAM,EACA,UAAWL,EAAW,KACxB,CAAC,EAED,KAAK,WAAaQ,EAClB,KAAK,mBAAqB,IAAI,KAAKF,CAAkB,EACrD,KAAK,kBAAoBC,EAEzB,KAAK,SAAW,KAAKC,CAAU,EAAE,KAAK,IAAI,CAC5C,CAMA,MAAM,UAAW,CACf,MAAMC,EAAM,IAAI,KAEhB,OAAI,KAAK,mBAAmB,QAAQ,GAAKA,EAAI,QAAQ,GACnD,KAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,MAGF,KAAK,MAAM,KAAK,kBAAkB,CAC3C,CAMA,MAAM,MAAMC,EAAa,CACvB,OAAO,IAAI,QAASC,GAAY,CAC9B,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,YACrE,EACA,6BAA6B,KAAK,IAAI,UAAUD,EAAY,YAAY,CAAC,EAC3E,EAEA,MAAME,EAAMX,EAAS,YAAYS,EAAa,IAAM,CAClD,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,WACrE,EACA,4BAA4B,KAAK,IAAI,eACvC,EACAC,EAAQ,IAAI,CACd,CAAC,EAED,KAAK,cAAgBC,CACvB,CAAC,CACH,CAMA,MAAM,UAAW,CACf,GAAI,KAAK,mBAAqB,EAC5B,YAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,KAGT,MAAMF,EAAcR,EAAgB,IAAI,KAAQ,KAAK,iBAAiB,EAEtE,OAAO,KAAK,MAAMQ,CAAW,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"],
5
+ "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAS,eAAAC,EAAa,cAAAC,MAAkB,uBACxC,OAAOC,MAAc,gBACrB,OAAS,mBAAAC,MAAuB,WAQhC,MAAOC,UAAgCL,CAAK,CAX5C,MAW4C,CAAAM,EAAA,kBAC1C,OAAO,UAAY,QAUnB,YAAY,CACV,KAAAC,EACA,mBAAAC,EAAqB,IAAI,KACzB,kBAAAC,EAAoB,EACpB,WAAAC,EAAaT,EAAY,QAC3B,EAAG,CACD,MAAM,CACJ,KAAAM,EACA,UAAWL,EAAW,KACxB,CAAC,EAED,KAAK,WAAaQ,EAClB,KAAK,mBAAqB,IAAI,KAAKF,CAAkB,EACrD,KAAK,kBAAoBC,EAEzB,KAAK,SAAW,KAAKC,CAAU,EAAE,KAAK,IAAI,CAC5C,CAMA,MAAM,UAAW,CACf,MAAMC,EAAM,IAAI,KAEhB,OAAI,KAAK,mBAAmB,QAAQ,GAAKA,EAAI,QAAQ,GACnD,KAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAWA,EAAI,YAAY,CAAE,GAG9E,KAAK,MAAM,KAAK,kBAAkB,CAC3C,CAMA,MAAM,MAAMC,EAAa,CACvB,OAAO,IAAI,QAASC,GAAY,CAC9B,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,YACrE,EACA,6BAA6B,KAAK,IAAI,UAAUD,EAAY,YAAY,CAAC,EAC3E,EAEA,MAAME,EAAMX,EAAS,YAAYS,EAAa,IAAM,CAClD,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,WACrE,EACA,4BAA4B,KAAK,IAAI,eACvC,EACAC,EAAQ,CAAE,QAAS,GAAM,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,CAAC,CAC7F,CAAC,EAED,KAAK,cAAgBC,CACvB,CAAC,CACH,CAMA,MAAM,UAAW,CACf,GAAI,KAAK,mBAAqB,EAC5B,YAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,EAG5F,MAAMF,EAAcR,EAAgB,IAAI,KAAQ,KAAK,iBAAiB,EAEtE,OAAO,KAAK,MAAMQ,CAAW,CAC/B,CACF",
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,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 {*} [options.conditional.subject] - Subject to evaluate.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*} [options.conditional.value] - Value to compare against.\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.parentWorkflowId, `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.parentWorkflowId, `should_${this.flow_control_type}`, false);\n\n return false;\n }\n }\n}\n"],
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.parentWorkflowId, `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.parentWorkflowId, `should_${this.flow_control_type}`, false);\n\n return false;\n }\n }\n}\n"],
5
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,iBAAkB,UAAU,KAAK,iBAAiB,GAAI,EAAI,EAEpF,KAEP,KAAK,IACH,KAAK,SAAS,2DAA2D,EACzE,qCAAqC,KAAK,IAAI,EAChD,EACA,KAAK,uBAAuB,KAAK,iBAAkB,UAAU,KAAK,iBAAiB,GAAI,EAAK,EAErF,GAEX,CACF",
6
6
  "names": ["LogicStep", "flow_control_types", "FlowControlStep", "__name", "conditional", "name", "flow_control_type"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var n=Object.defineProperty;var o=(s,t)=>n(s,"name",{value:t,configurable:!0});import i from"./step.js";import{step_types as r}from"../../enums/index.js";class c extends i{static{o(this,"LogicStep")}static step_name="logic";constructor({name:t,callable:a=o(async()=>{},"callable"),conditional:e={operator:null,subject:null,value:null}}){super({name:t,base_type:r.LOGIC,callable:a}),this.setConditional(e)}checkCondition(){const t=this.conditional.subject,a=this.conditional.operator,e=this.conditional.value;switch(a){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"):case this.getState("conditional_step_comparators.IN"):return(Array.isArray(t)||typeof t=="string")&&t.includes(e);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"):case this.getState("conditional_step_comparators.NOT_IN"):return(Array.isArray(t)||typeof t=="string")&&!t.includes(e);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: ${a}`)}}conditionalIsValid(){return this.conditional.subject!==null&&this.conditional.subject!==void 0&&this.conditional.operator!==null&&this.conditional.operator!==void 0&&this.conditional.value!==null&&this.conditional.value!==void 0}setConditional(t){this.conditional={subject:t.subject,operator:t.operator,value:t.value}}}export{c as default};
1
+ var r=Object.defineProperty;var n=(i,o)=>r(i,"name",{value:o,configurable:!0});import c from"./step.js";import{step_types as _}from"../../enums/index.js";class p extends c{static{n(this,"LogicStep")}static step_name="logic";constructor({name:o,callable:a=n(async()=>{},"callable"),conditional:s={operator:null,subject:null,value:null}}){super({name:o,step_type:_.LOGIC,callable:a}),this.setConditional(s)}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&&this.conditional_config.value!==null&&this.conditional_config.value!==void 0}setConditional(o){this.conditional_config={subject:o.subject,operator:o.operator,value:o.value}}}export{p 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 {*} [options.conditional.subject] - Subject to evaluate.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*} [options.conditional.value] - Value to compare against.\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 base_type: step_types.LOGIC,\n callable\n });\n\n this.setConditional(conditional);\n }\n\n /**\n * Evaluates the conditional expression.\n * @returns {boolean} True if the condition is met.\n * @throws {Error} Throws if operator is unknown.\n */\n checkCondition() {\n const subject = this.conditional.subject;\n const operator = this.conditional.operator;\n const value = this.conditional.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 case this.getState('conditional_step_comparators.IN'):\n return (Array.isArray(subject) || typeof subject === 'string') && subject.includes(value);\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 case this.getState('conditional_step_comparators.NOT_IN'):\n return (Array.isArray(subject) || typeof subject === 'string') && !subject.includes(value);\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 notMatchRegex = new RegExp(value);\n return !notMatchRegex.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 * @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 return (\n this.conditional.subject !== null &&\n this.conditional.subject !== undefined &&\n this.conditional.operator !== null &&\n this.conditional.operator !== undefined &&\n this.conditional.value !== null &&\n this.conditional.value !== undefined\n );\n }\n\n /**\n * Sets the conditional properties.\n * @param {Object} conditional - Conditional configuration object.\n */\n setConditional(conditional) {\n this.conditional = { subject: conditional.subject, operator: conditional.operator, value: conditional.value };\n }\n}\n"],
5
- "mappings": "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",
6
- "names": ["Step", "step_types", "LogicStep", "__name", "name", "callable", "conditional", "subject", "operator", "value"]
4
+ "sourcesContent": ["import Step from './step.js';\nimport { conditional_step_comparators, step_types } from '../../enums/index.js';\n\n/**\n * LogicStep class for conditional logic operations.\n * @class LogicStep\n * @extends Step\n */\nexport default class LogicStep extends Step {\n static step_name = 'logic';\n\n /**\n * Creates a new LogicStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [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\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 rawSubject = this.conditional_config.subject;\n const rawValue = 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 rawSubject === 'function' ? rawSubject() : rawSubject;\n \n // Don't resolve value for CUSTOM_FUNCTION - the value IS the function to call\n const isCustomFunction = operator === this.getState('conditional_step_comparators.CUSTOM_FUNCTION');\n const value = (!isCustomFunction && typeof rawValue === 'function') ? rawValue() : rawValue;\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 notMatchRegex = new RegExp(value);\n return !notMatchRegex.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, operator, and value all 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 this.conditional_config.value !== null &&\n this.conditional_config.value !== 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"],
5
+ "mappings": "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",
6
+ "names": ["Step", "step_types", "LogicStep", "__name", "name", "callable", "conditional", "rawSubject", "rawValue", "operator", "subject", "value"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var h=Object.defineProperty;var r=(o,t)=>h(o,"name",{value:t,configurable:!0});import{loop_types as c,step_types as u}from"../../enums/index.js";import p from"./logic_step.js";import"../../enums/index.js";class f extends p{static{r(this,"LoopStep")}static step_name=u.LOOP;constructor({name:t,iterable:e,callable:s=r(async()=>{},"callable"),conditional:n={operator:null,subject:null,value:null},loop_type:l=c.FOR_EACH,iterations:a=0,max_iterations:i=1e3}){super({name:t,conditional:n}),this.iterable=e,this.loop_type=l,this.iterations=a>i?i:a,this.max_iterations=i,this.results=[],this.current_item=null,this.callable=this[`${l}_loop`].bind(this),this.callable_type=this.getCallableType(s),this._callable=this.callable_type==="function"?s.bind(this):s.execute.bind(s)}async generator(){if(!this._callable.constructor.name.includes("Generator"))throw new Error("Iterable must be a generator function for generator loops");let t=0;for(const e of await this._callable())if(this.results.push(e),++t>=this.max_iterations)break;return{message:`Generator loop ${this.name} completed after ${t} iterations`,result:this.results}}async for_loop(){let t=0;for(;t<this.iterations;t++)this.results.push(await this._callable());return{message:`For loop ${this.name} completed after ${t} iterations`,result:this.results}}async for_each_loop(){if(!this.iterable)throw new Error("Iterable is required for for_each loops");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._callable());return{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");let t=0;for(;this.checkCondition()&&t<this.max_iterations;)t++,this.results.push(await this._callable());return{message:`While loop ${this.name} completed after ${t} iterations`,result:this.results}}}export{f as default};
1
+ var p=Object.defineProperty;var o=(r,t)=>p(r,"name",{value:t,configurable:!0});import{loop_types as u,step_types as c}from"../../enums/index.js";import f from"./logic_step.js";import"../../enums/index.js";class _ extends f{static{o(this,"LoopStep")}static step_name=c.LOOP;constructor({name:t,iterable:e,callable:s=o(async()=>{},"callable"),conditional:n={operator:null,subject:null,value:null},loop_type:l=u.FOR_EACH,iterations:a=0,max_iterations:i=1e3}){super({name:t,conditional:n}),this.iterable=e,this.loop_type=l,this.iterations=a>i?i:a,this.max_iterations=i,this.results=[],this.current_item=null;const h=this.getCallableType(s);this._loop_callable=h==="function"?s.bind(this):s.execute.bind(s),this.callable=this[`${l}_loop`].bind(this)}async generator_loop(){if(!this._loop_callable.constructor.name.includes("Generator"))throw new Error("Iterable must be a generator function for generator loops");let t=0;for await(const e of this._loop_callable())if(this.results.push(e),++t>=this.max_iterations)break;return{message:`Generator loop ${this.name} completed after ${t} iterations`,result:this.results}}async for_loop(){let t=0;for(;t<this.iterations;t++)this.results.push(await this._loop_callable());return{message:`For loop ${this.name} completed after ${t} iterations`,result:this.results}}async for_each_loop(){if(!this.iterable)throw new Error("Iterable is required for for_each loops");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{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");let t=0;for(;this.checkCondition()&&t<this.max_iterations;)t++,this.results.push(await this._loop_callable());return{message:`While loop ${this.name} completed after ${t} iterations`,result:this.results}}}export{_ 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 {*} [options.conditional.subject] - Subject to evaluate.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*} [options.conditional.value] - Value to compare against.\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 this.callable = this[`${loop_type}_loop`].bind(this);\n\n // When this.callable is set, it binds the callable function to this instance\n // so that it can access instance properties like current_item.\n // Because we're using a local method instead, we bind it here.\n this.callable_type = this.getCallableType(callable);\n this._callable = this.callable_type === 'function'\n ? callable.bind(this)\n : callable.execute.bind(callable);\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() {\n if (!this._callable.constructor.name.includes('Generator')) {\n throw new Error('Iterable must be a generator function for generator loops');\n }\n\n let iterations = 0;\n for (const item of await this._callable()) {\n this.results.push(item);\n\n if (++iterations >= this.max_iterations) {\n break;\n }\n }\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 let i = 0;\n for (; i < this.iterations; i++) {\n this.results.push(await this._callable());\n }\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 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._callable());\n }\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 let iterations = 0;\n while (this.checkCondition() && iterations < this.max_iterations) {\n iterations++;\n this.results.push(await this._callable());\n }\n\n return {\n message: `While loop ${this.name} completed after ${iterations} iterations`,\n result: this.results\n };\n }\n}\n"],
5
- "mappings": "+EAAA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,uBACvC,OAAOC,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAA+BD,CAAU,CAThD,MASgD,CAAAE,EAAA,iBAC9C,OAAO,UAAYH,EAAW,KAgB9B,YAAY,CACV,KAAAI,EACA,SAAAC,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,YAAAI,EAAc,CACZ,SAAU,KACV,QAAS,KACT,MAAO,IACT,EACA,UAAAC,EAAYT,EAAW,SACvB,WAAAU,EAAa,EACb,eAAAC,EAAiB,GACnB,EAAG,CACD,MAAM,CAAE,KAAAN,EAAM,YAAAG,CAAY,CAAC,EAC3B,KAAK,SAAWF,EAChB,KAAK,UAAYG,EACjB,KAAK,WAAaC,EAAaC,EAAiBA,EAAiBD,EACjE,KAAK,eAAiBC,EACtB,KAAK,QAAU,CAAC,EAChB,KAAK,aAAe,KAEpB,KAAK,SAAW,KAAK,GAAGF,CAAS,OAAO,EAAE,KAAK,IAAI,EAKnD,KAAK,cAAgB,KAAK,gBAAgBF,CAAQ,EAClD,KAAK,UAAY,KAAK,gBAAkB,WACpCA,EAAS,KAAK,IAAI,EAClBA,EAAS,QAAQ,KAAKA,CAAQ,CACpC,CAOA,MAAM,WAAY,CAChB,GAAI,CAAC,KAAK,UAAU,YAAY,KAAK,SAAS,WAAW,EACvD,MAAM,IAAI,MAAM,2DAA2D,EAG7E,IAAIG,EAAa,EACjB,UAAWE,KAAQ,MAAM,KAAK,UAAU,EAGtC,GAFA,KAAK,QAAQ,KAAKA,CAAI,EAElB,EAAEF,GAAc,KAAK,eACvB,MAIJ,MAAO,CACL,QAAS,kBAAkB,KAAK,IAAI,oBAAoBA,CAAU,cAClE,OAAQ,KAAK,OACf,CACF,CAMA,MAAM,UAAW,CACf,IAAIG,EAAI,EACR,KAAOA,EAAI,KAAK,WAAYA,IAC1B,KAAK,QAAQ,KAAK,MAAM,KAAK,UAAU,CAAC,EAG1C,MAAO,CACL,QAAS,YAAY,KAAK,IAAI,oBAAoBA,CAAC,cACnD,OAAQ,KAAK,OACf,CACF,CAOA,MAAM,eAAgB,CACpB,GAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,yCAAyC,EAGvD,OAAO,KAAK,UAAa,aAC3B,KAAK,SAAW,KAAK,SAAS,GAGhC,IAAIH,EAAa,EACjB,UAAWE,KAAQ,KAAK,SACtBF,IACA,KAAK,aAAeE,EACpB,KAAK,QAAQ,KAAK,MAAM,KAAK,UAAU,CAAC,EAG1C,MAAO,CACL,QAAS,iBAAiB,KAAK,IAAI,oBAAoBF,CAAU,cACjE,OAAQ,KAAK,OACf,CACF,CAOA,MAAM,YAAa,CACjB,GAAI,CAAC,KAAK,mBAAmB,EAC3B,MAAM,IAAI,MAAM,+CAA+C,EAGjE,IAAIA,EAAa,EACjB,KAAO,KAAK,eAAe,GAAKA,EAAa,KAAK,gBAChDA,IACA,KAAK,QAAQ,KAAK,MAAM,KAAK,UAAU,CAAC,EAG1C,MAAO,CACL,QAAS,cAAc,KAAK,IAAI,oBAAoBA,CAAU,cAC9D,OAAQ,KAAK,OACf,CACF,CACF",
6
- "names": ["loop_types", "step_types", "LogicStep", "LoopStep", "__name", "name", "iterable", "callable", "conditional", "loop_type", "iterations", "max_iterations", "item", "i"]
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 const userCallableType = this.getCallableType(callable);\n this._loop_callable = userCallableType === 'function'\n ? callable.bind(this)\n : callable.execute.bind(callable);\n\n this.callable = this[`${loop_type}_loop`].bind(this);\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 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 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 let i = 0;\n for (; i < this.iterations; i++) {\n this.results.push(await this._loop_callable());\n }\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 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 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 let iterations = 0;\n while (this.checkCondition() && iterations < this.max_iterations) {\n iterations++;\n this.results.push(await this._loop_callable());\n }\n\n return {\n message: `While loop ${this.name} completed after ${iterations} iterations`,\n result: this.results\n };\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,uBACvC,OAAOC,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAA+BD,CAAU,CAThD,MASgD,CAAAE,EAAA,iBAC9C,OAAO,UAAYH,EAAW,KAgB9B,YAAY,CACV,KAAAI,EACA,SAAAC,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,YAAAI,EAAc,CACZ,SAAU,KACV,QAAS,KACT,MAAO,IACT,EACA,UAAAC,EAAYT,EAAW,SACvB,WAAAU,EAAa,EACb,eAAAC,EAAiB,GACnB,EAAG,CACD,MAAM,CAAE,KAAAN,EAAM,YAAAG,CAAY,CAAC,EAC3B,KAAK,SAAWF,EAChB,KAAK,UAAYG,EACjB,KAAK,WAAaC,EAAaC,EAAiBA,EAAiBD,EACjE,KAAK,eAAiBC,EACtB,KAAK,QAAU,CAAC,EAChB,KAAK,aAAe,KAIpB,MAAMC,EAAmB,KAAK,gBAAgBL,CAAQ,EACtD,KAAK,eAAiBK,IAAqB,WACvCL,EAAS,KAAK,IAAI,EAClBA,EAAS,QAAQ,KAAKA,CAAQ,EAElC,KAAK,SAAW,KAAK,GAAGE,CAAS,OAAO,EAAE,KAAK,IAAI,CACrD,CAOA,MAAM,gBAAiB,CACrB,GAAI,CAAC,KAAK,eAAe,YAAY,KAAK,SAAS,WAAW,EAC5D,MAAM,IAAI,MAAM,2DAA2D,EAG7E,IAAIC,EAAa,EAEjB,gBAAiBG,KAAQ,KAAK,eAAe,EAG3C,GAFA,KAAK,QAAQ,KAAKA,CAAI,EAElB,EAAEH,GAAc,KAAK,eACvB,MAIJ,MAAO,CACL,QAAS,kBAAkB,KAAK,IAAI,oBAAoBA,CAAU,cAClE,OAAQ,KAAK,OACf,CACF,CAMA,MAAM,UAAW,CACf,IAAII,EAAI,EACR,KAAOA,EAAI,KAAK,WAAYA,IAC1B,KAAK,QAAQ,KAAK,MAAM,KAAK,eAAe,CAAC,EAG/C,MAAO,CACL,QAAS,YAAY,KAAK,IAAI,oBAAoBA,CAAC,cACnD,OAAQ,KAAK,OACf,CACF,CAOA,MAAM,eAAgB,CACpB,GAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,yCAAyC,EAGvD,OAAO,KAAK,UAAa,aAC3B,KAAK,SAAW,KAAK,SAAS,GAGhC,IAAIJ,EAAa,EACjB,UAAWG,KAAQ,KAAK,SACtBH,IACA,KAAK,aAAeG,EACpB,KAAK,QAAQ,KAAK,MAAM,KAAK,eAAe,CAAC,EAG/C,MAAO,CACL,QAAS,iBAAiB,KAAK,IAAI,oBAAoBH,CAAU,cACjE,OAAQ,KAAK,OACf,CACF,CAOA,MAAM,YAAa,CACjB,GAAI,CAAC,KAAK,mBAAmB,EAC3B,MAAM,IAAI,MAAM,+CAA+C,EAGjE,IAAIA,EAAa,EACjB,KAAO,KAAK,eAAe,GAAKA,EAAa,KAAK,gBAChDA,IACA,KAAK,QAAQ,KAAK,MAAM,KAAK,eAAe,CAAC,EAG/C,MAAO,CACL,QAAS,cAAc,KAAK,IAAI,oBAAoBA,CAAU,cAC9D,OAAQ,KAAK,OACf,CACF,CACF",
6
+ "names": ["loop_types", "step_types", "LogicStep", "LoopStep", "__name", "name", "iterable", "callable", "conditional", "loop_type", "iterations", "max_iterations", "userCallableType", "item", "i"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var o=Object.defineProperty;var s=(a,t)=>o(a,"name",{value:t,configurable:!0});import l from"./step.js";class i extends l{static{s(this,"SwitchStep")}static step_name="switch";constructor({name:t,cases:c=[],default_callable:e=s(async()=>{},"default_callable"),subject:n=null}){super({name:t,step_type:i.step_name}),this.cases=c;const h=this.getCallableType(e);this.default_callable=h==="function"?e.bind(this):e.execute.bind(e),this.subject=n,this.callable=this.switch.bind(this)}async switch(){for(const t of this.cases)if(t.switch_subject=this.subject,await t.checkCondition())return this.log(this.getState("events.step.event_names.SWITCH_CASE_MATCHED"),`Case matched for step: ${this.name}, executing case callable`),t.execute();return this.default_callable()}}export{i as default};
1
+ var h=Object.defineProperty;var c=(n,e)=>h(n,"name",{value:e,configurable:!0});import l from"./step.js";class i extends l{static{c(this,"SwitchStep")}static step_name="switch";constructor({name:e,cases:s=[],default_callable:t=c(async()=>{},"default_callable"),subject:a=null}){super({name:e,step_type:i.step_name}),this.cases=s,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=a,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,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;const s=await this.default_callable();return this._default_callable_type!=="function"?s.result:s}}export{i 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 {*} [options.subject=null] - Subject value to evaluate against each case.\n */\n constructor({\n name,\n cases = [],\n default_callable = async () => {},\n subject = null\n }) {\n super({\n name,\n step_type: SwitchStep.step_name,\n });\n\n this.cases = cases;\n const defaultCallableType = this.getCallableType(default_callable);\n this.default_callable = defaultCallableType === '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 * @returns {Promise<*>} The result of the matched case or default callable.\n */\n async switch() {\n for (const switch_case of this.cases) {\n switch_case.switch_subject = this.subject;\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 switch_case.execute();\n }\n }\n\n return this.default_callable();\n }\n}\n"],
5
- "mappings": "+EAAA,OAAOA,MAAU,YAQjB,MAAOC,UAAiCD,CAAK,CAR7C,MAQ6C,CAAAE,EAAA,mBAC3C,OAAO,UAAY,SAUnB,YAAY,CACV,KAAAC,EACA,MAAAC,EAAQ,CAAC,EACT,iBAAAC,EAAmBH,EAAA,SAAY,CAAC,EAAb,oBACnB,QAAAI,EAAU,IACZ,EAAG,CACD,MAAM,CACJ,KAAAH,EACA,UAAWF,EAAW,SACxB,CAAC,EAED,KAAK,MAAQG,EACb,MAAMG,EAAsB,KAAK,gBAAgBF,CAAgB,EACjE,KAAK,iBAAmBE,IAAwB,WAC5CF,EAAiB,KAAK,IAAI,EAC1BA,EAAiB,QAAQ,KAAKA,CAAgB,EAClD,KAAK,QAAUC,EAEf,KAAK,SAAW,KAAK,OAAO,KAAK,IAAI,CACvC,CAOA,MAAM,QAAS,CACb,UAAWE,KAAe,KAAK,MAK7B,GAJAA,EAAY,eAAiB,KAAK,QAEf,MAAMA,EAAY,eAAe,EAGlD,YAAK,IACH,KAAK,SAAS,6CAA6C,EAC3D,0BAA0B,KAAK,IAAI,2BACrC,EAEOA,EAAY,QAAQ,EAI/B,OAAO,KAAK,iBAAiB,CAC/B,CACF",
6
- "names": ["Step", "SwitchStep", "__name", "name", "cases", "default_callable", "subject", "defaultCallableType", "switch_case"]
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\n }) {\n super({\n name,\n step_type: SwitchStep.step_name,\n });\n\n this.cases = cases;\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 * @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 resolvedSubject = typeof this.subject === 'function' ? this.subject() : this.subject;\n \n for (const switch_case of this.cases) {\n switch_case.switch_subject = resolvedSubject;\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 caseResult = await switch_case.execute();\n return caseResult.result;\n }\n }\n\n // Unwrap Step/Workflow results for consistency with case results\n const defaultResult = await this.default_callable();\n if (this._default_callable_type !== 'function') {\n return defaultResult.result;\n }\n return defaultResult;\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAU,YAQjB,MAAOC,UAAiCD,CAAK,CAR7C,MAQ6C,CAAAE,EAAA,mBAC3C,OAAO,UAAY,SAUnB,YAAY,CACV,KAAAC,EACA,MAAAC,EAAQ,CAAC,EACT,iBAAAC,EAAmBH,EAAA,SAAY,CAAC,EAAb,oBACnB,QAAAI,EAAU,IACZ,EAAG,CACD,MAAM,CACJ,KAAAH,EACA,UAAWF,EAAW,SACxB,CAAC,EAED,KAAK,MAAQG,EACb,KAAK,uBAAyB,KAAK,gBAAgBC,CAAgB,EACnE,KAAK,sBAAwBA,EAC7B,KAAK,iBAAmB,KAAK,yBAA2B,WACpDA,EAAiB,KAAK,IAAI,EAC1BA,EAAiB,QAAQ,KAAKA,CAAgB,EAClD,KAAK,QAAUC,EAEf,KAAK,SAAW,KAAK,OAAO,KAAK,IAAI,CACvC,CAOA,MAAM,QAAS,CAEb,MAAMC,EAAkB,OAAO,KAAK,SAAY,WAAa,KAAK,QAAQ,EAAI,KAAK,QAEnF,UAAWC,KAAe,KAAK,MAK7B,GAJAA,EAAY,eAAiBD,EAEV,MAAMC,EAAY,eAAe,EAGlD,YAAK,IACH,KAAK,SAAS,6CAA6C,EAC3D,0BAA0B,KAAK,IAAI,2BACrC,GAKmB,MAAMA,EAAY,QAAQ,GAC3B,OAKtB,MAAMC,EAAgB,MAAM,KAAK,iBAAiB,EAClD,OAAI,KAAK,yBAA2B,WAC3BA,EAAc,OAEhBA,CACT,CACF",
6
+ "names": ["Step", "SwitchStep", "__name", "name", "cases", "default_callable", "subject", "resolvedSubject", "switch_case", "defaultResult"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronaldroe/micro-flow",
3
- "version": "0.4.0",
3
+ "version": "1.2.0",
4
4
  "description": "A lightweight, flexible workflow orchestration library for Node.js and browser environments. Build complex, sequential processes with ease using an intuitive API that supports conditional logic, flow control, event handling, and state management.",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -16,9 +16,9 @@ export default class Case extends LogicStep {
16
16
  * @param {Object} options - Configuration options.
17
17
  * @param {string} [options.name] - Name of the case.
18
18
  * @param {Object} [options.conditional] - Conditional configuration.
19
- * @param {*} [options.conditional.subject=null] - Subject to evaluate (typically set by SwitchStep).
19
+ * @param {*|Function} [options.conditional.subject=null] - Subject to evaluate (typically set by SwitchStep). Can be a function.
20
20
  * @param {conditional_step_comparators|string} [options.conditional.operator=null] - Comparison operator.
21
- * @param {*} [options.conditional.value=null] - Value to compare against.
21
+ * @param {*|Function} [options.conditional.value=null] - Value to compare against. Can be a function that returns the value.
22
22
  * @param {Function|Step|Workflow} [options.callable=async () => {}] - Function, Step, or Workflow to execute when case matches.
23
23
  * @param {boolean} [options.force_subject_override=false] - Force override of subject even if already set.
24
24
  */
@@ -38,7 +38,7 @@ export default class Case extends LogicStep {
38
38
  callable,
39
39
  });
40
40
 
41
- this.conditional = conditional;
41
+ this.conditional_config = conditional;
42
42
  this.force_subject_override = force_subject_override;
43
43
 
44
44
  this.is_matched = false;
@@ -53,14 +53,14 @@ export default class Case extends LogicStep {
53
53
  */
54
54
  set switch_subject(subject) {
55
55
  const subjectProvided = subject !== null && subject !== undefined;
56
- const hasExistingSubject = this.conditional.subject !== null && this.conditional.subject !== undefined;
56
+ const hasExistingSubject = this.conditional_config.subject !== null && this.conditional_config.subject !== undefined;
57
57
 
58
58
  if (!subjectProvided && !hasExistingSubject) {
59
59
  throw new Error(`No subject set for case step: ${this.name}, using default equality check`);
60
60
  }
61
61
 
62
62
  if (subjectProvided && (!hasExistingSubject || this.force_subject_override)) {
63
- this.conditional.subject = subject;
63
+ this.conditional_config.subject = subject;
64
64
  }
65
65
 
66
66
  if (!this.conditionalIsValid()) {
@@ -14,9 +14,9 @@ export default class ConditionalStep extends LogicStep {
14
14
  * @param {Object} options - Configuration options.
15
15
  * @param {string} [options.name] - Name of the step.
16
16
  * @param {Object} [options.conditional] - Conditional configuration.
17
- * @param {*} [options.conditional.subject] - Subject to evaluate.
17
+ * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.
18
18
  * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.
19
- * @param {*} [options.conditional.value] - Value to compare against.
19
+ * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.
20
20
  * @param {Function|Step|Workflow} [options.true_callable=async () => {}] - Callable to execute if condition is true.
21
21
  * @param {Function|Step|Workflow} [options.false_callable=async () => {}] - Callable to execute if condition is false.
22
22
  */
@@ -35,8 +35,18 @@ export default class ConditionalStep extends LogicStep {
35
35
  conditional
36
36
  });
37
37
 
38
- this.true_callable = true_callable;
39
- this.false_callable = false_callable;
38
+ // Bind function callables to this step instance for state access
39
+ if (typeof true_callable === 'function') {
40
+ this.true_callable = true_callable.bind(this);
41
+ } else {
42
+ this.true_callable = true_callable;
43
+ }
44
+
45
+ if (typeof false_callable === 'function') {
46
+ this.false_callable = false_callable.bind(this);
47
+ } else {
48
+ this.false_callable = false_callable;
49
+ }
40
50
 
41
51
  this.callable = this.conditional.bind(this);
42
52
  }
@@ -48,10 +58,7 @@ export default class ConditionalStep extends LogicStep {
48
58
  */
49
59
  async conditional() {
50
60
  const true_callable = this.true_callable;
51
- true_callable.parentWorkflowId = this.parentWorkflowId;
52
-
53
61
  const false_callable = this.false_callable;
54
- false_callable.parentWorkflowId = this.parentWorkflowId;
55
62
 
56
63
  let result = null;
57
64
 
@@ -61,8 +68,6 @@ export default class ConditionalStep extends LogicStep {
61
68
  `Condition met for step: ${this.name}, executing true branch`
62
69
  );
63
70
 
64
- // Normally, the callable is automatically set according to its type
65
- // Here, they are set separately, so we need to account for types
66
71
  if (typeof true_callable === 'function') {
67
72
  result = await true_callable();
68
73
  } else {
@@ -75,8 +80,6 @@ export default class ConditionalStep extends LogicStep {
75
80
  `Condition not met for step: ${this.name}, executing false branch`
76
81
  );
77
82
 
78
- // Normally, the callable is automatically set according to its type
79
- // Here, they are set separately, so we need to account for types
80
83
  if (typeof false_callable === 'function') {
81
84
  result = await false_callable();
82
85
  } else {
@@ -40,7 +40,7 @@ export default class DelayStep extends Step {
40
40
 
41
41
  /**
42
42
  * Executes an absolute delay until the specified timestamp. If the timestamp is in the past, it continues immediately.
43
- * @returns {Promise<DelayStep>} Resolves with the DelayStep instance when delay completes.
43
+ * @returns {Promise<Object>} Resolves with delay completion info when delay completes.
44
44
  */
45
45
  async absolute() {
46
46
  const now = new Date();
@@ -50,7 +50,7 @@ export default class DelayStep extends Step {
50
50
  this.getState('events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE'),
51
51
  `No delay for step: ${this.name}. Continuing.`
52
52
  );
53
- return this;
53
+ return { delayed: false, delay_type: this.delay_type, timestamp: now.toISOString() };
54
54
  }
55
55
 
56
56
  return this.delay(this.absolute_timestamp);
@@ -58,7 +58,7 @@ export default class DelayStep extends Step {
58
58
 
59
59
  /** Schedules a delay until the specified date and time.
60
60
  * @param {Date} delay_until - The date and time to delay until.
61
- * @returns {Promise<DelayStep>} Resolves with the DelayStep instance when delay completes.
61
+ * @returns {Promise<Object>} Resolves with delay completion info when delay completes.
62
62
  */
63
63
  async delay(delay_until) {
64
64
  return new Promise((resolve) => {
@@ -76,7 +76,7 @@ export default class DelayStep extends Step {
76
76
  ),
77
77
  `Delay complete for step: ${this.name}. Continuing.`
78
78
  );
79
- resolve(this);
79
+ resolve({ delayed: true, delay_type: this.delay_type, timestamp: new Date().toISOString() });
80
80
  });
81
81
 
82
82
  this.scheduled_job = job;
@@ -85,7 +85,7 @@ export default class DelayStep extends Step {
85
85
 
86
86
  /**
87
87
  * Executes a relative delay for the specified duration. If the delay duration is zero or negative, it continues immediately.
88
- * @returns {Promise<DelayStep>} Resolves with the DelayStep instance when delay completes.
88
+ * @returns {Promise<Object>} Resolves with delay completion info when delay completes.
89
89
  */
90
90
  async relative() {
91
91
  if (this.relative_delay_ms <= 0) {
@@ -93,7 +93,7 @@ export default class DelayStep extends Step {
93
93
  this.getState('events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE'),
94
94
  `No delay for step: ${this.name}. Continuing.`
95
95
  );
96
- return this;
96
+ return { delayed: false, delay_type: this.delay_type, timestamp: new Date().toISOString() };
97
97
  }
98
98
 
99
99
  const delay_until = addMilliseconds(new Date(), this.relative_delay_ms);
@@ -14,9 +14,9 @@ export default class FlowControlStep extends LogicStep {
14
14
  * Creates a new FlowControlStep instance.
15
15
  * @param {Object} options - Configuration options.
16
16
  * @param {Object} [options.conditional] - Conditional configuration.
17
- * @param {*} [options.conditional.subject] - Subject to evaluate.
17
+ * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.
18
18
  * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.
19
- * @param {*} [options.conditional.value] - Value to compare against.
19
+ * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.
20
20
  * @param {string} [options.name] - Name of the step.
21
21
  * @param {string} [options.flow_control_type=flow_control_types.BREAK] - Type of flow control.
22
22
  * @throws {Error} Throws if flow_control_type is invalid.
@@ -14,9 +14,9 @@ export default class LogicStep extends Step {
14
14
  * @param {Object} options - Configuration options.
15
15
  * @param {string} [options.name] - Name of the step.
16
16
  * @param {Object} [options.conditional] - Conditional configuration.
17
- * @param {*} [options.conditional.subject] - Subject to evaluate.
17
+ * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.
18
18
  * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.
19
- * @param {*} [options.conditional.value] - Value to compare against.
19
+ * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.
20
20
  * @param {Function} [options.callable=async () => {}] - Function to execute.
21
21
  */
22
22
  constructor({
@@ -30,7 +30,7 @@ export default class LogicStep extends Step {
30
30
  }) {
31
31
  super({
32
32
  name,
33
- base_type: step_types.LOGIC,
33
+ step_type: step_types.LOGIC,
34
34
  callable
35
35
  });
36
36
 
@@ -39,13 +39,21 @@ export default class LogicStep extends Step {
39
39
 
40
40
  /**
41
41
  * Evaluates the conditional expression.
42
+ * Supports function subjects and values - they are called to get the actual value.
42
43
  * @returns {boolean} True if the condition is met.
43
44
  * @throws {Error} Throws if operator is unknown.
44
45
  */
45
46
  checkCondition() {
46
- const subject = this.conditional.subject;
47
- const operator = this.conditional.operator;
48
- const value = this.conditional.value;
47
+ const rawSubject = this.conditional_config.subject;
48
+ const rawValue = this.conditional_config.value;
49
+ const operator = this.conditional_config.operator;
50
+
51
+ // Resolve subject - call it if it's a function
52
+ const subject = typeof rawSubject === 'function' ? rawSubject() : rawSubject;
53
+
54
+ // Don't resolve value for CUSTOM_FUNCTION - the value IS the function to call
55
+ const isCustomFunction = operator === this.getState('conditional_step_comparators.CUSTOM_FUNCTION');
56
+ const value = (!isCustomFunction && typeof rawValue === 'function') ? rawValue() : rawValue;
49
57
 
50
58
  switch (operator) {
51
59
  case this.getState('conditional_step_comparators.STRICT_EQUALS'):
@@ -76,14 +84,16 @@ export default class LogicStep extends Step {
76
84
  case this.getState('conditional_step_comparators.STRING_INCLUDES'):
77
85
  case this.getState('conditional_step_comparators.ARRAY_CONTAINS'):
78
86
  case this.getState('conditional_step_comparators.ARRAY_INCLUDES'):
79
- case this.getState('conditional_step_comparators.IN'):
80
87
  return (Array.isArray(subject) || typeof subject === 'string') && subject.includes(value);
88
+ case this.getState('conditional_step_comparators.IN'):
89
+ return (Array.isArray(value) || typeof value === 'string') && value.includes(subject);
81
90
  case this.getState('conditional_step_comparators.STRING_NOT_CONTAINS'):
82
91
  case this.getState('conditional_step_comparators.STRING_NOT_INCLUDES'):
83
92
  case this.getState('conditional_step_comparators.ARRAY_NOT_CONTAINS'):
84
93
  case this.getState('conditional_step_comparators.ARRAY_NOT_INCLUDES'):
85
- case this.getState('conditional_step_comparators.NOT_IN'):
86
94
  return (Array.isArray(subject) || typeof subject === 'string') && !subject.includes(value);
95
+ case this.getState('conditional_step_comparators.NOT_IN'):
96
+ return (Array.isArray(value) || typeof value === 'string') && !value.includes(subject);
87
97
  case this.getState('conditional_step_comparators.EMPTY'):
88
98
  return subject === '' || subject === null || subject === undefined || subject.length === 0;
89
99
  case this.getState('conditional_step_comparators.NOT_EMPTY'):
@@ -124,18 +134,21 @@ export default class LogicStep extends Step {
124
134
 
125
135
  /**
126
136
  * Checks if the conditional configuration is valid.
137
+ * A valid conditional has subject, operator, and value all set (not null/undefined).
138
+ * Functions are valid as subject or value - they will be called during checkCondition().
127
139
  * @returns {boolean} True if conditional is valid.
128
140
  */
129
141
  conditionalIsValid() {
130
142
  // Check if all conditional properties are set (not null or undefined)
131
143
  // Can't use falsy check here because valid values could be falsy (e.g. empty string, 0, false)
144
+ // Functions are valid - they'll be called to get the actual value
132
145
  return (
133
- this.conditional.subject !== null &&
134
- this.conditional.subject !== undefined &&
135
- this.conditional.operator !== null &&
136
- this.conditional.operator !== undefined &&
137
- this.conditional.value !== null &&
138
- this.conditional.value !== undefined
146
+ this.conditional_config.subject !== null &&
147
+ this.conditional_config.subject !== undefined &&
148
+ this.conditional_config.operator !== null &&
149
+ this.conditional_config.operator !== undefined &&
150
+ this.conditional_config.value !== null &&
151
+ this.conditional_config.value !== undefined
139
152
  );
140
153
  }
141
154
 
@@ -144,6 +157,6 @@ export default class LogicStep extends Step {
144
157
  * @param {Object} conditional - Conditional configuration object.
145
158
  */
146
159
  setConditional(conditional) {
147
- this.conditional = { subject: conditional.subject, operator: conditional.operator, value: conditional.value };
160
+ this.conditional_config = { subject: conditional.subject, operator: conditional.operator, value: conditional.value };
148
161
  }
149
162
  }
@@ -17,9 +17,9 @@ export default class LoopStep extends LogicStep {
17
17
  * @param {Array|Iterable|Function} options.iterable - Iterable to loop over or function returning an iterable. Required for 'for_each' and 'generator' loops.
18
18
  * @param {Function} [options.callable=async () => {}] - Function to execute for each iteration.
19
19
  * @param {Object} [options.conditional] - Conditional configuration for while loops. Required for 'while' loops.
20
- * @param {*} [options.conditional.subject] - Subject to evaluate.
20
+ * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.
21
21
  * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.
22
- * @param {*} [options.conditional.value] - Value to compare against.
22
+ * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.
23
23
  * @param {string} [options.loop_type=loop_types.FOR_EACH] - Type of loop ('for', 'for_each', 'while', or 'generator').
24
24
  * @param {number} [options.iterations=0] - Number of iterations to execute. Only used for 'for' loops.
25
25
  * @param {number} [options.max_iterations=1000] - Maximum number of iterations to prevent infinite loops.
@@ -45,15 +45,14 @@ export default class LoopStep extends LogicStep {
45
45
  this.results = [];
46
46
  this.current_item = null;
47
47
 
48
- this.callable = this[`${loop_type}_loop`].bind(this);
49
-
50
- // When this.callable is set, it binds the callable function to this instance
51
- // so that it can access instance properties like current_item.
52
- // Because we're using a local method instead, we bind it here.
53
- this.callable_type = this.getCallableType(callable);
54
- this._callable = this.callable_type === 'function'
48
+ // Store the user's callable separately so loop methods can invoke it.
49
+ // this._callable will be set to the loop method by the setter below.
50
+ const userCallableType = this.getCallableType(callable);
51
+ this._loop_callable = userCallableType === 'function'
55
52
  ? callable.bind(this)
56
53
  : callable.execute.bind(callable);
54
+
55
+ this.callable = this[`${loop_type}_loop`].bind(this);
57
56
  }
58
57
 
59
58
  /**
@@ -61,13 +60,14 @@ export default class LoopStep extends LogicStep {
61
60
  * @throws {Error} If the callable is not a generator or async generator function.
62
61
  * @returns {Object} - An object containing a message and the results of the loop.
63
62
  */
64
- async generator() {
65
- if (!this._callable.constructor.name.includes('Generator')) {
63
+ async generator_loop() {
64
+ if (!this._loop_callable.constructor.name.includes('Generator')) {
66
65
  throw new Error('Iterable must be a generator function for generator loops');
67
66
  }
68
67
 
69
68
  let iterations = 0;
70
- for (const item of await this._callable()) {
69
+ // Use for await...of to handle both sync and async generators
70
+ for await (const item of this._loop_callable()) {
71
71
  this.results.push(item);
72
72
 
73
73
  if (++iterations >= this.max_iterations) {
@@ -88,7 +88,7 @@ export default class LoopStep extends LogicStep {
88
88
  async for_loop() {
89
89
  let i = 0;
90
90
  for (; i < this.iterations; i++) {
91
- this.results.push(await this._callable());
91
+ this.results.push(await this._loop_callable());
92
92
  }
93
93
 
94
94
  return {
@@ -115,7 +115,7 @@ export default class LoopStep extends LogicStep {
115
115
  for (const item of this.iterable) {
116
116
  iterations++;
117
117
  this.current_item = item;
118
- this.results.push(await this._callable());
118
+ this.results.push(await this._loop_callable());
119
119
  }
120
120
 
121
121
  return {
@@ -137,7 +137,7 @@ export default class LoopStep extends LogicStep {
137
137
  let iterations = 0;
138
138
  while (this.checkCondition() && iterations < this.max_iterations) {
139
139
  iterations++;
140
- this.results.push(await this._callable());
140
+ this.results.push(await this._loop_callable());
141
141
  }
142
142
 
143
143
  return {
@@ -15,7 +15,7 @@ export default class SwitchStep extends Step {
15
15
  * @param {string} [options.name] - Name of the step.
16
16
  * @param {Array<Case|LogicStep>} [options.cases=[]] - Array of Case or LogicStep instances to evaluate. LogicStep instances MUST have conditional.subject set.
17
17
  * @param {Function|Step|Workflow} [options.default_callable=async () => {}] - Function, Step, or Workflow to execute if no cases match.
18
- * @param {*} [options.subject=null] - Subject value to evaluate against each case.
18
+ * @param {*|Function} [options.subject=null] - Subject value to evaluate against each case. Can be a function that returns the value.
19
19
  */
20
20
  constructor({
21
21
  name,
@@ -29,8 +29,9 @@ export default class SwitchStep extends Step {
29
29
  });
30
30
 
31
31
  this.cases = cases;
32
- const defaultCallableType = this.getCallableType(default_callable);
33
- this.default_callable = defaultCallableType === 'function'
32
+ this._default_callable_type = this.getCallableType(default_callable);
33
+ this._default_callable_raw = default_callable;
34
+ this.default_callable = this._default_callable_type === 'function'
34
35
  ? default_callable.bind(this)
35
36
  : default_callable.execute.bind(default_callable);
36
37
  this.subject = subject;
@@ -44,8 +45,11 @@ export default class SwitchStep extends Step {
44
45
  * @returns {Promise<*>} The result of the matched case or default callable.
45
46
  */
46
47
  async switch() {
48
+ // Resolve subject once - call it if it's a function
49
+ const resolvedSubject = typeof this.subject === 'function' ? this.subject() : this.subject;
50
+
47
51
  for (const switch_case of this.cases) {
48
- switch_case.switch_subject = this.subject;
52
+ switch_case.switch_subject = resolvedSubject;
49
53
 
50
54
  const is_matched = await switch_case.checkCondition();
51
55
 
@@ -55,10 +59,19 @@ export default class SwitchStep extends Step {
55
59
  `Case matched for step: ${this.name}, executing case callable`
56
60
  );
57
61
 
58
- return switch_case.execute();
62
+ // Return the case's result value directly, not the Case object.
63
+ // This keeps result structure consistent: switchStep.result contains the
64
+ // callable's return value, matching how Step.result works.
65
+ const caseResult = await switch_case.execute();
66
+ return caseResult.result;
59
67
  }
60
68
  }
61
69
 
62
- return this.default_callable();
70
+ // Unwrap Step/Workflow results for consistency with case results
71
+ const defaultResult = await this.default_callable();
72
+ if (this._default_callable_type !== 'function') {
73
+ return defaultResult.result;
74
+ }
75
+ return defaultResult;
63
76
  }
64
77
  }