@@ -10,14 +10,14 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
1010
1111function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
1212
13- var params = require ( 'params' ) ;
1413var debug = require ( 'debug' ) ( 'json-rules-engine' ) ;
15- var isPlainObject = require ( 'lodash.isplainobject ' ) ;
14+ var isObjectLike = require ( 'lodash.isobjectlike ' ) ;
1615
1716var Condition = function ( ) {
1817 function Condition ( properties ) {
1918 _classCallCheck ( this , Condition ) ;
2019
20+ if ( ! properties ) throw new Error ( 'Condition: constructor options required' ) ;
2121 var booleanOperator = Condition . booleanOperator ( properties ) ;
2222 Object . assign ( this , properties ) ;
2323 if ( booleanOperator ) {
@@ -32,7 +32,10 @@ var Condition = function () {
3232 return new Condition ( c ) ;
3333 } ) ;
3434 } else {
35- properties = params ( properties ) . require ( [ 'fact' , 'operator' , 'value' ] ) ;
35+ if ( ! properties . hasOwnProperty ( 'fact' ) ) throw new Error ( 'Condition: constructor "fact" property required' ) ;
36+ if ( ! properties . hasOwnProperty ( 'operator' ) ) throw new Error ( 'Condition: constructor "operator" property required' ) ;
37+ if ( ! properties . hasOwnProperty ( 'value' ) ) throw new Error ( 'Condition: constructor "value" property required' ) ;
38+
3639 // a non-boolean condition does not have a priority by default. this allows
3740 // priority to be dictated by the fact definition
3841 if ( properties . hasOwnProperty ( 'priority' ) ) {
@@ -94,7 +97,7 @@ var Condition = function () {
9497 case 0 :
9598 value = this . value ;
9699
97- if ( ! ( isPlainObject ( value ) && value . hasOwnProperty ( 'fact' ) ) ) {
100+ if ( ! ( isObjectLike ( value ) && value . hasOwnProperty ( 'fact' ) ) ) {
98101 _context . next = 5 ;
99102 break ;
100103 }
@@ -137,7 +140,7 @@ var Condition = function () {
137140 key : 'evaluate' ,
138141 value : function ( ) {
139142 var _ref2 = _asyncToGenerator ( regeneratorRuntime . mark ( function _callee2 ( almanac , operatorMap ) {
140- var op , rightHandSideValue , leftHandSideValue , evaluationResult ;
143+ var op , rightHandSideValue , leftHandSideValue , result ;
141144 return regeneratorRuntime . wrap ( function _callee2$ ( _context2 ) {
142145 while ( 1 ) {
143146 switch ( _context2 . prev = _context2 . next ) {
@@ -186,10 +189,10 @@ var Condition = function () {
186189
187190 case 14 :
188191 leftHandSideValue = _context2 . sent ;
189- evaluationResult = op . evaluate ( leftHandSideValue , rightHandSideValue ) ;
192+ result = op . evaluate ( leftHandSideValue , rightHandSideValue ) ;
190193
191- debug ( 'condition::evaluate <' + leftHandSideValue + ' ' + this . operator + ' ' + rightHandSideValue + '?> (' + evaluationResult + ')' ) ;
192- return _context2 . abrupt ( 'return' , evaluationResult ) ;
194+ debug ( 'condition::evaluate <' + leftHandSideValue + ' ' + this . operator + ' ' + rightHandSideValue + '?> (' + result + ')' ) ;
195+ return _context2 . abrupt ( 'return' , { result : result , leftHandSideValue : leftHandSideValue , rightHandSideValue : rightHandSideValue , operator : this . operator } ) ;
193196
194197 case 18 :
195198 case 'end' :
0 commit comments