From fa80f1e150a08e4268f46d229530979d7bb46688 Mon Sep 17 00:00:00 2001 From: Chris Hatch Date: Mon, 9 Jan 2023 15:09:38 -0600 Subject: [PATCH 01/10] Ugly but working --- src/index.ts | 26 +++++++++++++++++++++++++- src/pr.test.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/pr.test.ts diff --git a/src/index.ts b/src/index.ts index add97d4..b87c78c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -295,8 +295,32 @@ export function ruleFactory< throw new UserError(`Data at '${arrayRule}' is not an array`); const arrayResult = arrayMethod.call(toArray(data), (item, index) => { Object.assign(input, { $item: item, $index: index, $array: data }); + + let conditionResult: RuleResult; + if (arrayMethod === Array.prototype.filter && typeof rule.run === 'object' && 'and' in rule.run) { + const and = toArray(rule.run.and); + for (const rule of and) { + conditionResult = evaluateRule({ + stepRow, + input, + rule, + }); + if (!conditionResult) break; + } + if (trace) + logTrace({ + operation: 'if.and', + rule: and, + result: serialize(conditionResult), + currentState: serialize(input), + stepRow, + stepCount, + }); + } else { handleRule(rule.run); - return results.lastValue; + conditionResult = results.lastValue; + } + return conditionResult; }); results.lastValue = arrayResult; if ('set' in rule) { diff --git a/src/pr.test.ts b/src/pr.test.ts new file mode 100644 index 0000000..a2490ad --- /dev/null +++ b/src/pr.test.ts @@ -0,0 +1,29 @@ +import { ruleFactory } from './index'; + +const context = { + list: [ + { supplier: "Webbeds", parentBrandName: "Red Lion (RLH Corporation)" }, + { supplier: "NotWebbeds", parentBrandName: "Red Lion (RLH Corporation)" }, + ], + roomCount: 2, +}; + +const rulesEngine = ruleFactory([ + { + filter: "list", + run: {and: ['$item.supplier == "Webbeds"', '$item.parentBrandName == "Red Lion (RLH Corporation)"']}, + set: "results", + }, + + { return: "results" }, +]); + + +describe("pr", () => { + it("should return the right stuff", () => { +const result = rulesEngine(context); +console.log(result) + + expect(result.length).toEqual(1); + }); +}) \ No newline at end of file From 1deb0447b7ba866a20eadc334f95f0295c79e501 Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 21:48:56 -0800 Subject: [PATCH 02/10] fixes lint issues and removes console logs --- src/index.ts | 50 +++++++++++++++++++++++++++----------------------- src/pr.test.ts | 27 +++++++++++++++------------ 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/index.ts b/src/index.ts index b87c78c..0cc69ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -296,30 +296,34 @@ export function ruleFactory< const arrayResult = arrayMethod.call(toArray(data), (item, index) => { Object.assign(input, { $item: item, $index: index, $array: data }); - let conditionResult: RuleResult; - if (arrayMethod === Array.prototype.filter && typeof rule.run === 'object' && 'and' in rule.run) { - const and = toArray(rule.run.and); - for (const rule of and) { - conditionResult = evaluateRule({ - stepRow, - input, - rule, - }); - if (!conditionResult) break; + let conditionResult: RuleResult; + if ( + arrayMethod === Array.prototype.filter && + typeof rule.run === 'object' && + 'and' in rule.run + ) { + const and = toArray(rule.run.and); + for (const rule of and) { + conditionResult = evaluateRule({ + stepRow, + input, + rule, + }); + if (!conditionResult) break; + } + if (trace) + logTrace({ + operation: 'if.and', + rule: and, + result: serialize(conditionResult), + currentState: serialize(input), + stepRow, + stepCount, + }); + } else { + handleRule(rule.run); + conditionResult = results.lastValue; } - if (trace) - logTrace({ - operation: 'if.and', - rule: and, - result: serialize(conditionResult), - currentState: serialize(input), - stepRow, - stepCount, - }); - } else { - handleRule(rule.run); - conditionResult = results.lastValue; - } return conditionResult; }); results.lastValue = arrayResult; diff --git a/src/pr.test.ts b/src/pr.test.ts index a2490ad..fc1be76 100644 --- a/src/pr.test.ts +++ b/src/pr.test.ts @@ -2,28 +2,31 @@ import { ruleFactory } from './index'; const context = { list: [ - { supplier: "Webbeds", parentBrandName: "Red Lion (RLH Corporation)" }, - { supplier: "NotWebbeds", parentBrandName: "Red Lion (RLH Corporation)" }, + { supplier: 'Webbeds', parentBrandName: 'Red Lion (RLH Corporation)' }, + { supplier: 'NotWebbeds', parentBrandName: 'Red Lion (RLH Corporation)' }, ], roomCount: 2, }; const rulesEngine = ruleFactory([ { - filter: "list", - run: {and: ['$item.supplier == "Webbeds"', '$item.parentBrandName == "Red Lion (RLH Corporation)"']}, - set: "results", + filter: 'list', + run: { + and: [ + '$item.supplier == "Webbeds"', + '$item.parentBrandName == "Red Lion (RLH Corporation)"', + ], + }, + set: 'results', }, - { return: "results" }, + { return: 'results' }, ]); - -describe("pr", () => { - it("should return the right stuff", () => { -const result = rulesEngine(context); -console.log(result) +describe('pr', () => { + it('should return the right stuff', () => { + const result = rulesEngine(context); expect(result.length).toEqual(1); }); -}) \ No newline at end of file +}); From 9f680f111ea63a56881bf092b0b4402e03e52e1b Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 22:04:04 -0800 Subject: [PATCH 03/10] adds tests --- src/arrays.test.ts | 30 ++++++++++++++++++++++++++++++ src/pr.test.ts | 32 -------------------------------- 2 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 src/pr.test.ts diff --git a/src/arrays.test.ts b/src/arrays.test.ts index 62b0d30..dde47c6 100644 --- a/src/arrays.test.ts +++ b/src/arrays.test.ts @@ -63,6 +63,36 @@ describe('Array Operators', () => { ]); expect(multiplesOfThree({ list: [1, 2, 3, 4] })).toEqual([3]); }); + + it('can .filter() with multiple conditions', () => { + const context = { + list: [ + { + name: 'Foo', + age: 30, + }, + { + name: 'Bar', + age: 20, + }, + ], + isBaz: true, + }; + + const getMultiConditionalResult = ruleFactory([ + { + filter: 'list', + run: { + and: ['isBaz == true', '$item.name == "Foo"', '$item.age == 30'], + }, + set: 'results', + }, + + { return: 'results' }, + ]); + + expect(getMultiConditionalResult(context).length).toEqual(1); + }); }); describe('find', () => { diff --git a/src/pr.test.ts b/src/pr.test.ts deleted file mode 100644 index fc1be76..0000000 --- a/src/pr.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { ruleFactory } from './index'; - -const context = { - list: [ - { supplier: 'Webbeds', parentBrandName: 'Red Lion (RLH Corporation)' }, - { supplier: 'NotWebbeds', parentBrandName: 'Red Lion (RLH Corporation)' }, - ], - roomCount: 2, -}; - -const rulesEngine = ruleFactory([ - { - filter: 'list', - run: { - and: [ - '$item.supplier == "Webbeds"', - '$item.parentBrandName == "Red Lion (RLH Corporation)"', - ], - }, - set: 'results', - }, - - { return: 'results' }, -]); - -describe('pr', () => { - it('should return the right stuff', () => { - const result = rulesEngine(context); - - expect(result.length).toEqual(1); - }); -}); From a7bded0605e1fce946957296a256d91b47747233 Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 22:35:25 -0800 Subject: [PATCH 04/10] fix log trace operation --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0cc69ea..f55e7c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -313,7 +313,7 @@ export function ruleFactory< } if (trace) logTrace({ - operation: 'if.and', + operation: 'run.and', rule: and, result: serialize(conditionResult), currentState: serialize(input), From a66b5b45866ab2c0348a8de8c2e4a329237e684c Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 22:40:30 -0800 Subject: [PATCH 05/10] adds support for multi or conditionals --- src/arrays.test.ts | 37 ++++++++++++++++++++++++------------- src/index.ts | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/arrays.test.ts b/src/arrays.test.ts index dde47c6..347f199 100644 --- a/src/arrays.test.ts +++ b/src/arrays.test.ts @@ -64,18 +64,9 @@ describe('Array Operators', () => { expect(multiplesOfThree({ list: [1, 2, 3, 4] })).toEqual([3]); }); - it('can .filter() with multiple conditions', () => { + it('can .filter() with multiple AND conditions', () => { const context = { - list: [ - { - name: 'Foo', - age: 30, - }, - { - name: 'Bar', - age: 20, - }, - ], + list: ['Foo', 'Bar', 'Baz', 'Foo'], isBaz: true, }; @@ -83,7 +74,27 @@ describe('Array Operators', () => { { filter: 'list', run: { - and: ['isBaz == true', '$item.name == "Foo"', '$item.age == 30'], + and: ['isBaz == true', '$item.length == 3', '$item == "Foo"'], + }, + set: 'results', + }, + + { return: 'results' }, + ]); + + expect(getMultiConditionalResult(context)).toEqual(['Foo', 'Foo']); + }); + + it('can .filter() with multiple OR conditions', () => { + const context = { + list: ['Foo', 'Bar', 'Baz'], + }; + + const getMultiConditionalResult = ruleFactory([ + { + filter: 'list', + run: { + or: ['$item == "Bar"', '$item == "Baz"'], }, set: 'results', }, @@ -91,7 +102,7 @@ describe('Array Operators', () => { { return: 'results' }, ]); - expect(getMultiConditionalResult(context).length).toEqual(1); + expect(getMultiConditionalResult(context)).toEqual(['Bar', 'Baz']); }); }); diff --git a/src/index.ts b/src/index.ts index f55e7c0..db93c5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -296,6 +296,7 @@ export function ruleFactory< const arrayResult = arrayMethod.call(toArray(data), (item, index) => { Object.assign(input, { $item: item, $index: index, $array: data }); + // additional logic for array operations let conditionResult: RuleResult; if ( arrayMethod === Array.prototype.filter && @@ -320,6 +321,29 @@ export function ruleFactory< stepRow, stepCount, }); + } else if ( + arrayMethod === Array.prototype.filter && + typeof rule.run === 'object' && + 'or' in rule.run + ) { + const or = toArray(rule.run.or); + for (const rule of or) { + conditionResult = evaluateRule({ + stepRow, + input, + rule, + }); + if (conditionResult) break; + } + if (trace) + logTrace({ + operation: 'or.and', + rule: or, + result: serialize(conditionResult), + currentState: serialize(input), + stepRow, + stepCount, + }); } else { handleRule(rule.run); conditionResult = results.lastValue; From 62cf14fe2763107013b8c4db4740e9c5318feefc Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 22:57:15 -0800 Subject: [PATCH 06/10] adds readme and update tests to reflect readme --- README.md | 82 +++++++++++++++++++++++++++++++--------------- src/arrays.test.ts | 38 ++++++++++----------- 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index f416b6a..f1a06ff 100644 --- a/README.md +++ b/README.md @@ -297,12 +297,40 @@ const multiplesOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' } + { return: 'results' }, ]); multiplesOfThree({ list: [1, 2, 3, 4] }); // [3] ``` +##### Multiple conditions + +```js +// and +const evensButGreaterThanTwo = ruleFactory([ + { + filter: 'list', + run: { and: ['$item % 2 == 0', '$item > 2'] }, + set: 'results', + }, + { return: 'results' }, +]); +evensButGreaterThanTwo({ list: [1, 2, 3, 4] }); +// [4] + +// or +const multiplesOfThreeOrZero = ruleFactory([ + { + filter: 'list', + run: { or: ['$item % 3 == 0', '$item === 0'] }, + set: 'results', + }, + { return: 'results' }, +]); +multiplesOfThreeOrZero({ list: [0, 1, 2, 3, 4] }); +// [0, 3] +``` + #### `find` ```ts @@ -312,13 +340,13 @@ const getFirstMultipleOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' } + { return: 'results' }, ]); -getFirstMultipleOfThree({list: [1, 2, 3, 4]}) +getFirstMultipleOfThree({ list: [1, 2, 3, 4] }); // 3 -getFirstMultipleOfThree({list: [9, 3, 4]}) +getFirstMultipleOfThree({ list: [9, 3, 4] }); // 9 -getFirstMultipleOfThree({list: [99]}) +getFirstMultipleOfThree({ list: [99] }); // undefined ``` @@ -331,11 +359,11 @@ const isEveryNumberMultipleOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' } + { return: 'results' }, ]); -isEveryNumberMultipleOfThree({list: [3, 6, 9]}) +isEveryNumberMultipleOfThree({ list: [3, 6, 9] }); // true -isEveryNumberMultipleOfThree({list: [3, 6, 9, 10]}) +isEveryNumberMultipleOfThree({ list: [3, 6, 9, 10] }); // false ``` @@ -348,13 +376,13 @@ const hasEvenNumbers = ruleFactory([ run: '2 % $item == 0', set: 'results', }, - { return: 'results' } + { return: 'results' }, ]); -hasEvenNumbers({list: [2, 4]}) +hasEvenNumbers({ list: [2, 4] }); // true -hasEvenNumbers({list: [2, 4, 5]}) +hasEvenNumbers({ list: [2, 4, 5] }); // true -hasEvenNumbers({list: [5]}) +hasEvenNumbers({ list: [5] }); // false ``` @@ -362,13 +390,13 @@ hasEvenNumbers({list: [5]}) ```ts const calculateDiscount = ruleFactory([ - {"if": {"and": ["price >= 25", "price <= 50"]}, "then": "discount = 5"}, - {"if": "price > 50", "then": "discount = 10"}, - {"return": "discount"} + { if: { and: ['price >= 25', 'price <= 50'] }, then: 'discount = 5' }, + { if: 'price > 50', then: 'discount = 10' }, + { return: 'discount' }, ]); -calculateDiscount({price: 40, discount: 0}) +calculateDiscount({ price: 40, discount: 0 }); // 5 -calculateDiscount({price: 60, discount: 0}) +calculateDiscount({ price: 60, discount: 0 }); // 10 ``` @@ -376,15 +404,15 @@ calculateDiscount({price: 60, discount: 0}) ```ts const isScoreValid = ruleFactory({ - "if": {"and": ["score > 0", "score <= 100"]}, - "then": "valid = true", - "else": "valid = false", -}) -isScoreValid({score: 10}) + if: { and: ['score > 0', 'score <= 100'] }, + then: 'valid = true', + else: 'valid = false', +}); +isScoreValid({ score: 10 }); // { score: 10, valid: true }} -isScoreValid({score: -10}) +isScoreValid({ score: -10 }); // { score: 10, valid: false }} -isScoreValid({score: 101}) +isScoreValid({ score: 101 }); // { score: 10, valid: false }} ``` @@ -394,12 +422,12 @@ Execute string rule from `try`. Handle errors in the `catch` expression. ```js [ - { + { try: 'THROW "error"', catch: 'status = "Failure"', }, { return: 'status' }, // returns "Failure" -] +]; ``` #### `return` @@ -410,7 +438,7 @@ Ends rule execution, returning the specified value. [ { return: '"blue"' }, // returns "blue" { return: '"green"' }, // is not executed -] +]; ``` ### Builtin Operators diff --git a/src/arrays.test.ts b/src/arrays.test.ts index 347f199..df13d9d 100644 --- a/src/arrays.test.ts +++ b/src/arrays.test.ts @@ -65,44 +65,40 @@ describe('Array Operators', () => { }); it('can .filter() with multiple AND conditions', () => { - const context = { - list: ['Foo', 'Bar', 'Baz', 'Foo'], - isBaz: true, - }; - - const getMultiConditionalResult = ruleFactory([ + const evensButGreaterThanTwo = ruleFactory([ { filter: 'list', - run: { - and: ['isBaz == true', '$item.length == 3', '$item == "Foo"'], - }, + run: { and: ['$item % 2 == 0', '$item > 2'] }, set: 'results', }, - { return: 'results' }, ]); - expect(getMultiConditionalResult(context)).toEqual(['Foo', 'Foo']); + expect(evensButGreaterThanTwo({ list: [1, 2, 3, 4] })).toEqual([4]); + expect(evensButGreaterThanTwo({ list: [4, 5, 6, 7] })).toEqual([4, 6]); + expect(evensButGreaterThanTwo({ list: [-1, -2, 0, 10, 20] })).toEqual([ + 10, 20, + ]); }); it('can .filter() with multiple OR conditions', () => { - const context = { - list: ['Foo', 'Bar', 'Baz'], - }; - - const getMultiConditionalResult = ruleFactory([ + const multiplesOfThreeOrZero = ruleFactory([ { filter: 'list', - run: { - or: ['$item == "Bar"', '$item == "Baz"'], - }, + run: { or: ['$item % 3 == 0', '$item === 0'] }, set: 'results', }, - { return: 'results' }, ]); - expect(getMultiConditionalResult(context)).toEqual(['Bar', 'Baz']); + expect(multiplesOfThreeOrZero({ list: [0, 1, 2, 3, 4] })).toEqual([0, 3]); + expect(multiplesOfThreeOrZero({ list: [0, 5, 6, 7, 8] })).toEqual([0, 6]); + expect(multiplesOfThreeOrZero({ list: [3, 6, 30, 60] })).toEqual([ + 3, 6, 30, 60, + ]); + expect(multiplesOfThreeOrZero({ list: [33, -30, 0] })).toEqual([ + 33, -30, 0, + ]); }); }); From bd0c17d024f8270b0b057756e73995d2591622cb Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 23:04:20 -0800 Subject: [PATCH 07/10] remove extra readme changes --- README.md | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f1a06ff..72c1cb5 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ const multiplesOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' }, + { return: 'results' } ]); multiplesOfThree({ list: [1, 2, 3, 4] }); // [3] @@ -340,13 +340,13 @@ const getFirstMultipleOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' }, + { return: 'results' } ]); -getFirstMultipleOfThree({ list: [1, 2, 3, 4] }); +getFirstMultipleOfThree({list: [1, 2, 3, 4]}) // 3 -getFirstMultipleOfThree({ list: [9, 3, 4] }); +getFirstMultipleOfThree({list: [9, 3, 4]}) // 9 -getFirstMultipleOfThree({ list: [99] }); +getFirstMultipleOfThree({list: [99]}) // undefined ``` @@ -359,11 +359,11 @@ const isEveryNumberMultipleOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' }, + { return: 'results' } ]); -isEveryNumberMultipleOfThree({ list: [3, 6, 9] }); +isEveryNumberMultipleOfThree({list: [3, 6, 9]}) // true -isEveryNumberMultipleOfThree({ list: [3, 6, 9, 10] }); +isEveryNumberMultipleOfThree({list: [3, 6, 9, 10]}) // false ``` @@ -376,13 +376,13 @@ const hasEvenNumbers = ruleFactory([ run: '2 % $item == 0', set: 'results', }, - { return: 'results' }, + { return: 'results' } ]); -hasEvenNumbers({ list: [2, 4] }); +hasEvenNumbers({list: [2, 4]}) // true -hasEvenNumbers({ list: [2, 4, 5] }); +hasEvenNumbers({list: [2, 4, 5]}) // true -hasEvenNumbers({ list: [5] }); +hasEvenNumbers({list: [5]}) // false ``` @@ -390,13 +390,13 @@ hasEvenNumbers({ list: [5] }); ```ts const calculateDiscount = ruleFactory([ - { if: { and: ['price >= 25', 'price <= 50'] }, then: 'discount = 5' }, - { if: 'price > 50', then: 'discount = 10' }, - { return: 'discount' }, + {"if": {"and": ["price >= 25", "price <= 50"]}, "then": "discount = 5"}, + {"if": "price > 50", "then": "discount = 10"}, + {"return": "discount"} ]); -calculateDiscount({ price: 40, discount: 0 }); +calculateDiscount({price: 40, discount: 0}) // 5 -calculateDiscount({ price: 60, discount: 0 }); +calculateDiscount({price: 60, discount: 0}) // 10 ``` @@ -404,15 +404,15 @@ calculateDiscount({ price: 60, discount: 0 }); ```ts const isScoreValid = ruleFactory({ - if: { and: ['score > 0', 'score <= 100'] }, - then: 'valid = true', - else: 'valid = false', -}); -isScoreValid({ score: 10 }); + "if": {"and": ["score > 0", "score <= 100"]}, + "then": "valid = true", + "else": "valid = false", +}) +isScoreValid({score: 10}) // { score: 10, valid: true }} -isScoreValid({ score: -10 }); +isScoreValid({score: -10}) // { score: 10, valid: false }} -isScoreValid({ score: 101 }); +isScoreValid({score: 101}) // { score: 10, valid: false }} ``` @@ -422,12 +422,12 @@ Execute string rule from `try`. Handle errors in the `catch` expression. ```js [ - { + { try: 'THROW "error"', catch: 'status = "Failure"', }, { return: 'status' }, // returns "Failure" -]; +] ``` #### `return` @@ -438,7 +438,7 @@ Ends rule execution, returning the specified value. [ { return: '"blue"' }, // returns "blue" { return: '"green"' }, // is not executed -]; +] ``` ### Builtin Operators From d6058a91de518f946821c6cc9db03cf3ae055c15 Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 23:05:12 -0800 Subject: [PATCH 08/10] remove more readme additions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72c1cb5..bd5ef6f 100644 --- a/README.md +++ b/README.md @@ -359,7 +359,7 @@ const isEveryNumberMultipleOfThree = ruleFactory([ run: '$item % 3 == 0', set: 'results', }, - { return: 'results' } + { return: 'results' } ]); isEveryNumberMultipleOfThree({list: [3, 6, 9]}) // true @@ -376,7 +376,7 @@ const hasEvenNumbers = ruleFactory([ run: '2 % $item == 0', set: 'results', }, - { return: 'results' } + { return: 'results' } ]); hasEvenNumbers({list: [2, 4]}) // true From 28d5695ddbda1b64048b125dc7788c648b923b7e Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 23:11:51 -0800 Subject: [PATCH 09/10] removes extra line --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index db93c5d..5648238 100644 --- a/src/index.ts +++ b/src/index.ts @@ -295,7 +295,6 @@ export function ruleFactory< throw new UserError(`Data at '${arrayRule}' is not an array`); const arrayResult = arrayMethod.call(toArray(data), (item, index) => { Object.assign(input, { $item: item, $index: index, $array: data }); - // additional logic for array operations let conditionResult: RuleResult; if ( From c7c57280a93269b1309a6202f336844f5e6e5830 Mon Sep 17 00:00:00 2001 From: Cecil tantay Date: Mon, 13 Feb 2023 23:14:22 -0800 Subject: [PATCH 10/10] fix logtrace operation value for 'or' --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5648238..fa4a22c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -336,7 +336,7 @@ export function ruleFactory< } if (trace) logTrace({ - operation: 'or.and', + operation: 'run.or', rule: or, result: serialize(conditionResult), currentState: serialize(input),