MCPcopy
hub / github.com/CacheControl/json-rules-engine / start

Function start

examples/01-hello-world.js:15–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13const { Engine } = require('json-rules-engine')
14
15async function start () {
16 /**
17 * Setup a new engine
18 */
19 const engine = new Engine()
20
21 /**
22 * Create a rule
23 */
24 engine.addRule({
25 // define the 'conditions' for when "hello world" should display
26 conditions: {
27 all: [{
28 fact: 'displayMessage',
29 operator: 'equal',
30 value: true
31 }]
32 },
33 // define the 'event' that will fire when the condition evaluates truthy
34 event: {
35 type: 'message',
36 params: {
37 data: 'hello-world!'
38 }
39 }
40 })
41
42 /**
43 * Define a 'displayMessage' as a constant value
44 * Fact values do NOT need to be known at engine runtime; see the
45 * 03-dynamic-facts.js example for how to pull in data asynchronously during runtime
46 */
47 const facts = { displayMessage: true }
48
49 // engine.run() evaluates the rule using the facts provided
50 const { events } = await engine.run(facts)
51
52 events.map(event => console.log(event.params.data.green))
53}
54
55start()
56/*

Callers 1

01-hello-world.jsFile · 0.70

Calls 2

addRuleMethod · 0.95
runMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…