Skip to content

Commit 11e8b1b

Browse files
author
Cache Hamm
committed
compiled sources for 1.4.0
1 parent 01df95a commit 11e8b1b

File tree

5 files changed

+85
-23
lines changed

5 files changed

+85
-23
lines changed

dist/almanac.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var _fact = require('./fact');
1212

1313
var _fact2 = _interopRequireDefault(_fact);
1414

15+
var _errors = require('./errors');
16+
1517
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1618

1719
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
@@ -60,7 +62,7 @@ var Almanac = function () {
6062
value: function _getFact(factId) {
6163
var fact = this.factMap.get(factId);
6264
if (fact === undefined) {
63-
throw new Error('Undefined fact: ' + factId);
65+
throw new _errors.UndefinedFactError('Undefined fact: ' + factId);
6466
}
6567
return fact;
6668
}

dist/engine.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ var Engine = function (_EventEmitter) {
6060
*/
6161
function Engine() {
6262
var rules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
63+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6364

6465
_classCallCheck(this, Engine);
6566

6667
var _this = _possibleConstructorReturn(this, (Engine.__proto__ || Object.getPrototypeOf(Engine)).call(this));
6768

6869
_this.rules = [];
70+
_this.allowUndefinedFacts = options.allowUndefinedFacts || false;
6971
_this.operators = new Map();
7072
_this.facts = new Map();
7173
_this.status = READY;
@@ -245,7 +247,7 @@ var Engine = function (_EventEmitter) {
245247
}, _callee, this);
246248
}));
247249

248-
function evaluateRules(_x2, _x3) {
250+
function evaluateRules(_x3, _x4) {
249251
return _ref.apply(this, arguments);
250252
}
251253

dist/errors.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8+
9+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
10+
11+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
12+
13+
var UndefinedFactError = exports.UndefinedFactError = function (_Error) {
14+
_inherits(UndefinedFactError, _Error);
15+
16+
function UndefinedFactError() {
17+
var _ref;
18+
19+
_classCallCheck(this, UndefinedFactError);
20+
21+
for (var _len = arguments.length, props = Array(_len), _key = 0; _key < _len; _key++) {
22+
props[_key] = arguments[_key];
23+
}
24+
25+
var _this = _possibleConstructorReturn(this, (_ref = UndefinedFactError.__proto__ || Object.getPrototypeOf(UndefinedFactError)).call.apply(_ref, [this].concat(props)));
26+
27+
_this.code = 'UNDEFINED_FACT';
28+
return _this;
29+
}
30+
31+
return UndefinedFactError;
32+
}(Error);

dist/json-rules-engine.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.Engine = exports.Operator = exports.Rule = exports.Fact = undefined;
77

8-
exports.default = function (rules) {
9-
return new _engine2.default(rules);
8+
exports.default = function (rules, options) {
9+
return new _engine2.default(rules, options);
1010
};
1111

1212
var _engine = require('./engine');

dist/rule.js

+45-19
Original file line numberDiff line numberDiff line change
@@ -196,71 +196,97 @@ var Rule = function (_EventEmitter) {
196196
*/
197197
evaluateCondition = function () {
198198
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee(condition) {
199-
var comparisonValue, subConditions, passes;
199+
var comparisonValue, passes, subConditions;
200200
return regeneratorRuntime.wrap(function _callee$(_context) {
201201
while (1) {
202202
switch (_context.prev = _context.next) {
203203
case 0:
204204
comparisonValue = void 0;
205+
passes = void 0;
205206

206207
if (!condition.isBooleanOperator()) {
207-
_context.next = 14;
208+
_context.next = 15;
208209
break;
209210
}
210211

211212
subConditions = condition[condition.operator];
212213

213214
if (!(condition.operator === 'all')) {
214-
_context.next = 9;
215+
_context.next = 10;
215216
break;
216217
}
217218

218-
_context.next = 6;
219+
_context.next = 7;
219220
return all(subConditions);
220221

221-
case 6:
222+
case 7:
222223
comparisonValue = _context.sent;
223-
_context.next = 12;
224+
_context.next = 13;
224225
break;
225226

226-
case 9:
227-
_context.next = 11;
227+
case 10:
228+
_context.next = 12;
228229
return any(subConditions);
229230

230-
case 11:
231+
case 12:
231232
comparisonValue = _context.sent;
232233

233-
case 12:
234-
_context.next = 17;
234+
case 13:
235+
_context.next = 28;
235236
break;
236237

237-
case 14:
238-
_context.next = 16;
238+
case 15:
239+
_context.prev = 15;
240+
_context.next = 18;
239241
return almanac.factValue(condition.fact, condition.params);
240242

241-
case 16:
243+
case 18:
242244
comparisonValue = _context.sent;
245+
_context.next = 28;
246+
break;
247+
248+
case 21:
249+
_context.prev = 21;
250+
_context.t0 = _context['catch'](15);
251+
252+
if (!(_this3.engine.allowUndefinedFacts && _context.t0.code === 'UNDEFINED_FACT')) {
253+
_context.next = 27;
254+
break;
255+
}
256+
257+
passes = false;
258+
_context.next = 28;
259+
break;
260+
261+
case 27:
262+
throw _context.t0;
263+
264+
case 28:
265+
if (!(passes === undefined)) {
266+
_context.next = 32;
267+
break;
268+
}
243269

244-
case 17:
245-
_context.next = 19;
270+
_context.next = 31;
246271
return condition.evaluate(comparisonValue, _this3.engine.operators);
247272

248-
case 19:
273+
case 31:
249274
passes = _context.sent;
250275

276+
case 32:
251277
if (passes) {
252278
_this3.emit('success', _this3.event, almanac);
253279
} else {
254280
_this3.emit('failure', _this3.event, almanac);
255281
}
256282
return _context.abrupt('return', passes);
257283

258-
case 22:
284+
case 34:
259285
case 'end':
260286
return _context.stop();
261287
}
262288
}
263-
}, _callee, _this3);
289+
}, _callee, _this3, [[15, 21]]);
264290
}));
265291

266292
return function evaluateCondition(_x3) {

0 commit comments

Comments
 (0)