@clipboard-health/rules-engine 1.5.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# @clipboard-health/rules-engine <!-- omit from toc -->
|
|
2
2
|
|
|
3
|
-
A pure functional rules engine
|
|
3
|
+
A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- `all`: Runs all the rules that matches the criteria
|
|
5
|
+
The engine uses static rules created in code instead of dynamic rules serialized to a database since we haven't needed the latter yet.
|
|
7
6
|
|
|
8
7
|
## Table of contents <!-- omit from toc -->
|
|
9
8
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/rules-engine",
|
|
3
|
-
"description": "A pure functional rules engine.",
|
|
4
|
-
"version": "1.
|
|
3
|
+
"description": "A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.",
|
|
4
|
+
"version": "1.7.0",
|
|
5
5
|
"bugs": "https://github.com/clipboardhealth/core-utils/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"tslib": "2.8.0",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Rule, type RuleContext } from "../rule";
|
|
2
|
+
/**
|
|
3
|
+
* Run all rules that return true for `runIf` only if the first rule returns true.
|
|
4
|
+
*
|
|
5
|
+
* @param rules The rules to run.
|
|
6
|
+
*/
|
|
7
|
+
export declare function allIfFirst<TInput, TOutput, TContext extends RuleContext<TInput, TOutput>>(...rules: Array<Rule<TInput, TOutput, TContext>>): Rule<TInput, TOutput, TContext>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.allIfFirst = allIfFirst;
|
|
4
|
+
/**
|
|
5
|
+
* Run all rules that return true for `runIf` only if the first rule returns true.
|
|
6
|
+
*
|
|
7
|
+
* @param rules The rules to run.
|
|
8
|
+
*/
|
|
9
|
+
function allIfFirst(...rules) {
|
|
10
|
+
return {
|
|
11
|
+
runIf: (input) => Boolean(rules[0]?.runIf(input)),
|
|
12
|
+
run: (context) => rules
|
|
13
|
+
.filter((rule) => rule.runIf(context.input))
|
|
14
|
+
.reduce((previousContext, rule) => rule.run(previousContext), context),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=allIfFirst.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allIfFirst.js","sourceRoot":"","sources":["../../../../../../packages/rules-engine/src/lib/runners/allIfFirst.ts"],"names":[],"mappings":";;AAOA,gCAUC;AAfD;;;;GAIG;AACH,SAAgB,UAAU,CACxB,GAAG,KAA6C;IAEhD,OAAO;QACL,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CACf,KAAK;aACF,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;aAC3C,MAAM,CAAC,CAAC,eAAe,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3E,CAAC;AACJ,CAAC"}
|