Skip to content

Commit 3ea4437

Browse files
author
Cache Hamm
committed
build 2.0.0-beta1
1 parent df770a4 commit 3ea4437

5 files changed

Lines changed: 176 additions & 118 deletions

File tree

dist/almanac.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var warn = require('debug')('json-rules-engine:warn');
3131
* Triggers fact computations and saves the results
3232
* A new almanac is used for every engine run()
3333
*/
34+
3435
var Almanac = function () {
3536
function Almanac(factMap) {
3637
var runtimeFacts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

dist/condition.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
1010

1111
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1212

13-
var params = require('params');
1413
var debug = require('debug')('json-rules-engine');
1514
var isPlainObject = require('lodash.isplainobject');
1615

1716
var 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')) {

dist/engine.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ exports.FINISHED = exports.RUNNING = exports.READY = undefined;
77

88
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
99

10-
var _params = require('params');
11-
12-
var _params2 = _interopRequireDefault(_params);
13-
1410
var _fact = require('./fact');
1511

1612
var _fact2 = _interopRequireDefault(_fact);
@@ -94,7 +90,9 @@ var Engine = function (_EventEmitter) {
9490
_createClass(Engine, [{
9591
key: 'addRule',
9692
value: function addRule(properties) {
97-
(0, _params2.default)(properties).require(['conditions', 'event']);
93+
if (!properties) throw new Error('Engine: addRule() requires options');
94+
if (!properties.hasOwnProperty('conditions')) throw new Error('Engine: addRule() argument requires "conditions" property');
95+
if (!properties.hasOwnProperty('event')) throw new Error('Engine: addRule() argument requires "event" property');
9896

9997
var rule = void 0;
10098
if (properties instanceof _rule2.default) {
@@ -228,6 +226,7 @@ var Engine = function (_EventEmitter) {
228226
debug('engine::run ruleResult:' + ruleResult.result);
229227
if (ruleResult.result) {
230228
_this2.emit('success', rule.event, almanac, ruleResult);
229+
_this2.emit(rule.event.type, rule.event.params, almanac, ruleResult);
231230
almanac.factValue('success-events', { event: rule.event });
232231
} else {
233232
_this2.emit('failure', rule.event, almanac, ruleResult);

0 commit comments

Comments
 (0)