Skip to content

Commit f061af3

Browse files
author
Cache Hamm
committed
Rename successResults to results
1 parent b3c083d commit f061af3

16 files changed

+58
-64
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ let facts = {
8686
// Run the engine to evaluate
8787
engine
8888
.run(facts)
89-
.then(runResult => {
90-
runResult.successResults.map(result => console.log(result.event.params.message))
89+
.then(({ results }) => {
90+
results.map(result => console.log(result.event.params.message))
9191
})
9292

9393
/*
@@ -170,10 +170,9 @@ engine.addFact('account-information', function (params, almanac) {
170170
let facts = { accountId: 'lincoln' }
171171
engine
172172
.run(facts)
173-
.then((runResult) => {
174-
console.log(facts.accountId + ' is a ' + runResult.successResults.map(result => result.event.params.message))
173+
.then(({ results }) => {
174+
console.log(facts.accountId + ' is a ' + results.map(result => result.event.params.message))
175175
})
176-
.catch(err => console.log(err.stack))
177176

178177
/*
179178
* OUTPUT:

docs/engine.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Engine stores and executes rules, emits events, and maintains state.
1111
* [engine.removeRule(Rule instance)](#engineremoverulerule-instance)
1212
* [engine.addOperator(String operatorName, Function evaluateFunc(factValue, jsonValue))](#engineaddoperatorstring-operatorname-function-evaluatefuncfactvalue-jsonvalue)
1313
* [engine.removeOperator(String operatorName)](#engineremoveoperatorstring-operatorname)
14-
* [engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac, successResults: [], failureResults: []})](#enginerunobject-facts-object-options---promise--events-events-almanac-almanac-successresults--failureresults-)
14+
* [engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac, results: [], failureResults: []})](#enginerunobject-facts-object-options---promise--events-events-almanac-almanac-successresults--failureresults-)
1515
* [engine.stop() -> Engine](#enginestop---engine)
1616
* [engine.on('success', Function(Object event, Almanac almanac, RuleResult ruleResult))](#engineonsuccess-functionobject-event-almanac-almanac-ruleresult-ruleresult)
1717
* [engine.on('failure', Function(Object event, Almanac almanac, RuleResult ruleResult))](#engineonfailure-functionobject-event-almanac-almanac-ruleresult-ruleresult)
@@ -104,9 +104,6 @@ engine.addRule(rule)
104104
engine.removeRule(rule)
105105
```
106106

107-
108-
109-
110107
### engine.addOperator(String operatorName, Function evaluateFunc(factValue, jsonValue))
111108

112109
Adds a custom operator to the engine. For situations that require going beyond the generic, built-in operators (`equal`, `greaterThan`, etc).
@@ -156,7 +153,7 @@ engine.removeOperator('startsWithLetter');
156153

157154

158155

159-
### engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac, successResults: [], failureResults: []})
156+
### engine.run([Object facts], [Object options]) -> Promise ({ events: Events, almanac: Almanac, results: [], failureResults: []})
160157

161158
Runs the rules engine. Returns a promise which resolves when all rules have been run.
162159

@@ -168,12 +165,13 @@ await engine.run()
168165
await engine.run({ userId: 1 })
169166

170167
// results
171-
const runResult = await engine.run({ userId: 1 })
168+
const { results, failureResults, events } = await engine.run({ userId: 1 })
172169

173170
/**
174-
* runResult.almanac: Almanac instance for the run
175-
* runResult.successEvents: rule results for successful rules
176-
* runResult.failureEvents: rule results for failed rules
171+
* almanac: Almanac instance for the run
172+
* results: rule results for successful rules
173+
* failureResults: rule results for failed rules
174+
* events: successful events
177175
*/
178176
```
179177
Link to the [Almanac documentation](./almanac.md)

docs/walkthrough.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Running an engine executes the rules, and fires off event events for conditions
162162
engine.run({ userId: 1 }); // any time a rule condition requires 'userId', '1' will be returned
163163

164164
// run() returns a promise
165-
engine.run({ userId: 4 }).then((results) => {
166-
console.log('all rules executed; the following events were triggered: ', results.successResults.map(result => JSON.stringify(result.event)))
165+
engine.run({ userId: 4 }).then(({ results }) => {
166+
console.log('all rules executed; the following events were triggered: ', results.map(result => JSON.stringify(result.event)))
167167
});
168168
```
169169
Helper methods (for this example)

examples/01-hello-world.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require('colors')
1313
const { Engine } = require('json-rules-engine')
1414

15-
async function start() {
15+
async function start () {
1616
/**
1717
* Setup a new engine
1818
*/
@@ -47,9 +47,9 @@ async function start() {
4747
const facts = { displayMessage: true }
4848

4949
// engine.run() evaluates the rule using the facts provided
50-
const { successResults } = await engine.run(facts)
50+
const { results } = await engine.run(facts)
5151

52-
successResults.map(result => console.log(result.event.params.data.green))
52+
results.map(result => console.log(result.event.params.data.green))
5353
}
5454

5555
start()

examples/02-nested-boolean-logic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require('colors')
1313
const { Engine } = require('json-rules-engine')
1414

15-
async function start() {
15+
async function start () {
1616
/**
1717
* Setup a new engine
1818
*/
@@ -61,9 +61,9 @@ async function start() {
6161
gameDuration: 40
6262
}
6363

64-
const { successResults } = await engine.run(facts)
64+
const { results } = await engine.run(facts)
6565

66-
successResults.map(result => console.log(result.event.params.message.red))
66+
results.map(result => console.log(result.event.params.message.red))
6767
}
6868
start()
6969
/*

examples/03-dynamic-facts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { Engine } = require('json-rules-engine')
1616
// example client for making asynchronous requests to an api, database, etc
1717
const apiClient = require('./support/account-api-client')
1818

19-
async function start() {
19+
async function start () {
2020
/**
2121
* Setup a new engine
2222
*/
@@ -70,9 +70,9 @@ async function start() {
7070

7171
// define fact(s) known at runtime
7272
const facts = { accountId: 'lincoln' }
73-
const { successResults } = await engine.run(facts)
73+
const { results } = await engine.run(facts)
7474

75-
console.log(facts.accountId + ' is a ' + successResults.map(result => result.event.params.message))
75+
console.log(facts.accountId + ' is a ' + results.map(result => result.event.params.message))
7676
}
7777
start()
7878

examples/04-fact-dependency.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require('colors')
1515
const { Engine } = require('json-rules-engine')
1616
const accountClient = require('./support/account-api-client')
1717

18-
async function start() {
18+
async function start () {
1919
/**
2020
* Setup a new engine
2121
*/
@@ -108,11 +108,11 @@ async function start() {
108108
})
109109

110110
// first run, using washington's facts
111-
console.log('-- FIRST RUN --');
111+
console.log('-- FIRST RUN --')
112112
facts = { accountId: 'washington' }
113113
await engine.run(facts)
114114

115-
console.log('-- SECOND RUN --');
115+
console.log('-- SECOND RUN --')
116116
// second run, using jefferson's facts; facts & evaluation are independent of the first run
117117
facts = { accountId: 'jefferson' }
118118
await engine.run(facts)
@@ -138,5 +138,3 @@ start()
138138
* jefferson did NOT meet conditions for the microsoft-terminated-employees rule.
139139
* jefferson DID meet conditions for the five-year-tenure rule.
140140
*/
141-
142-

examples/05-optimizing-runtime-with-fact-priorities.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require('colors')
1313
const { Engine } = require('json-rules-engine')
1414
const accountClient = require('./support/account-api-client')
1515

16-
async function start() {
16+
async function start () {
1717
/**
1818
* Setup a new engine
1919
*/

examples/06-custom-operators.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
require('colors')
1919
const { Engine } = require('json-rules-engine')
2020

21-
async function start() {
21+
async function start () {
2222
/**
2323
* Setup a new engine
2424
*/
@@ -88,7 +88,7 @@ async function start() {
8888
* Each run() of the engine executes on an independent set of facts. We'll run twice, once per word
8989
*/
9090

91-
// first run, using 'bacon'
91+
// first run, using 'bacon'
9292
facts = { word: 'bacon' }
9393
await engine.run(facts)
9494

examples/07-rule-chaining.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require('colors')
1515
const { Engine } = require('json-rules-engine')
1616
const { getAccountInformation } = require('./support/account-api-client')
1717

18-
1918
async function start () {
2019
/**
2120
* Setup a new engine

0 commit comments

Comments
 (0)