You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[engine.addOperator(String operatorName, Function evaluateFunc(factValue, jsonValue))](#engineaddoperatorstring-operatorname-function-evaluatefuncfactvalue-jsonvalue)
Adds or updates a condition to the engine. Rules may include references to this condition. Conditions must start with `all`, `any`, `not`, or reference a condition.
Copy file name to clipboardExpand all lines: docs/rules.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,11 @@ Rules contain a set of _conditions_ and a single _event_. When the engine is ru
27
27
*[String and Numeric operators:](#string-and-numeric-operators)
28
28
*[Numeric operators:](#numeric-operators)
29
29
*[Array operators:](#array-operators)
30
+
*[Operator Decorators](#operator-decorators)
31
+
*[Array decorators:](#array-decorators)
32
+
*[Logical decorators:](#logical-decorators)
33
+
*[Utility decorators:](#utility-decorators)
34
+
*[Decorator composition:](#decorator-composition)
30
35
*[Rule Results](#rule-results)
31
36
*[Persisting](#persisting)
32
37
@@ -406,6 +411,35 @@ The ```operator``` compares the value returned by the ```fact``` to what is stor
406
411
407
412
```doesNotContain``` - _fact_ (an array) must not include _value_
408
413
414
+
## Operator Decorators
415
+
416
+
Operator Decorators modify the behavior of an operator either by changing the input or the output. To specify one or more decorators prefix the name of the operator with them in the ```operator``` field and use the colon (```:```) symbol to separate decorators and the operator. For instance ```everyFact:greaterThan``` will produce an operator that checks that every element of the _fact_ is greater than the value.
417
+
418
+
See [12-using-operator-decorators.js](../examples/13-using-operator-decorators.js) for an example.
419
+
420
+
### Array Decorators:
421
+
422
+
```everyFact``` - _fact_ (an array) must have every element pass the decorated operator for _value_
423
+
424
+
```everyValue``` - _fact_ must pass the decorated operator for every element of _value_ (an array)
425
+
426
+
```someFact``` - _fact_ (an array) must have at-least one element pass the decorated operator for _value_
427
+
428
+
```someValue``` - _fact_ must pass the decorated operator for at-least one element of _value_ (an array)
429
+
430
+
### Logical Decorators
431
+
432
+
```not``` - negate the result of the decorated operator
433
+
434
+
### Utility Decorators
435
+
```swap``` - Swap _fact_ and _value_ for the decorated operator
436
+
437
+
### Decorator Composition
438
+
439
+
Operator Decorators can be composed by chaining them together with the colon to separate them. For example if you wanted to ensure that every number in an array was less than every number in another array you could use ```everyFact:everyValue:lessThan```.
440
+
441
+
```swap``` and ```not``` are useful when there are not symmetric or negated versions of custom operators, for instance you could check if a _value_ does not start with a letter contained in a _fact_ using the decorated custom operator ```swap:not:startsWithLetter```. This allows a single custom operator to have 4 permutations.
442
+
409
443
## Rule Results
410
444
411
445
After a rule is evaluated, a `rule result` object is provided to the `success` and `failure` events. This argument is similar to a regular rule, and contains additional metadata about how the rule was evaluated. Rule results can be used to extract the results of individual conditions, computed fact values, and boolean logic results. `name` can be used to easily identify a given rule.
0 commit comments