@ronaldroe/micro-flow 1.2.1 → 1.3.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 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};
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}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 {*|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": "+EAAA,OAAOA,MAAU,YACjB,OAAuC,cAAAC,MAAkB,uBA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AOC,GAAU,UAAYD,EAAQ,WAAWC,CAAK,EAC7F,KAAK,KAAK,SAAS,+CAA+C,EAChE,OAAO,OAAOD,GAAY,UAAY,OAAOC,GAAU,UAAYD,EAAQ,SAASC,CAAK,EAC3F,KAAK,KAAK,SAAS,sCAAsC,EACvD,OAAOD,GAAY,KACrB,KAAK,KAAK,SAAS,0CAA0C,EAC3D,OAAOA,GAAY,KACrB,KAAK,KAAK,SAAS,sCAAsC,EACvD,OAAO,OAAOA,IAAYC,EAC5B,KAAK,KAAK,SAAS,0CAA0C,EAC3D,OAAO,OAAOD,IAAYC,EAC5B,KAAK,KAAK,SAAS,8CAA8C,EAC/D,GAAI,OAAOA,GAAU,WACnB,MAAM,IAAI,MAAM,4BAA4BA,CAAK,EAAE,EAErD,OAAOA,EAAMD,CAAO,EACtB,QACE,MAAM,IAAI,MAAM,qBAAqBD,CAAQ,EAAE,CACnD,CACF,CAQA,oBAAqB,CAInB,OACE,KAAK,mBAAmB,UAAY,MACpC,KAAK,mBAAmB,UAAY,QACpC,KAAK,mBAAmB,WAAa,MACrC,KAAK,mBAAmB,WAAa,QACrC,KAAK,mBAAmB,QAAU,MAClC,KAAK,mBAAmB,QAAU,MAEtC,CAMA,eAAeH,EAAa,CAC1B,KAAK,mBAAqB,CAAE,QAASA,EAAY,QAAS,SAAUA,EAAY,SAAU,MAAOA,EAAY,KAAM,CACrH,CACF",
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 and operator set (not null/undefined).\n * Functions are valid as subject or value - they will be called during checkCondition().\n * @returns {boolean} True if conditional is valid.\n */\n conditionalIsValid() {\n // Check if all conditional properties are set (not null or undefined)\n // Can't use falsy check here because valid values could be falsy (e.g. empty string, 0, false)\n // Functions are valid - they'll be called to get the actual value\n return (\n this.conditional_config.subject !== null &&\n this.conditional_config.subject !== undefined &&\n this.conditional_config.operator !== null &&\n this.conditional_config.operator !== undefined\n );\n }\n\n /**\n * Sets the conditional properties.\n * @param {Object} conditional - Conditional configuration object.\n */\n setConditional(conditional) {\n this.conditional_config = { subject: conditional.subject, operator: conditional.operator, value: conditional.value };\n }\n}\n"],
5
+ "mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAuC,cAAAC,MAAkB,uBAOzD,MAAOC,UAAgCF,CAAK,CAR5C,MAQ4C,CAAAG,EAAA,kBAC1C,OAAO,UAAY,QAYnB,YAAY,CACV,KAAAC,EACA,SAAAC,EAAWF,EAAA,SAAY,CAAC,EAAb,YACX,YAAAG,EAAc,CACZ,SAAU,KACV,QAAS,KACT,MAAO,IACT,CACF,EAAG,CACD,MAAM,CACJ,KAAAF,EACA,UAAWH,EAAW,MACtB,SAAAI,CACF,CAAC,EAED,KAAK,eAAeC,CAAW,CACjC,CAQA,gBAAiB,CACf,MAAMC,EAAa,KAAK,mBAAmB,QACrCC,EAAW,KAAK,mBAAmB,MACnCC,EAAW,KAAK,mBAAmB,SAGnCC,EAAU,OAAOH,GAAe,WAAaA,EAAW,EAAIA,EA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A,CAAK,EAAE,EAErD,OAAOA,EAAMD,CAAO,EACtB,QACE,MAAM,IAAI,MAAM,qBAAqBD,CAAQ,EAAE,CACnD,CACF,CAQA,oBAAqB,CAInB,OACE,KAAK,mBAAmB,UAAY,MACpC,KAAK,mBAAmB,UAAY,QACpC,KAAK,mBAAmB,WAAa,MACrC,KAAK,mBAAmB,WAAa,MAEzC,CAMA,eAAeH,EAAa,CAC1B,KAAK,mBAAqB,CAAE,QAASA,EAAY,QAAS,SAAUA,EAAY,SAAU,MAAOA,EAAY,KAAM,CACrH,CACF",
6
6
  "names": ["Step", "step_types", "LogicStep", "__name", "name", "callable", "conditional", "rawSubject", "rawValue", "operator", "subject", "value"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ronaldroe/micro-flow",
3
- "version": "1.2.1",
3
+ "version": "1.3.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": {
@@ -134,7 +134,7 @@ export default class LogicStep extends Step {
134
134
 
135
135
  /**
136
136
  * Checks if the conditional configuration is valid.
137
- * A valid conditional has subject, operator, and value all set (not null/undefined).
137
+ * A valid conditional has subject and operator set (not null/undefined).
138
138
  * Functions are valid as subject or value - they will be called during checkCondition().
139
139
  * @returns {boolean} True if conditional is valid.
140
140
  */
@@ -146,9 +146,7 @@ export default class LogicStep extends Step {
146
146
  this.conditional_config.subject !== null &&
147
147
  this.conditional_config.subject !== undefined &&
148
148
  this.conditional_config.operator !== null &&
149
- this.conditional_config.operator !== undefined &&
150
- this.conditional_config.value !== null &&
151
- this.conditional_config.value !== undefined
149
+ this.conditional_config.operator !== undefined
152
150
  );
153
151
  }
154
152