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

Method evaluate

src/condition.js:90–115  ·  view source on GitHub ↗

* Takes the fact result and compares it to the condition 'value', using the operator * LHS OPER RHS * * * @param {Almanac} almanac * @param {Map} operatorMap - map of available operators, keyed by operator na

(almanac, operatorMap)

Source from the content-addressed store, hash-verified

88 * @returns {Boolean} - evaluation result
89 */
90 evaluate (almanac, operatorMap) {
91 if (!almanac) return Promise.reject(new Error('almanac required'))
92 if (!operatorMap) return Promise.reject(new Error('operatorMap required'))
93 if (this.isBooleanOperator()) { return Promise.reject(new Error('Cannot evaluate() a boolean condition')) }
94
95 const op = operatorMap.get(this.operator)
96 if (!op) { return Promise.reject(new Error(`Unknown operator: ${this.operator}`)) }
97
98 return Promise.all([
99 almanac.getValue(this.value),
100 almanac.factValue(this.fact, this.params, this.path)
101 ]).then(([rightHandSideValue, leftHandSideValue]) => {
102 const result = op.evaluate(leftHandSideValue, rightHandSideValue)
103 debug(
104 `condition::evaluate <${JSON.stringify(leftHandSideValue)} ${
105 this.operator
106 } ${JSON.stringify(rightHandSideValue)}?> (${result})`
107 )
108 return {
109 result,
110 leftHandSideValue,
111 rightHandSideValue,
112 operator: this.operator
113 }
114 })
115 }
116
117 /**
118 * Returns the boolean operator for the condition

Callers

nothing calls this directly

Calls 5

isBooleanOperatorMethod · 0.95
debugFunction · 0.85
allMethod · 0.80
getValueMethod · 0.80
factValueMethod · 0.45

Tested by

no test coverage detected